[antlr-interest] Token vs Rule

Adrian Tineo Cabello tineo at ac.uma.es
Thu Apr 1 23:55:05 PST 2004


Hi there, this is my first post (of possibly many as I am going to do heavy 
use of ANTLR in the months ahead).

> What is the difference between putting the token in the tokens
> section vs declaring it as a rule outside of the tokens section.
> They seem to produce different result which I am not quite sure I
> understand:
>
> class ExprLexer extends Lexer;
> options
> {
> 	k = 2;
> }
>
> tokens
> {
> 	STAR		=	"*";
> }
>
> STAR : '*';

"srandm", from what I have read in the docs (ANTLR metalanguage) I think it 
makes no difference, you create the token in both ways. You would normally 
create it in the lexer with the STAR:'*'; syntax. The use of the tokens 
section is appropiate in the tree-parser to define imaginary tokens to 
construct AST nodes, which could be handy to walk the tree.

Hope that helps

Adrian T.




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list