[antlr-interest] TokenStreamRewriteEngine: possible to use non-terminals instead of tokens?
SainTiss
saintiss at arklinux.org
Wed Feb 4 14:06:12 PST 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wednesday 04 February 2004 22:41, Terence Parr wrote:
> On Feb 4, 2004, at 1:31 PM, SainTiss wrote:
> > -----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.
>
> The stack will handle the recursion properly.
Indeed it will... The problem I was referring too, however, is that it is not
always so obvious whether a rule is going to be recursive or not (because
there might be many alternative sub-rules, and in a large grammar, it's
probably tedious to check which of them eventually calls the original rule
again). And as I see it, it is necessary to find all points of recursion,
because each of those has a potential of overwriting the top of stack...
>
> identifier will set the attribute value and you are free to use it at
> the appropriate time. In your myRule example, you need to make a copy
> of the index value before it calls identifier again. This is
> simulating what a return value bubbling up would do. It's set below,
> but each reference has a copy. The instance variable approach avoids
> the problem of having to define the return value in all the
> intermediate rules and the stack avoids the "what about recursive rule
> ref" problem.
That will work as well, with the same problem as above: you need to be sure
which sub-rules will eventually call "identifier", and make a copy for each
of them. But it may be needed to make copies in sub-rules too, if they
themselves call "identifier" multiple times, and so on...
So in conclusion, I guess it will work, but analyzing where pushes and pops
and copies need to be made, is going to be almost as bad as having to pass a
parameter...
Unless of course I'm overlooking something again, but I think I could make an
example illustrating this if needed...
Thanks,
Hans
>
> Hope this helps...
>
> Ter
> --
> 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)
iD8DBQFAIWzUXlnUYIbmLOQRAiLDAKCBIdgZCo5yJk/7ekLMMM1revUXOwCglsXa
7obwCk7tJg6zl85vzOG04jo=
=min5
-----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