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

Matthew Ford Matthew.Ford at forward.com.au
Fri Oct 5 05:50:36 PDT 2001


I vote for 2)
> 2) Label the IDENT and use the label in cases like this.

The "Draft specification for Antlr Tree Generation" I posted a short while
back read
....
Example of a rule based use of ! to disable tree generation

addition!
    :   INT PLUS i:INT
;

In this case no tree generation code is generated for this rule.  If you
want to create a tree by hand for this rule you need to return it as shown
below
addition returns [AST return_tree]!
   :   INT PLUS i:INT  { .. code to generate return_tree }
;


So I suggest this be relaxed a little to say that
No tree generation code is output except that labels in the rule are
initialized with the appropriate minimal tree.
.....


----- Original Message -----
From: "Ric Klaren" <klaren at cs.utwente.nl>
To: "ANTLR mailinglist" <antlr-interest at yahoogroups.com>
Cc: "Terence Parr" <parrt at jguru.com>
Sent: Friday, October 05, 2001 10:10 PM
Subject: [antlr-interest] RFC: slight change in ! semantics


> 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/
>
>


 

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



More information about the antlr-interest mailing list