[antlr-interest] AST->Template: Not Getting It

Christopher Laco claco at chrislaco.com
Wed May 13 18:39:26 PDT 2009


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?


More information about the antlr-interest mailing list