[antlr-interest] Token lin lexer

Jim Idle jimi at temporal-wave.com
Wed May 19 08:35:36 PDT 2010


Please consult: http://antlr.markmail.org where you will find this answered lots of times, including just two days ago. Look for $type.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Bob
> Sent: Wednesday, May 19, 2010 8:34 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Token lin lexer
> 
> 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!
> 
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list