[antlr-interest] Epsilon productions and end of file

Arnar Birgisson arnarb at oddi.is
Tue Dec 16 11:51:03 PST 2003


Hello,

I think ANTLR (as most parser generators) doesn't automatically assume
that end-of-file is reached after the start symbol. In fact, ANTLR
doesn't know which rule is the start-rule, because it's called at
run-time from your main-routine (or whatever). This allows you to parse
f.x. file headers and leave the file pointer after the parsable portion
and possibile continue reading some more data from there.

This means that you must specifically tell ANTLR where to expect
end-of-file, and for that you use the special token EOF.

As for epsilon-productions, you would use the ? operator. In you
example,

production: ( other_production )? ;

Hope this helps,
Arnar

>>> marcin-rzeznicki at wp.pl 12/16/03 7:51 AM >>>
Hi. How should I specify epsilon productions in my grammar? So far I've
been
using following pattern:

    production: other_prodution | ();

But it doesn't seem to work. Theory says that end-of-input char (usually
marked as $) is a member of starting production's follow set. Therefore,
supposing we have grammar:

    S -> AS`
    S`-> aS | "epsilon"

we should end up with $ in follow set of S`, which will result in
placing
production:

     S`->"epsilon"

in parsing table, to be chosen by parser when it reads EOF from input
stream. But my parser, generated by ANTLR for Java, do not respect this
and
throws exception when meeting EOF. After inspection of its source code I
have discovered that it has not placed EOF condition in its switch
instructions. I do not suppose this a bug (if it was so, it would be
horrible), I'd rather say I had not specified my intention clearly and
parser did not discover it as "epsilon" production.
--
Greetings
Marcin Rzeznicki



 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

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

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/ 




 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

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

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list