develooper Front page | perl.perl6.internals.api.parser | Postings from November 2000

Re: Backtracking through the source

Thread Previous | Thread Next
Simon Cozens
November 27, 2000 16:31
Re: Backtracking through the source
Message ID:
On Mon, Nov 27, 2000 at 11:49:30PM +0000, Tom Hughes wrote:
> In message <>
>           Dan Sugalski <> 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

<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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About