[antlr-interest] Solving lexer ambiguities
John B. Brodie
jbb at acm.org
Tue Sep 11 19:41:50 PDT 2012
Greetings!
You might try something like the following --- obviously untested since
you did not provide complete example of your issue:
FLOAT:
(DIGIT)+ '.' (DIGIT)* EXPONENT?
| (DIGIT)+ EXPONENT;
DOT: '.' ( (DIGIT)+ EXPONENT? {$type=FLOAT;} )? ;
hopefully in your language the 2structure strings can never match a
FLOAT.....
(e.g. something like 1structure.2E5.35 isnt permitted....)
Hope this helps...
-jbb
On 09/11/2012 08:45 PM, Jose Juan Tapia wrote:
> So I was gaving a problem with my lexer recognition where my double token
> is defined as follows.
>
> FLOAT:
> (DIGIT)+ '.' (DIGIT)* EXPONENT?
> | '.' (DIGIT)+ EXPONENT?
> | (DIGIT)+ EXPONENT;
>
>
> However additional to that I have certain structures where the following
> syntax:
>
> 1structure.2structure .35
>
> Should be recognized by the following grammar
>
> STRING (DOT STRING)? FLOAT
>
> The problem being of course, that my lexer is recognizing the .2 token as a
> FLOAT and I'm not sure how can I make it so that it choses the alternative
> solution. (I've tried using backtracking to no avail. Maybe I'm doing it
> wrong but my current assumption is that since the ambiguity is at the lexer
> rather than at the parser level the parser can't do much to solve the
> conflict).
More information about the antlr-interest
mailing list