1
votes

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.

1
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

1 Answers

1
votes

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.