[antlr-interest] A rewrite rule including all children of a parserrule?

Shmuel Siegel ssiegel at finjan.com
Tue Oct 9 06:13:47 PDT 2007


At various stages of beta releases, using the rulename in the rewrite
rule didn't work so I got into the habit of always enumerating the
components. In your case, since you want to leave out a component, you
need to enumerate the components.

WARNING: don't mix rewrite styles. If you have the rewrite you can't say
"EOF!".

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Tom Davies
Sent: Tuesday, October 09, 2007 1:05 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] A rewrite rule including all children of a
parserrule?

Hi,

I'm converting a V2 grammar to V3 (by hand -- should I be using the  
automated tool?) and I have a question to do with rewrite rules.

The V2 rule uses the action:

{#module = #(#[MODULE_DEFN, "MODULE_DEFN"], module);}

to create the tree. The rule and my V3 tree rewrite rule is below.

Do I need to explicitly list all the child rules matched by the rule,  
or could I say ^(MODULE_DEFN $module) and get exactly the same result  
as ^(MODULE_DEFN optionalDocComment moduleNameDecl  
importDeclarationList friendDeclarationList outerDefnList) ?

If I had the grammar anywhere near working I'd just test this myself,  
but I'd like to know before I waste too much time :-)

Thanks,
   Tom

//a start rule for a module.
module
     : optionalDocComment moduleNameDecl[input.LT(1), "a valid module  
name"]
       importDeclarationList[input.LT(1), "a list of import  
declarations"]
       friendDeclarationList[input.LT(1), "a list of friend  
declarations"]
       outerDefnList[input.LT(1), "a list of top-level definitions"]
       EOF!
       -> ^(MODULE_DEFN optionalDocComment moduleNameDecl  
importDeclarationList friendDeclarationList outerDefnList)
     ;



More information about the antlr-interest mailing list