Hi John,

On Tue, Nov 15, 2011 at 11:46 PM, John B. Brodie <j...@acm.org> wrote:

> Greetings!
> ...
> I do not think you want to recognize floating point values in the
> parser. any tokens you send to the HIDDEN $channel (or skip();) will be
> silently accepted before and after the '.' of the float. change your
> INTEGER rule to this:
>

I fully agree...



> fragment FLOAT: ;
> INTEGER : DIGIT+ ('.' DIGIT+ {$type=FLOAT;} )? ;
>
> and use FLOAT in the number rule.
>

.. however, Jarrod's grammar allows for input to end with `expression '.'`,
which could be "123." (an INTEGER followed by a DOT). This would be input
the lexer would trip over.

A possible fix could look like:

INTEGER
  :  DIGIT+ ({input.LA(1)=='.' && input.LA(2)>='0' && input.LA(2)>='9'}?=>
'.' DIGIT+ {$type=FLOAT;})?
  ;

I.e., only match a '.' if the character after the '.' is a digit.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to