abstract syntax tree - ANTLR - Linking nodes of an AST -
I want to know how I can define in grammar file, that the "two mothers of the AST node" -father ". For example, if the tree of the first tree is also a child of 'n' node 'A', then what syntax should I use so that the node 'D' does not appear repeatedly (I want something like a second tree).
A | | | ------- | B.C. DA / \ / | | ---- | | B.C. \ | D
If I do something like this:
ABCD -> ^ (AB ^ (cd) d)
The node 'D' will appear repeatedly.
AFAIK, there is no convenient API for this, you must manually copy AST, and then Put this in your rewrite rule:
@parser :: members {GeneralTree Copy (CommonType Origin) {// http://stackoverflow.com/Questions/6781019/Englo-Duplicate -a-tree return copy effectual; }} Rules: A BCD - & gt; ^ (A b ^ (cd) {copy ($ d.tree)});
Comments
Post a Comment