[antlr-interest] Generating AST trees

Richard Knight <r.knight at zoodigitalgroup.com> r.knight at zoodigitalgroup.com
Sun Feb 2 14:11:34 PST 2003


Hi,

I'm a bit of a newbie at all this, so apologies if this doesn't make 
a lot of sense...

I'm trying to figure out how to use the AST generation stuff to 
generate a parse tree in the way I want (or at least think I 
want!).  Say I have a grammar that looks something like:


expression: left operation right ;

operation: OP1 | OP2 | OP3;

left: ...more grammar...

right: ...more grammar...


So in the rule for expression there are no explicit tokens that have 
come out of the lexer.  I'd like to generate a tree like:

         expression
       /     |      \
      /      |       \
     /       |        \
   left   operation  right

only it seems there's no way to generate nodes in the tree that 
correspond to rules, rather than tokens, unless I'm missing 
something (quite likely !).

I could achieve it by manually by inserting code fragments into the 
grammar, but it seems like a lot of effort when the automagic AST 
generation seems like it might be able to do almost what I want...

Any ideas how I might get around this ?

Thanks !

Rich.

    


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list