[antlr-interest] Token lin lexer

Bob temporaryemail at comcast.net
Wed May 19 08:33:39 PDT 2010


I'm 1 day into Antlr and hope for an answer to this:

 

With an identifier rule (for example this one):

 

SIMPLE_IDENTIFIER : ( 'a'..'z'|'A'..'Z'|'_' ) (
'a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')* ;

 

Is it possible, when the lexer recognizes the input stream to be a
SIMPLE_IDENTIFIER, to add some extra code that would

look-up the SIMPLE_IDENTIFIER and return possibly a different token? - Thus
directing the parser to different grammar rules.

 

Take this expression for example:

 

(  V(n1)/r1 + Func(arg1) )

 

where the semantics of V(n1) are more akin to n1->V rather than a function
call to V with arg n1.

I'd like to capture the V(n1) during parsing and make it a n1->V node
instead of a function call node.

 

Using flex this is easy: Once the identifier string is matched it can be
used in a lookup to determine the token type then fed to bison.

 

So, Can Antlr let me switch the token type at the lexical level before the
parser gets hold of it?

 

Hope this makes sense!

 



More information about the antlr-interest mailing list