[antlr-interest] ANTLR 3.0 question about common actions

Jamie Herre jlst at gettysgroup.com
Mon Aug 2 08:51:17 PDT 2004


On Jul 28, 2004, at 5:51 PM, Terence Parr wrote:

> lexer grammar(target="Java")
> ....
> NEWLINE : '\n' {if (some-condition) <skip()>;} ;
>
> where <skip()> is a reference to the template called skip in your
> output templates.  It just gets replaced and ANTLR couldn't care less.
> The "Java.stg" file would contain all the stuff one would need to look
> at.

I think this is a great idea.  I'm wondering whether maybe different 
quoting styles could be available for actions. E.g.  This would allow 
old-schoolers to suit themselves and also provide a alternate mode with 
some of the extra punctuation removed.

  // Normal action syntax
NEWLINE : '\n' {if (some-condition) <skip()>;} ;

// Pure target language code
NEWLINE : '\n' %c{if (some-condition) 
callSkipInJavaObjectWithContext();} ;

// Pure ANTRL pseudo-code
NEWLINE : '\n' %a{if (some-condition) skip();} ;

// which would be expanded into
NEWLINE : '\n' {<if(<boolexpr(some-condition)>)> <skip()>;} ;

Ideally, one could write meaningful actions with no target language 
code at all.

Hopefully ANTLR could generate the whole parser in using pseudo-code 
and then expand it into the target language as a last step.

Yikes, a parser generator for code transformation based on code 
transformation.

-Jamie




 
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