[antlr-interest] How do I accept input ending with a newline *or* EOF?

Kirby Bohling kirby.bohling at gmail.com
Mon Jan 31 16:54:00 PST 2011


On Mon, Jan 31, 2011 at 6:34 PM, Jim Idle <jimi at temporal-wave.com> wrote:
> It is much better to add a NL to the end of the input if it is not present
> as the ambiguities are complicated and pointless without that, but with
> this simple example you can do:
<snip..>

Jim,

   I've seen you make this suggestion several times.  Is there a
canonical or simple way to do that inside the Lexer?  Or is the
easiest way to do that to monkey with the stream to ensure it kicks
out a potentially missing character if it isn't the last character
before the EOF?

I've had this problem, and I just had my NL be ('\n'|EOF) and moved
along, for the grammars I had it was 'good enough'.  It would seem
much easier, and cleaner to fix up it up as you suggest, just not sure
the cleanest way to go about it.

Kirby


More information about the antlr-interest mailing list