[antlr-interest] Question about lists in tree rewrites

Jim Idle jimi at temporal-wave.com
Thu Mar 22 16:20:53 PDT 2007


Rather than rename you rule, just label it:

selectList    : d1=displayedColumn (COMMA d2=displayedColumn )*  
               -> ^(SELECT_LIST $d1 (COMMA $d2)* );

Also, are you sure you needs those commas in the AST? When you out put
your translated code, you can infer that they are needed by consequence
of the fact that there is more than one displayed column.


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Miguel Ping
Sent: Thursday, March 22, 2007 4:16 PM
To: antlr-interest
Subject: [antlr-interest] Question about lists in tree rewrites

Hi all,

Suppose I got this rule

selectList    : displayedColumn (COMMA displayedColumn )*  ->
^(SELECT_LIST displayedColumn+ );

I know antlr (v3) is smart and sees that 'displayedColumn' repeats at
least once, and manages the list for me in the rewrite rule.
But suppose I am writing a translator, and really need thosesCOMMAS
tokens, how should I do the rewrite rule to include the COMMA's ?
Right now I made a stupid hack:

selectList	: displayedColumn (COMMA otherColumn)*  -> ^(SELECT_LIST
displayedColumn (COMMA otherColumn)* )
	otherColumn	:	displayedColumn; //dummy rule

But as I said, I feel a bit stupid and wonder if is there an easier
way to do this...
Thanks in advance,
Miguel Ping

More information about the antlr-interest mailing list