[antlr-interest] input vs. output ASTs in a tree parser

james_cataldo at agilent.com james_cataldo at agilent.com
Thu Aug 3 13:18:18 PDT 2006


I answered my own quesiton by running a test.  It appears that the output is

> #(BAR)

Cheers,
Adam Cataldo

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of james_cataldo at agilent.com
Sent: Thursday, August 03, 2006 11:49 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] input vs. output ASTs in a tree parser

Hi Folks,

Suppose I have the following very basic tree parser:

> class FooParser extends TreeParser;
>
> options {
>     importVocab = Foo;
>     buildAST = true;
> }
> 
> parent!
> :
>     #(PARENT childLabel:child
>         {#parent = #childLabel;}
>     )
> ;
>
> child!
> :
>     #(CHILD barLabel:BAR
>         {#child = #barLabel;}
>     )
> ;

If I give as input to the parent() method of FooParser a tree of type
> #(PARENT #(CHILD BAR))
does the output of FooPrarser.getAST() return a tree of type
> #(CHILD BAR)
or a tree of type
> #(BAR)

In other words, does #childLabel refer to the input AST parsed by the child subrule or the output AST generated by the child subrule?

Cheers,
Adam Cataldo


More information about the antlr-interest mailing list