[antlr-interest] Fundamental tree parsing question

Richard Clark rdclark at gmail.com
Tue Jul 10 11:20:41 PDT 2007


On 7/10/07, Ted Villalba <ted.villalba at gmail.com> wrote:
> Hi,
>
> I'm stuck trying to figure out how to distinguish between multi-term values
> in a syntax tree.
> For instance, the following rule rewrites to a simple tree:
>
> field    : tag '=' LPAREN value RPAREN -> ^('=' tag value)

Use subtrees:

tokens { TAG; VALUE; }

field    : tag '=' LPAREN value RPAREN -> ^('=' tag value) ;

tag : ID -> ^(TAG ID) ;

value : NUMBER -> ^(VALUE NUMBER) ;

// end of the example

So something like :
TAG A=(THE TREE TEST)

Will give you:

(= (TAG A) (VALUE THE TREE TEST))

 ...Richard


More information about the antlr-interest mailing list