[antlr-interest] Howto modify token creation?

Indhu Bharathi indhu.b at s7software.com
Wed Sep 23 23:20:27 PDT 2009


You can do something like

ID	: LETTER (LETTER|DIGIT)*
	{
		String text = getText();
		Integer tknType;
		if( (tknType=table.get(text))!=null ) {
			$type = tknType;
		}
	}

The table can be passed to the lexer using some member function. But I don't
know any clean way how to make sure ANTLR lexer doesn't assign the same int
to some other token.

Curious to know where you are using this. If the lexer emits tokens
dynamically, the parser also has to handle it dynamically right? (using
semantic predicats probably) This has to be a peculiar case.

Cheers, Indhu


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Heiko Folkerts
Sent: Thursday, September 24, 2009 11:27 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Howto modify token creation?

Hi,
I'd like to use a rule that catches all strings e.g. like identifiers and
keywords and create specific tokens depending of the contents of the string.
Because new keywords can be added to a database coding all keywords in the
grammar is not an option. Do I have to override the emit function to create
the different tokens or which way should I take?

Regards

Heiko


Mit freundlichem Gruß
Heiko Folkerts
Systementwicklung und -design
--
______________________________________________
DAVID GmbH · Wendenring 1 · 38114 Braunschweig
Tel.: +49 531 24379-14
Fax.: +49 531 24379-79
E-Mail: mailto:Heiko.Folkerts at david-bs.de
WWW:   http://www.david-bs.de 
Eintragung: Amtsgericht Braunschweig, HRB 3167
Geschäftsführer: Frank Ptok
______________________________________________

 

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