[antlr-interest] Yet another idea for a completly generic
TreeParser
Terence Parr
parrt at cs.usfca.edu
Sun May 15 08:33:00 PDT 2005
On May 14, 2005, at 11:34 PM, Prashant Deva wrote:
> 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?
Hi Prashant. I like it. :) A very interesting twist. How general
would it have to be I wonder to be useful. For example, could it be
just the method names to use? Probably not. I think that if we
could agree on the available arguments to functions such as the child
index etc... we could let the user specify templates. This is one
nice thing about using StringTemplate for code gen.
Loring and Monty and I discussed something like this for tokens and
ASTs at the Oregon ANTLR cabal. But we thought in terms of what
properties you could have. Perhaps we should go further and specify
the templates used to do common operations. For example, here's one
kind of tree access using ST notation:
getChild(node,index) ::= "node.getChild(index)"
and here's another:
getChild(node,index) ::= "node.children[index]"
Interesting. In this way there would be no penalty going through a
tree adapter for example to access the other tree.
Hmm...I also like no casting...I'm getting mighty tired of casting
when using data structures I can tell ya!
Great line of thinking! Can anybody think of problems?
Ter
More information about the antlr-interest
mailing list