[antlr-interest] combining tokens in rewrite rule

Jim Idle jimi at intersystems.com
Mon Jan 22 09:45:54 PST 2007


Manu,

Firstly, from your questions, I am assuming that this is ANTLR 3, not ANTLR 2. If it is ANTLR2 then ignore this answer.

Declare an "Imaginary" token in the tokens section

tokens
{
	NAMESPACE;
}

Then accumulate the text of the individual IDs, '.' and dots, and rewrite the rule as the imaginary token, set to the concatenated text.

Jim

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Manu
Sent: Sunday, January 21, 2007 3:05 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] combining tokens in rewrite rule

Hi,

I want to combine tokens when generating the AST.

For example, for a rule like this:

namespaceSpec:	(ID) ('.' ID)*;

i want to generate a tree rule that returns a new tree with only one
ID token, that is the result of all ID and '.' concatenation. Is there
a way to do this?

Thanks.

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.4/644 - Release Date: 1/22/2007 7:30 AM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.4/644 - Release Date: 1/22/2007 7:30 AM
 


More information about the antlr-interest mailing list