[antlr-interest] ANTLR 3.0 question about common actions
Monty Zukowski
monty at codetransform.com
Wed Jul 28 13:48:04 PDT 2004
On Jul 28, 2004, at 1:19 PM, Terence Parr wrote:
> So, the main question is: how can we make standard actions in order to
> avoid retargeting issues and yet allow for free-form actions,
> especially those that predicate standard actions?
Currently you have an escape mechanism that says "this is all target
language, but pick out the tree stuff and $ stuff," and offers Ric the
opportunity to complain how ugly this is :)
Inverting it might be appropriate. How about "this is all standard
action language, but pick out special things and treat them as target
language?" Think macros, real syntactic macros, not just text
substitution.
The disconnect comes from not understanding the relationship between
the generated code and the standard actions. I'm thinking of tree
building here. Trees have a model implemented in the target language
and controllers, if you will, implemented through the code generator.
Staring at the generated code yields quite a confusing view! Ah, the
joys of a mangled metaphor.
Nonetheless the current tree building approach is pretty brute force,
which leads to some head scratching code. I think it could be simpler
if the generator code really know what was going on. I'm saying that
it's not writing the code I would write if I were building trees by
hand--whereas the parsing code does meet that goal.
I would argue for building the standard actions not from a code
generator but from a syntactic macro system. It may be that
StringTemplate is already powerful enough to handle this. I would have
to think through some examples to see where the added power of the
macro system would help. Syntactic macros are basically templates
which have access to the AST of the target language. Somewhere in
between may be the right mix for ANTLR. We don't want people to have
to write (and maintain) a C++ parser just to be able to make a C++ code
generator. But having a syntactic awareness of variables might help.
Experimentation is clearly necessary.
Monty
ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit --
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list