[antlr-interest] Examining characters in lexer

Jim Idle jimi at temporal-wave.com
Fri Mar 13 08:13:34 PDT 2009


Dennis Brothers wrote:
> OK, I tried it, and I'm getting an error I don't know how to interpret:
>
> [10:19:33] error(10):  internal error:  
> org 
> .antlr 
> .analysis 
> .NFAToDFAConverter.getPredicatesPerNonDeterministicAlt(Unknown  
> Source): no AST/token for nonepsilon target w/o predicate
>
> That is emitted three times when I try to generate code.
>
> Here's the lexer section:
>
> NEWLINE	:	'\r'? '\n' ;
> WS  	:	(' '|'\t'|NEWLINE)+ {$channel=HIDDEN;} ;
> STRING 	:	( '0'..'9'|'_'|'\'' | LETTER )+ ;
> LETTER	:	{ Char.IsLetter( input.LA(1) ) }?=> . ;
>   
lexer grammar f;

NEWLINE :       '\r'? '\n' ;
WS      :       (' '|'\t'|NEWLINE)+ {$channel=HIDDEN;} ;
STRING  :       ( '0'..'9'|'_'|'\'' | LETTER )+ ;
fragment
LETTER  : { Char.IsLetter( input.LA(1)) }?=> . ;

You missed the fragment specifier from your LETTER rule, which creates a 
real token rule that clashes with the invocation of the self same rule 
in STRING and all sorts of other problems ;-)

If you are bothered about efficiency here, you might find that the 
following generates better code:

Jim


More information about the antlr-interest mailing list