automata - How to transform a grammar into LL(1) grammar form? -


e -> e+e|e*e|(e)|a 

given grammar, how can transform grammar ll(1) form?

e->ax|(e) x->+e|*e|epsilon 

is ll(1) grammar?

the original grammar left recursive, not ll(1), in fact not ll(k) k.

fortunately left recursion can removed. standard algorithm separately addressing immediate left recursion (as have here) , indirect left recursion. immediate left recursion simpler case of two. wikipedia article explains here.

basically move parts following recursive reference new production (the tail), has ε alternative,

   x -> ε|+e|*e 

then remove left recursive alternatives original production, , allow x follow of remaining non-recursive alternatives,

   e -> (e)x|ax 

note proposal misses x following parenthesized expression, not recognize same language.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -