[antlr-interest] Parsing optional component in Tree Walker

Peter Kronenberg PKronenberg at technicacorp.com
Mon Apr 11 05:43:16 PDT 2005


I have a tree walker that needs to deal with an optional component C.

If tree is #(ROOT A B) then call handleAB(a.getText(), b.getText()).
If tree is #(ROOT A B C) then call handleAB(a.getText(), b.getText(),
true);

The handler for C has already set some stuff, but handleAB needs to know
about it.  Since there is likely to be recursion while walking the tree,
setting a variable isn't feasable.

What I've come up with is

(#(ROOT A B C)) => #(ROOT a:A b:B C) {
   handleAB(#a.getText(), #b.getText(), true);
}
| #(ROOT A B) {
   handleAB(#a.getText(), #b.getText());
}

It seems a bit kludgy and redundant.  Is there a better way?
I can adjust the parameters of handleAB, but I need some indication if
the optional C is there


Peter Kronenberg
Software Engineer
(703) 885-1222
pkronenberg at technicacorp.com


The information contained in this transmission may contain privileged and confidential information. It is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Technica Corporation does not represent this e-mail to be free from any virus, fault or defect and it is therefore the responsibility of the recipient to first scan it for viruses, faults and defects. To reply to our e-mail administrator directly, please send an e-mail to postmaster at technicacorp.com. Thank you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050411/4b3fa6eb/attachment-0001.html


More information about the antlr-interest mailing list