Converting Grammar to Grammar LL (1): Some Problems

This is not exactly homework, but it is related to my research:

For example, the grammar is similar:

E → E + E | E * E | -E | (E) | id

After removing the ambiguity, it becomes (starting with the operator with the lowest priority)

E->-F|F
F->F+G|G
G->G*H|H
H->(E)|id

And after deleting the left recursion and left factoring (in this case is not required) the final grammar LL1:

E->-F|F
F->GF'
F'->+GF'|e
G->HG'
B->*HG'|e
H->(E)|id

Which gives a parser table without errors, which works fine. Now about the problem I am facing, suppose the grammar is this:

E → E + E | E * E | id = E | (E) | id

Now I can not create a parser table without conflicts, which means that my final grammar is not LL1. Here are the steps:

after removing the ambiguity:

E->id=F|F
F->F+G|G
G->G*H|H
H->(E)|id

, :

E->id=F|F
F->GF'
F'->+GF'|e
G->HG'
B->*HG'|e
H->(E)|id

Parser , , , - , , , . , , , . .

+5
1

, :

E -> E+E|E*E|id=E|(E)|id

:

E -> E+E|E*E|(E)|E'
E' -> id=E|id

:

E -> GF       FIRST(E) = FIRST(G)
F -> +GF|e
G -> HG'      FIRST(G) = FIRST(H)
G' -> *HG'|e
H -> (E)|E'   FIRST(H) = {(} + FIRST(E') = {(, id} 
E' -> idE''   FIRST(E') = {id}
E'' -> =E|e   FIRST(E'') = {=} + {#}

, , .

LL (1), N, FIRST(N -> a) FIRST(N -> b) N -> a, N -> b N.

, N -> id= .

LL(2) ( , , , ), id=E . (FIRST2 2- ).

, :

E -> E+E|E*E|id=E|(E)|id

, , , . !

+2
source

All Articles