I want to write a program to gives grammar as input and change it to LL1.
my problem is converting to LL1 I don't have any algorithm to convert. I earn grammar from some input text by a simple text analyzer but how I can change it to LL1 ? is there any algorithm that is clear to implement.
Asked
Active
Viewed 1,430 times
1

Oak
- 26,231
- 8
- 93
- 152

kamiar3001
- 2,646
- 4
- 42
- 78
-
there is not a deterministic way to do it so.. will not be able to write a program... you can use some techniques as factorization or eliminating left recursion... but maybe you will not reach the desired LL1 grammar (even if the lenguage CAN be expressed as a LL1 grammar) – Qsebas Dec 09 '13 at 19:40
1 Answers
1
The dragon book: Compilers, Principles, Techniques and Tools by Aho, Sethi and Ullman has a chapter (titled Syntax Analysis) which explains a procedure to eliminate left recursion and another procedure to left factor a context free grammar.
The resulting grammar is suitable for LL parsing.
I suggest you read that chapter in the book and see if you can convert it into code.