[antlr-interest] TokenStreamRewriteEngine: possible to use non-terminals instead of tokens?

Terence Parr parrt at cs.usfca.edu
Wed Feb 4 12:54:36 PST 2004


Yeah, instance variables are not so good, but much easier that passing 
something back a million times.  The new attribute mechanism for ANTLR 
will solve this.  To simulate, just created a stack for for every 
attribute you want.  Every time you enter a rule where you want to 
define an attribute, push a new value and then pop at end of rule.  
Here you'd do

IntAttributeStack typeIndexAttr = ... ;

Then in the rule you want to delete the type, do this:

{
typeIndexAttr.push(null);
}

then

{
typeIndexAttr.pop();
}

at the end.

In the typeSpec rule then, you'll set the top of stack to be a value.  
Back in the defining rule, you can peek at the top of stack and ask for 
the index. :)

This ensures that nested constructs work properly.

Ter


On Feb 4, 2004, at 12:19 PM, SainTiss wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Wednesday 04 February 2004 20:08, Terence Parr wrote:
>>
>> There is no typeSpec.  Remember that antlr generates a method for each
>> rule not a class, which is really icky...
>>
>> just define an instance variable and set it with an action.
>
> Hrmm, I'm wondering if that's a safe way to go about?
> Suppose you've got the following statement:
>
> MyType myVar = new MyInterface {
> 		public myMethod() {
> 			int c = 5;
> 		}
> 	};
>
> And suppose I'd like to get rid of "MyType", but not "int".
> Working with one instance variable, it would probably work in this 
> case, as
> "MyType" will be parsed before "int". But suppose I'd like to get rid 
> of the
> initializer instead... Then "5" will be parsed before "new 
> MyInterface....",
> so "5" will be deleted instead of "new MyInterface....", right?
> If this is all true, then I guess a more intelligent mechanism will be 
> needed,
> agree?
>
> Thanks,
>
> Hans
>
>>
>> Ter
>>
>>> Thanks,
>>>
>>> Hans
>>>
>>>
>>> - --
>>> Ark Linux - Linux for the Masses (http://arklinux.org)
>>>
>>> Capitalism:
>>> You don't have any cows. The bank will not lend you money to buy 
>>> cows,
>>> because you don't have any cows to put up as collateral.
>>>
>>> Representative Democracy:
>>> You have two cows. Your neighbors pick someone to tell you who gets
>>> the milk.
>>>
>>> In a world without walls and fences, who needs windows and gates?
>>>
>>> Hans Schippers
>>> 2LIC INF
>>> UA 2003-2004
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.2.3 (GNU/Linux)
>>>
>>> iD8DBQFAIUGjXlnUYIbmLOQRAh3yAJ9mvkG9Vb/WD0j75gz509+EoiFNAQCffpL4
>>> AKza8UQe1wOT0oSXtZIal18=
>>> =mWv8
>>> -----END PGP SIGNATURE-----
>>>
>>>
>>>
>>>
>>> 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/
>>
>> --
>> Professor Comp. Sci., University of San Francisco
>> Creator, ANTLR Parser Generator, http://www.antlr.org
>> Co-founder, http://www.jguru.com
>> Co-founder, http://www.knowspam.net enjoy email again!
>> Co-founder, http://www.peerscope.com pure link sharing
>>
>>
>>
>>
>>
>>
>> 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/
>
> - --
> Ark Linux - Linux for the Masses (http://arklinux.org)
>
> Capitalism:
> You don't have any cows. The bank will not lend you money to buy cows,
> because you don't have any cows to put up as collateral.
>
> Representative Democracy:
> You have two cows. Your neighbors pick someone to tell you who gets 
> the milk.
>
> In a world without walls and fences, who needs windows and gates?
>
> Hans Schippers
> 2LIC INF
> UA 2003-2004
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFAIVO0XlnUYIbmLOQRAtgPAKCl8kHB+5Pho0q9XU0kDEkzuqFbJgCfdSnu
> wGz+p2dCzATm66gORsZyN6M=
> =ne/t
> -----END PGP SIGNATURE-----
>
>
>
>
> 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/
>
>
>
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com pure link sharing




 

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