[antlr-interest] newbie: tokens and lexer rules

JConner at ssp-uk.com JConner at ssp-uk.com
Tue Aug 2 06:52:09 PDT 2005


Hello!

To help myself to learn antlr, I'm playing around with a grammer (fgl.g).
I'm trying to get to grips with parser rules, lexer rules, tokens, and the
like.

I've come accross a parser rule that contains a mixture of rule references
and tokens:

functionIdentifier
    : DAY
    | YEAR
<many more tokens>
    | constantIdentifier
    ;

So that I can easily add actions to get the text of the token, I thought
I'd be clever and bunch the tokens up in a lexer rule, then reference this
from the parser rule:

functionIdentifier
    : MY_STUFF
    | constantIdentifier
    ;

(and in the lexer)

MY_STUFF
    : DAY
    | YEAR
<more>
    ;

When I try to compile this, I get errors about lexer rules for DAY, YEAR,
etc not being defined.  I thought I could use tokens in lexer rules...?

Can anyone point out the obvious issue that I'm missing?

John



More information about the antlr-interest mailing list