[antlr-interest] ANTLR 3 rewrite rule syntax

Shmuel Siegel ssiegel at finjan.com
Mon Dec 4 17:42:24 PST 2006


The "artificially add a subrule" method works and it is at least linear
in the conditionals. The conditional rewrite method is combinatorial in
the conditionals and can easily get out of hand.
I was hoping that the rewrite rule syntax itself could handle the
individual conditionals and repetition factors as that would allow me to
keep the grammar oriented to the input instead of the output.
Oh well, I guess this will become a 3.1 enhancement request since there
are workarounds.

Thanks for the feedback,
Shmuel

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of David Holroyd
Sent: Monday, December 04, 2006 7:19 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] ANTLR 3 rewrite rule syntax

On Mon, Dec 04, 2006 at 03:56:45PM +0200, Shmuel Siegel wrote:
> Consider 
> 
> rule : A? B (id+)=C*
> 
> I know that I can write -> A? MYTOKEN[$B] $id*
> 
> But how can I make private tokens from "A" and "C". Ultimately "C" can
> be handled by a subrule but how do I issue a conditional token in my
> rewrite. MYTOKEN[$A?] and MYTOKEN[$A]? don't seem to work.

In addition to Jim's suggestion, you could also push "A" into another
rule:

  rule : myA? B (id+=C)*  -> myA? MYTOKEN[$B] $id
       ;
  myA  : A -> MYTOKEN[$A]
       ;


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list