Re: [Newbie] LL(1) and if-then-else

"Thomas W. Christopher" <>
3 Apr 1997 14:11:16 -0500

          From comp.compilers

Related articles
[Newbie] LL(1) and if-then-else (1997-03-31)
Re: [Newbie] LL(1) and if-then-else (1997-04-02)
Re: [Newbie] LL(1) and if-then-else (Thomas W. Christopher) (1997-04-03)
| List of all articles for this month |

From: "Thomas W. Christopher" <>
Newsgroups: comp.compilers
Date: 3 Apr 1997 14:11:16 -0500
Organization: Illinois Institute of Technology
References: 97-03-177
Keywords: parse, LL(1)

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
empty RHS.

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
currently) from

-Thomas W. Christopher

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.