[antlr-interest] Re: more specific (lang independent?) actions (WAS: header sections)
Marq Kole
marq.kole at philips.com
Thu Nov 18 12:17:36 PST 2004
--- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...>
<SNIP>
> > So are these handled by a generic rule like ID '{' (.)* '}'
where the
> > stuff inside is just passed as an attribute to the template? So
> > antlr.g doesn't have to change if some other language needs its
own
> > special block?
>
> Wow. Devious thought. I like the flexibility so any language
target
> could require special code sections. We'd probably have to make it
>
> section fields {
> ....
> }
>
> rather than
>
> fields {
> }
>
> A VERY interesting idea. C++ might need a whole slew of
sections...
What I do like about the current approach is that is extremely easy
to change the way separate sections are defined and used within the
code generator. If you need different types of sections for any
supported language, language independence becomes more of an
theoretical issue than of practical consequences.
It is just very practical to have the
header "name" {
}
sections at the start for any global stuff, and something like
code "name" {
}
sections after the optional actions section (needed for backwards
compatibility) in each of the lexer/parser/treewalker definitions.
The way code generation is currently handled in C++ is different
from that in Python, but it is very easy to make customized sections
and introduce these at the appropriate places in the code generator.
In the end, if you want to rewrite a grammar in ANTLR C++ to ANTLR
Python, you will need to consider how each of the "language
independent" sections translates to the concepts of the other
language.
In the end it all comes down to correctly documenting the available
sections for each of the supported language in the ANTLR runtime
documentation.
Greetz,
Marq
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