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

Ric Klaren klaren at cs.utwente.nl
Fri Oct 5 05:10:59 PDT 2001


Hi,

While porting over my more aggressive AST element declaration generation
scheme from C++ to java I stumbled on a showstopper...

Consider a rule like this (from the java 1.3 grammar):

classDefinition ! [AST modifiers]
	:	"class" IDENT
		// it _might_ have a superclass...
		sc:superClassClause
		// it might implement some interfaces...
		ic:implementsClause
		// now parse the body of the class
		cb:classBlock
		{#classDefinition = #(#[CLASS_DEF,"CLASS_DEF"],
							   modifiers,IDENT,sc,ic,cb);}
	;

The problem is the use of IDENT in the action code and the use of the !
operator. Because the ast generation is turned of no declaration for the
AST for IDENT is made, and I have no nice way of finding out that IDENT is
used in the action (prescanning the action will be ugly AFAIK). I always
used the ! as nothing gets generated and so I always label these tokens in
these cases upon reading the docs it turns out that ANTLR indeed supports
the above (another of these little inconsistencies).

So the options are:
1) No optimization and generate 'sloppy' code until a later release.
2) Label the IDENT and use the label in cases like this.
3) always generate declarations for things like IDENT (not for things like 
   "class" since you can't reference it in actions (can't?) )
4) Making it configurable.

4 is not really a option for me, this just makes a lot of ugly stuff more
ugly.

1 well though luck for me :) put some pieces of code in the fridge.
2 tough luck for the others ;) let them label stuff, it's imho a bit more
consistent to make explicit labeling the default, in stead of ''yah this
turns of all tree generation oh wait a sec no not for tokens.''
3 Sort of the golden middle. It keeps some people like Ruslan ;) slightly
  disgruntled, but nobody has to 'relabel' their grammars.

Well let me know what you think people..

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
Wit is cultured insolence. - Aristotle


 

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



More information about the antlr-interest mailing list