[antlr-interest] Question concerning writing a TreeParser rule
Martin Probst
mail at martin-probst.com
Wed Apr 26 05:41:39 PDT 2006
Hi,
it's probably going to be easier if you modify your rule like this:
batchExprList {
boolean multi = false;
} :
batchExpr (SEP! batchExpr { multi = true; })*
{ if (multi) ## = #(#[SEP], ##); }
;
This gives you the follwing tree:
SEP
/ | \
... ... ...
instead of
SEP
/ \
SEP ....
/ \
... ....
This way you can have this tree parser rule:
list: #( SEP ( x=expr { myarraylist.add(x); } )* )
Otherwise you'd have to have a member variable for the tree parser
(current list root or something), check for it's existence, delete it
if necessary etc. - this will make it a lot easier.
Martin
More information about the antlr-interest
mailing list