[antlr-interest] Epsilon productions and end of file

Marcin Rzeznicki marcin-rzeznicki at wp.pl
Wed Dec 17 13:44:19 PST 2003

----- Wiadomosc oryginalna ----- 
Od: "Arnar Birgisson" <arnarb at oddi.is>
Do: <antlr-interest at yahoogroups.com>
Wyslano: 17 grudnia 2003 12:13
Temat: RE: [antlr-interest] Epsilon productions and end of file

> > > This means that you must specifically tell ANTLR where to expect
> > > end-of-file, and for that you use the special token EOF.
> >
> > Yes, but when I use explicit EOF, it does not calculate
> > follow sets as I
> > would expect. For example
> >
> > S -> AB , means taht follow set of S goes to follow set of B (with $)
> >
> > S -> AB EOF ends with EOF in follow set of S, nothing to do with B
> I'm sorry, I don't quite follow. S -> AB EOF should not result in EOF
> being in FOLLOW(S), but in FOLLOW(B).

Of course, I have misplaced symbols. It should be: EOF goes to FOLLOW(B),
but FOLLOW(S) is not in FOLLOW(B) anymore. I am sorry. What I mean is that
by writing S->AB I expect FOLLOW(S) to be in FOLLOW(B), as FOLLOW(S)
contains EOF, so does FOLLOW(B). By writing S->AB EOF it ends up in EOF
being in FOLLOW(B), but without everything else from FOLLOW(S). In my
example the grammar is like:
P->(F) | ...
Constructing LL parser with pencil I have assumed that ')' is in FOLLOW(F),
therefore in FOLLOW(F'), and every word of generated lanuage may be
terminated by ')' or EOF. But parser did not want to choose epsilon
productions that should occur when EOF was read, but tried to look ahead for
another token, which resulted in throwing an exception. So it only accepted
words terminating with ')'

When I transformed grammar to:
FOLLOW (F) contains ')' as well as EOF, but then FOLLOW(F') does not contain
')', so parser does not accept words that have ')' somewhere within.

That's my problem.

Marcin Rzeznicki


Yahoo! Groups Links

To visit your group on the web, go to:

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

Your use of Yahoo! Groups is subject to:

More information about the antlr-interest mailing list