[antlr-interest] Tree Grammar: applying a multi-value to a string template
Florian Barth
antlr at florian-barth.de
Fri Apr 24 00:53:56 PDT 2009
Hi there!
I'm working on a tool that translates from my DSL to source code (e.g.
Java). Being an AntLR rookie I was surprised of my good progress, but
finally I ran into a problem that needs some experts' opinion :)
My language allows to define random distributions for certain values:
My parser generates an AST that looks like this: ^(UNIFORM ^(VALUES
atom*)). Using output=template and the programming language specific
templates I have the following problem:
In my tree grammar I have the following rule:
^(UNIFORM ^(VALUES (val+=atom)*))
-> uniform(values={$val})
This matches perfectly and supplies the uniform-template with the
according values. As the contained atoms need further parsing and
rewriting I thought of inserting a nice ".st" into the rewrite rule:
-> uniform(values={$val.st})
I used this before for single values with great results. However in
this case I need to further evaluate further rules for each element of
the list and then hand it over to the template.
An example for these further computations would be the transformation
of the separator in floats.
It would be great if somebody had an idea to help me :)
Regards,
Florian
More information about the antlr-interest
mailing list