As far as I can tell, there are two major flaws with ANTLR's default TreeParsers:
Fortunately, ANTLR is OO, and OO principles tend to make defects in design and implementation easy to correct in a localized fashion. That's the case with this problem. I have written two new classes which you can graft onto your existing solutions with a minimum of hassle, and these classes solve both of the flaws described above.
Here is a summary of the changes you make for this to work. Two new classes are introduced into the hierarchy, as seen below (the new classes are in bold):
Old Hierarchy New Hierarchy
------------- -------------
CommonAST CommonAST
| |
| |
v v
MyAST MyKludgeASTNode <======> MyASTNode
|
|
v
MyAST
I have some sample code. I am too tired to give a lengthy description now. You can grab a directory full of code and run
. ./pf . ./yto compile and run the stuff and see how the old version fails and the new version works.
Here's a summary of the differences:
Here's the C++ version: