[antlr-interest] AST->Template: Not Getting It
Frank Du
frank.du at riskmetrics.com
Thu May 14 07:26:21 PDT 2009
Please try to use this rule for your tree walker:
statement: getExpr -> template(content ={$getExpr.st}) "<content>";
Thanks,
Frank
-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Christopher Laco
Sent: Wednesday, May 13, 2009 9:39 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] AST->Template: Not Getting It
I suck at this, clearly I don't get it. It feels like I've made zero
progress in weeks.
I finally got to the point where I can output a simple AST with one
grammar, and I'm trying to use a tree grammar to translate that into the
target language using templates.
My simple tree:
(DOCUMENT (GET 'variable'))
My tree grammar:
document : ^(DOCUMENT statement*) -> using() ;
statement: getExpr;
getExpr: ^(GET LITERAL) -> print() ;
My template:
>
> group CSharpGenerator;
>
> using() ::= <<
> foo
>>>
>
> print() ::= <<
> System.Console.WriteLine;
>>>
When I run the parsers tree through the tree grammar passing in the
template, all I get is this:
foo
orint() seems to never be called.
If I change the tree grammar to output AST and print that tree, I get
the same tree, which seems to imply my tree grammar is fine.
What am I missing?
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list