[antlr-interest] Cannot find symbol stuff

Kay Roepke kroepke at classdump.org
Wed Aug 2 10:08:45 PDT 2006


Hi!

On 2. Aug 2006, at 18:47 Uhr, Herumor wrote:

> NUMBERS : ('0' | '1'..'9' ('0'..'9')*) ('.' {_ttype = DOT;}  
> ('0'..'9')+
> {$setType(DEC_NUMBERS);})? ;

What is the lexer supposed to return for the NUMBERS rule?
The parser would either see NUMBERS or DEC_NUMBERS, depending on  
whether the lexer sees '.' ('0'..'9') or not.
The DOT type would never be used in this case anyway, because the  
token type will be set to DEC_NUMBERS if the
optional part matches.
Seems to me that you'd need to rethink your approach to lexing NUMBERS.

To the token types DOT and DEC_NUMBERS:
They are not defined in the lexer grammar, so the lexer wouldn't know  
about them. Consequently they cannot be in
its vocabulary. I'm not sure whether you can use a 'tokens' section  
in a lexer (I guess not) but you could add a
empty protected rule DEC_NUMBERS. DOT I would define as a bona-fide  
token rule, since that's what you use it as.

So, adding

protected
DEC_NUMBERS: ;

and

DOT : '.';

should work. Then you can rewrite your NUMBERS rule like:

NUMBERS : ('0' | '1'..'9' ('0'..'9')*) (DOT ('0'..'9')+ {$setType 
(DEC_NUMBERS);})? ;

but I'd do it a bit differently (see the archives for a lot of  
solutions to this. E.g. search for the thread
"Please advise about float" from September, 19th 2005.)
--> http://www.antlr.org/pipermail/antlr-interest/2005-September/ 
thread.html

HTH,

-k


More information about the antlr-interest mailing list