|[Newbie] LL(1) and if-then-else email@example.com (1997-03-31)|
|Re: [Newbie] LL(1) and if-then-else firstname.lastname@example.org (1997-04-02)|
|Re: [Newbie] LL(1) and if-then-else email@example.com (Thomas W. Christopher) (1997-04-03)|
|From:||"Thomas W. Christopher" <firstname.lastname@example.org>|
|Date:||3 Apr 1997 14:11:16 -0500|
|Organization:||Illinois Institute of Technology|
MORIN Bruno wrote:
> Currently studying compilers, we need for a project to resolve the 'if
> - then - else' ambiguity. We are programming a mini-compiler based on
> a LL(1) grammar and are unable to resolve the ambiguity raised by an
> 'else' statement.
It can't be removed, but you can still use LL(1) parsing by "cheating".
s -> if e then s else s | if e then s | ....
is rewritten into
s-> if e then e elseOpt | ....
elseOpt -> else s | empty
Now for elseOpt, there is a conflict between the first set of "else s"
and the follow set of s (for the empty alternative).
Have the parser generator (or you, if you're doing this by hand)
prefer a right hand side selected by the first set over than selected by
the follow set. In this case, let else select "else s" rather than the
I'm sorry, this is a little brief. I've discussed it more fully in the
documentation on TCLL1, an LL(1) parser generator. You can get the
document and the parser generator (written in and targeting Icon
-Thomas W. Christopher http://www.iit.edu/~tc
Return to the
Search the comp.compilers archives again.