[antlr-interest] Lexer strangeness
clifford.heath at gmail.com
Sat Oct 6 01:07:27 PDT 2007
New to Antlr, not to parser-generators. Hi all!
I'm using ANTLRWorks downloaded today on a MAC under OS/X.
I have the following snippet which works when I do it this way:
fragment ID: LETTER ( ( LETTER|DIGIT )* LETTER)? DIGIT?;
fragment LETTER : ('_'|'A'..'Z'|'a'..'z');
fragment DIGIT: '0'..'9';
but not when I do it this way:
IDENTIFIER: ID DIGIT?;
fragment ID: LETTER ( ( LETTER|DIGIT )* LETTER)?;
In the latter case it fails to match the IDENTIFIER 'f3', for example.
I have it structured this way because in the full grammar,
I have two similar things:
VARIABLE: ID DIGIT?;
where IDENTIFIER may not end with a digit, but VARIABLE might.
Use of a VARIABLE always makes the lexer/parser fail. I thought
I might have an greedy/non-greedy problem here, but even without
the similar definitions, the above fails.
What's happening here? Can someone point me in the right direction please?
More information about the antlr-interest