Am Thursday 30 April 2009 11:25:28 schrieb Florian Barth: > I try to map the conditional statement to StringTemplate with the > following rule: > cond : ^(IF > ^(CONDITION conds+=condExpression) > ^(THEN thens+=expression) > ^(ELSEIF > ^(conds+=CONDITION condExpression) > ^(thens+=THEN expression) > )* > ^(ELSE else=expression)? > ) > -> > conditional(conditions={$conds.st},thens={$thens.st},else={$else.st}) > ; > > The second problem is the application of the StringTemplates in the > Rewrite rule. The forwarding to the expression StringTemplate works > perfect. However applying the conds.st and thens.st to the multi- > valued attributes leads to compiler errors as the templates do not > accept a multi-valued attribute and so does not descend into the rules > responsible for rendering the expressions.
I think antlr is smart in generating multivalue nodes, you can in the parser say something like: if: IF c=cond THEN b=block (ELSEIF c+=cond THEN b+=block)* else? -> ^IF(cond+, block*, else) to generate a tree which allready has the conds and elseif nodes collected. Your tree is then like: ^(IF cond+ block+ else?) Michael 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-interest@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 -~----------~----~----~----~------~----~------~--~---