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

SainTiss saintiss at arklinux.org
Wed Feb 4 13:31:05 PST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I must be misunderstanding this, because as far as I can see, this won't work 
in general...
Having a stack will work if there's a rule which calls itself directly or 
indirectly.
But rules called by this rule might also be calling themselves, which would 
reintroduce the problem that the top of stack is being overwritten.
Additionally (supposing I'm trying to delete an identifier), there may be 
subsequent identifiers, which are at the same nesting level, and so the top 
of stack will again be overwritten...
Trivial case:
myRule: identifier identifier otherRule;
Suppose I'm trying to get the index of the first identifier, that won't work, 
because the second will already have overwritten it... I know I could check 
the top of stack before the second identifier is parsed, but of course this 
is a trivial case, and in more complex cases it won't be so clear which parts 
of the rule will potentially overwrite the top of stack.

But I guess I'm missing something here?

Thanks,

Hans

On Wednesday 04 February 2004 21:54, Terence Parr wrote:
> 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/

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

iD8DBQFAIWSZXlnUYIbmLOQRAqSdAJ9pJ+BPrDaXYNxzzDmP24+sv6rZIACggaS2
JDenhdgqSUbr8Ucrn9dFnGI=
=tv2r
-----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/ 




More information about the antlr-interest mailing list