views:

34

answers:

1

is there any implementation of ll(k) to ll(1) convertor ?

+3  A: 

IIRC; in general, no because some languages have ll(k) grammars but no ll(1) grammars. So unless I'm mistaken, not all ll(k) can be converted ll(1). However, that says nothing about the possibility of such a tool that will work the cases where it can be done.


the rule for left factoring is:

A := A B |
     A C |
     D |
     E ;

turns into:

A := (D | E) (B | C)*

or if you don't allow () groups and *:

A := D A'
     E A'

A' := B A' |
      C A' |
      nul ;

The trick becomes how to handle the translation of the action rules; if your language supports it, lambdas can be kinda handy there.

BCS
actually I'm looking for a piece of code that implements the handler for left recursion and Left-Factoring.i just want a simple example for a very simple grammar.
Mahdi