[antlr-interest] Expecting EOF?

Ron Burk ronburk at gmail.com
Sun Apr 11 12:10:46 PDT 2010


Didn't spot anything you did to ask to treat EOF the
same as NEWLINE.


[C:\rlb]dump \input.txt
0000: 66 75 6e 63 74 69 65 20 66 28 78 29 20 69 73 20    functie f(x) is
0010: 7b  d  a  9 61 20 69 73 20 78 20 2b 20 35  d  a    {...a is x + 5..
0020:  9 32 2a 61  d  a 7d  d  a 66 28 31 30 29          .2*a..}..f(10)

As Jim speculated, your input seems to not have a trailing NEWLINE.
As for Windows versus Unix, they are equally happy to let users
create text files that aren't terminated by newlines (something
most programmer's editors view as correct behavior).

You could certainly make the grammar do the work
of treating EOF as a NEWLINE (and then as EOF
of course), but I suspect the simplest out is to just
have the lexer generate a NEWLINE if one was not
seen just prior to the EOF...


More information about the antlr-interest mailing list