[antlr-interest] Re: more specific (lang independent?) actions (WAS: header sections)

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Nov 18 14:34:50 PST 2004



--- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...> wrote:
> 
> On Nov 18, 2004, at 10:34 AM, Monty Zukowski wrote:
> > On Nov 18, 2004, at 9:59 AM, Terence Parr wrote:
> >> grammar P(...options..., package=org.antlr.test, super=DBGParser);
> >>
> >> import {
> >> import java.io.*;
> >> }
> >>
> >> init {
> >> 	code, not a ctor method def.  Just code to init
> >> 	antlr will generate this into the ctor or whatever
> >> }
> >>
> >> fields {
> >> String currentMethodName;
> >> int level;
> >> }
> >>
> >> methods {
> >> public void computeFoo() {
> >> 	...
> >> }
> >> }
> >>
> >>
> >
> > 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 {
> ....
> }

I like the way this discussion has been going, but even better would
be to use a language qualifier where appropriate:

java header { ... }
or
cpp options { ... }
or
python init { ... }

Then these special actions could be treated as file-level attributes
by the code generators for the target languages.  With any luck, the
language-specificity can be localized to output grammar files.

--Loring

> rather than
> 
> fields {
> }
> 
> A VERY interesting idea.  C++ might need a whole slew of sections...
> 
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!





 
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