[antlr-interest] Difference between tokens {...} and ordinary lexer rules

Felix Dorner felix_do at web.de
Fri Feb 29 15:10:44 PST 2008


Hey,

I am really new. From just testing these two approaches:

/// start
...
tokens {
  CLINTON='clinton';
  OBAMA='obama';
}

assignment : ID'='INT;

ID : ('a'..'z'|'A'..'Z')+ ;
INT : '0'|('1'..'9')('0'..'9')* ;
//end

and

// start
...
assignment : ID'='INT;

CLINTON: 'clinton';
OBAMA: 'obama';
ID : ('a'..'z'|'A'..'Z')+ ;
INT : '0'|('1'..'9')('0'..'9')* ;
//end

I can't find a difference. What's the 'better' way to go? The only thing 
I see is that accidentally moving the ID rule in the second example 
above the two "canditate" rules, would also allow "clinton=0" or 
"obama=0". This could be avoided when using the tokens{...} approach.

Thanks for any comments,
Felix







More information about the antlr-interest mailing list