[antlr-interest] Tree building limitation in tree grammars?
franck102
franck102 at yahoo.com
Mon Nov 28 05:08:13 PST 2011
My parser grammar can generate a number of subtrees with similar structure,
and just a different root type. In the tree grammar I am trying to just pass
such a subtree along without any changes, but that is turning out to be much
trickier than I expected, am I missing something?
Given this AST: ^( AND true false ) I want the tree grammar to generate the
same AST subtree.
The following attempts are not working:
^( ( AND | OR ) booleanExpression booleanExpression ) // no rewrite =>
flattens the tree,
// I get a nil root and 3 children
^( ( root=AND | root=OR ) booleanExpression booleanExpression )
-> ( ( AND | OR ) booleanExpression booleanExpression ) //
syntax error
^( ( root=AND | root=OR ) booleanExpression booleanExpression )
-> ( AND? OR? booleanExpression booleanExpression ) //
syntax error
^( root=(AND | OR ) booleanExpression booleanExpression )
-> ( $root booleanExpression booleanExpression ) // runtime
error, $root is empty
Am I going to have to split those rules??
Any suggestion appreciated!
--
View this message in context: http://antlr.1301665.n2.nabble.com/Tree-building-limitation-in-tree-grammars-tp7038639p7038639.html
Sent from the ANTLR mailing list archive at Nabble.com.
More information about the antlr-interest
mailing list