Greetings! On 11/28/2011 08:08 AM, franck102 wrote: > 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 am surprised. flattening has not been my experience, altho i have not used an alternative for the root node.... > > // 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! > > 3 untested suggestions (i happen to prefer the third, but i am weird;-): ^( (root=AND|root=OR) e1=booleanExpression e2=booleanExpression ) -> ^($root $e1 $e2) or ^( binaryOperator booleanExpression booleanExpression ) // no rewrite or ^( op=binaryOperator e1=booleanExpression e2=booleanExpression ) -> ^($op $e1 $e2) where binaryOperator = AND | OR /* | others go here... */ ; List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.