[antlr-interest] ANTLR 3.0 question about common actions

Tiller, Michael (M.M.) mtiller at ford.com
Wed Jul 28 14:09:36 PDT 2004


> From: Terence Parr [mailto:parrt at cs.usfca.edu]
> Sent: Wednesday, July 28, 2004 4:19 PM
> Subject: [antlr-interest] ANTLR 3.0 question about common actions
> 
> Howdy,
> 
[...]
> 
> 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?

This is a difficult issue and I'm not sure how to address everything you
are asking for, but I did find it interesting that SLK
(http://home.earthlink.net/~slkpg/) addresses this by having named
actions in the grammar.  In other words, there isn't any target code in
the grammar at all, just names (e.g. method names) that will be filled
in by the object that implement the parser (in whatever language).

This seems like a good way to handle the first issue you raised which is
how to deal with retargeting since the grammar only defines the hooks
that an eventual parser must have, but not all the action code.

The tricky part is the "predicate standard actions"?  By this I'm
assuming you mean things like disambiguation of symbols vs. keywords by
checking a symbol table.  It seems like this would be nearly impossible
to make target language neutral.  Taking the ideas from SLK a step
further, perhaps you could have a different notation for semantic
predicates (which should return a Boolean type in the target language)
from actions.

So your parsers/walkers might look something like:

class CalcTreeWalker extends TreeParser;

expr
  :  #(PLUS a=expr b=expr) $add(a,b)
  |  #(STAR a=expr b=expr) $mult(a,b)
  |  i:INT		         $intLiteral(i)
	;

where 'add', 'mult' and 'intLiteral' could be implemented as methods in
the generated 'CalcTreeWalker' class.  This is, of course, a very simple
case.  I'm just using it to demonstrate how this could be accomplished.
It would obviously be necessary to allow actions to be executed at
different points as well (e.g. for semantic preciates, but also in other
cases).  Just a thought.
 
> Ter

--
Mike



 
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