On Mon, Nov 27, 2000 at 11:49:30PM +0000, Tom Hughes wrote: > In message <5.0.1.4.0.20001127163751.024354e0@24.8.96.48> > Dan Sugalski <dan@sidhe.org> wrote: > > > Is there any reasonable case where we would need to backtrack over > > successfully parsed source and redo the parsing? I'm not talking about the > > case where regular expressions run over text and ultimately fail, but > > rather cases where we need to chuck out part of what we have and restart? > > That's effectively analogous to asking how much lookahead you need > to have I doubt it; I get the feeling that what Dan is talking about is infinite look-*behind*. Nine times out of ten, you won't need to redo your parsing, so having an infinite lookahead will just slow everything down. It's the other 1 time that you'll need to say "oops, shit, this token isn't what I thought it was" and it's then that you need to backtrack and re-parse. I had a way of doing this with a module I was working on called Parse::Hairy, but that's gone the way of the missing disk drive. But here's an example of it: sub bar { ... } print foo bar(); Now, having parsed this far, we know that foo is a filehandle that we're printing to, so we build up our op tree to print the results of calling bar() to a filehandle called foo; ooh, but what do we see now: sub foo { ... } Eek, foo was actually a subroutine, and we mean print(foo(bar())); need to redo our parse tree. That's when the lookbehind comes into play. And, yes, that can be done. It's not standard CS stuff, but it's perfectly implementable. -- <Addi> Just imagine we are meeting the aliens for the first time. <ton> Most people would just shoot them to see how many points they are worth.Thread Previous | Thread Next