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

Ruslan Zasukhin sunshine at public.kherson.ua
Fri Oct 5 06:33:16 PDT 2001

on 10/5/01 15:10, Ric Klaren at klaren at cs.utwente.nl wrote:

> 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?) )
                     ^^^^^^^^^^^^^^^^^^ only after adding label I think.

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

Hi Ric, 

OF COURSE you must provide backward compatibility. People must not relable
already existed grammars.

So in fact we have only 2 ways to make things better:
> 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.
Yes, 3) is not yet optimal but make things better that right now. Agree.
So this is the minimal target you should do.

And if this is not huge amount of work, why not to make it configurable and
WRITE DOWN that ANTLR in future versions will go to this more optimal way.
On default optimization must be OFF, for existed grammars. Everybody who
develop new grammar will set it ON and will enjoy by better code.

BTW, I still wonder on internal generation code algorithm.
I have not yet look into code, but it very sounds to me that
ANTL read some token of grammar and immediately generate code.

Why ???

Why the GREAT tool that we all use to make compilers,
in most cases the multi-pass compilers:
-- parse and build AST for the whole file
-- optimize tree 
-- generate code

can not self do this in several passes ???

Why ANTLR can not parse the whole grammar and build in RAM AST tree,
later analyze and optimize tree, and only after this generate PERFECT code.

I believe this is possible.
And I believe that such cool man as Terr, can develop such solution.

I do not think that looking into semantic action to see WHAT tokens are used
in it is bad idea.

As for me, I going following Ian technique create custom AST tree and not
use default AST trees. Unfortunately this way cause that in each rule I must
add init section

rule returns [myNode* result]s
    myNodeT* t3;   
    int t4;
    : "drop" "table" t3 = table t4 = drop_behavior
            result = new myNode( t3, t4 );

table returns [myNodeT* result ] : .....;
drop_behavior returns [int result ] : ....;

But if ANTLR will be smart, and if it will be able look by AST tree,
and to see that type of t3 must be myNodeT,
and the type of t4 must be int
then ANTLR could generate correct code using the next grammar only:

rule returns [myNode* result]s
    : "drop" "table" t3 = table t4 = drop_behavior
            result = new myNode( t3, t4 );

I know this is possible in principle.

Best regards,
Ruslan Zasukhin


e-mail: ruslan at paradigmasoft.com
web   : http://www.paradigmasoft.com

To subscribe to the Valentina mail list
send a letter to valentina-on at lists.macserve.net


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

More information about the antlr-interest mailing list