[antlr-interest] ANTLR 3 rewrite rule syntax
Jim Idle
jimi at intersystems.com
Mon Dec 4 09:04:05 PST 2006
Use conditional rewrite (plenty of ways to decide what is to be written, this is just one example):
rule: (a=A)? b=B (id+=C)*
-> {$a == null && $id == null}? $b
-> {$a == null && $id != null}? $b $id*
etc…
;
That should give you enough info to proceed I think.
Jim
_____
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Shmuel Siegel
Sent: Monday, December 04, 2006 5:57 AM
To: ANTLR Interest
Subject: [antlr-interest] ANTLR 3 rewrite rule syntax
To my surprise, I am coming to like the rewrite rules better than the grammar markups; more power and better separation between grammar and output. I do have some syntax questions.
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.
Shmuel
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.15.6/567 - Release Date: 12/4/2006 7:18 AM
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.15.6/567 - Release Date: 12/4/2006 7:18 AM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061204/a9f69806/attachment.html
More information about the antlr-interest
mailing list