[antlr-interest] Yet another idea for a completly generic TreeParser

Prashant Deva prashant.deva at gmail.com
Sat May 14 23:34:38 PDT 2005


I have a sort of real twisted idea on how to make Antlr parse any kind of tree.

So lets see,
Problem: Currently we cannot parse stuff like xml dom trees since
their ast interface differs from the AST interface used by antlr tree
parsers.

Solution: All the solution suggested till now suggest to somehow adapt
the 2 different interfaces.
I have got a pretty twisted sort of solution for the whole thing.

What if you could change antlr itself to handle exactly your tree's interface?
Before you go all out bashing my post, read below ;)

Again think everything in terms of functionality and not java interfaces.

We have our antlr treeParser(TP), which requires a certain kind of
functionality that is implemented in the AST interface.

Our interface implements a tree like structure, that can provide the
same kind of functionality.

So instead of doing all the adapting and stuff, why don't we do this-

We take our codeGen of the treeParser.
Currently our codeGen is supposed to generate code for the AST interface.
We tell it to use our XYZ interface, we tell the codeGen how exactly
to achieve the same functionality of IAST from IXYZ.
Eg- instead of IAST.getFirstChild, it should generate IXYZ.getChild(0).

Thus we can leave both antlr and our tree as is, and just modify the
codegen to generate the same kind of funcionality to be used by our
tree. Thus , instead of making the interface of 2 trees similar, we
just put a constrain of having the functionality of the 2 trees same.

Then Antlr will use a completly typeSafe, specifically made TreeParser
for our interface.

The codeGen modification part can be made super simple inside an ide.

So what do you think?

PRASHANT


More information about the antlr-interest mailing list