[antlr-interest] a simple (not for me :)) grammar problem

Mark Volkmann r.mark.volkmann at gmail.com
Mon Jan 7 07:13:33 PST 2008


On Jan 7, 2008 6:24 AM, Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 21:20 7/01/2008, =?ISO-8859-9?Q?F=FDrat_K=FC=E7=FCk?= wrote:
>  >
>  >this is my simple solution:
>
> It's not a solution if it doesn't work :)
>
> Try doing what I suggested.  You really should handle the floats
> in the lexer, since you don't have to worry about whitespace
> weirdness that way.  And if you do it the way I said, it should
> work.

I think this is what you want or at least really close.

grammar Sample;

start
  options { backtrack = true; }
  : (floatValue | integerValue) DOT IDENTIFIER
    { System.out.println("matched!"); }
  ;

floatValue: NUMBER DOT NUMBER;
integerValue: NUMBER;

DOT: '.';
IDENTIFIER: LETTER+;
NUMBER: DIGIT+;
fragment LETTER: 'a'..'z';
fragment DIGIT: '0'..'9';

NEWLINE: '\r'? '\n' { skip(); };

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list