[antlr-interest] lexer: matching float vs int
Sam Harwell
sharwell at pixelminegames.com
Tue Sep 9 12:45:21 PDT 2008
You should cross-list that article under “generating user-friendly error messages for bad input” or something similar. The wiki has various articles on error handling, but none that I saw that have user-friendly messages as a goal. The comments on yours as-is make it the best I’ve seen on that topic.
Sam
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Tuesday, September 09, 2008 2:16 PM
To: antlr-interest
Subject: Re: [antlr-interest] lexer: matching float vs int
On Tue, 2008-09-09 at 13:10 -0500, Sam Harwell wrote:
Here is the numeric lexer section of a C++ grammar. This method is very different from Jim’s method, as it doesn’t use any semantic predicates,
See the leading points in the article, being that ANTLR is working out the lookahead for you, whereas the example is minimal in this regard, you don't have a range operator '..' here and the only language specific things are input.LA(), which is just LA() in C. Finally, your code does not accommodate erroneous input, it will just throw lexer exceptions. If you are using IDEs or want good error messages from a parser, then you need to code for that rather than try to intercept exceptions and work it out afterwards.
But use whatever flaots your boat ;-). The examples was just for all the new people that find this particular problem very thorny :-)
Jim
and has no dependency on the target language. I
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080909/7d1c35a6/attachment.html
More information about the antlr-interest
mailing list