[antlr-interest] invoke subtemplates on multivalue attribute
Florian Barth
antlr at florian-barth.de
Thu Apr 30 02:25:28 PDT 2009
Hi everyone!
I'm writing a language transformator based on AntLR and I'm running
into some problems:
In order to transform conditional statement my parser constructs the
following AST:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: condition AST.png
Type: image/png
Size: 14509 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090430/f98c8835/attachment.png
-------------- next part --------------
In my Tree Grammar I'm having some problems with the multiple ELSEIF
nodes.
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 first problem I'm running into is that '?' and '*' seem to be not
allowed in tree grammars. I could split the rule into a rule that
contains an else and one without. This works for ELSE, but I think
it's not really applicable to ELSEIF as this would lead to very many
alternative rules.
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.
Does anyone have a solution to the problems or perhaps recommend
another approach for tackling this task?
Regards,
Florian Barth
More information about the antlr-interest
mailing list