[antlr-interest] How does AST construction work?

Paul Johnson gt54-antlr at cyconix.com
Mon May 16 10:53:34 PDT 2005


Thanks - I think the fog is slowly lifting...

Bryan Ewbank wrote:
> Try removing the "^" from your example and look at the results.  This
> should help...

I tried this, and the returned tree just contains '2':

expr : mexpr (PLUS mexpr)* SEMI! ;

mexpr : atom (STAR atom)* ;

-----
 > Main
 > 2+4*5;
  2
value is 2
-----

At first sight, it seems to me that the returned list should actually 
have been ( 2 + 4 * 5 ) (with no root - or does the first parsed element 
become the root by default?)

My reasoning is simply that the first call to mexpr returns the list 
(2), then PLUS is appended, and the second call to mexpr returns the 
list (4 STAR 5). How is it that just a single '2' is returned?

Thanks -

Paul



More information about the antlr-interest mailing list