[antlr-interest] Re: RFC: slight change in ! semantics

lgc at mail1.jpl.nasa.gov lgc at mail1.jpl.nasa.gov
Sat Oct 6 15:30:38 PDT 2001

--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
> On Friday, October 5, 2001, at 05:10 AM, Ric Klaren wrote
> > So the options are:
> > 1) No optimization and generate 'sloppy' code until a later 
> > 2) Label the IDENT and use the label in cases like this.
> > 3) always generate declarations for things like IDENT (not for 
> > like
> >    "class" since you can't reference it in actions (can't?) )
> This is a shortcut that will work and a decent compiler will remove 
> code for creating the value if it can determine the ctor is 
> free.  Yeah, right. ;)
> Since the AST action is special, it's best to track which tokens are 
> referenced and update the "generate AST node" boolean for that 
> item.  These actions have to be translated anyway, so a simple check 
> inside the action recognizer should fix this.  Oh wait, actually, 
> that.  You'd have to do 2 passes over the rule looking for backward 
> references.  Ick.
> Option 3 is good for now and optimization folks can simply rewrite 
> not use the rule level ! and use individual ! on the grammar 
> Ter

I've been trying to keep away from the discussions here while trying 
to finish the tree grammar generation.  There is actually a fifth 
option.  Option 3 recognizes ! as having semantics "create, but do not 
automatically link this into the syntax tree", which is the semantics 
carried over from PCCTS and allows manual reconstruction of tree 
segments.  Changing the semantics to "do not create" would be a bit 
drastic.  However (option 5:), it would not be too difficult to add a 
new annotation, "!!", to the ANTLR grammar with the "do not create" 
semantics (in antlr.g, there are only three or four references to 
BANG; BANGBANG could be added as an alternative, and the 
modification to the code generator would be minimal).

With the explicit tree construction stuff that I have a working 
version of and Ter is currently looking at, it should be possible to 
never have to build a tree in actions (AST nodes, yes, but they would 
then be specified to be part of a tree) and better optimization is 
possible--in particular, it is possible to track which AST nodes are 
used without requiring ANTLR to understand the target language.

BTW, ANTLR code generation is not as good as in PCCTS (Ter had some 
time to polish that and had paying customers), and the AST code 
generation is a bit careless.  AST generation code is built when 
grammar.buildAST == false (in the Java version, at least).  That can 
be fixed fairly quickly, but I've had to fix a few other defects in 
AST generation code (! is only partially implemented in 2.7.1; ! on a 
subrule, for example, is supported in the grammar, but 
behavior.noASTsubrule() is not implemented).



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list