> I was wondering this morning whether we ought to write the Perl 6
> parser as a set of recursive regexes. Might make it easier to plug in
> new productions on the fly. And designing the parser around regexes
> might indicate ways in which Perl's regexes are not yet powerful
> enough.
>
There's a very nice section on that stuff in "Algorithms in SNOBOL4"
(AiS4) on doing just that. The extension that he uses to get around some
of the problems in parsing a context-dependent language is defining a
"syntactic routine" that gets called at the appropriate point in the
pattern match to decide whether or not the given token is of the type
needed.
This is done by using SNOBOL's dynamic function evaluation and
conditional assignment during a pattern match. To do this kind of thing
in Perl, we'd need to be able to match a substring, and then call an
arbitrary function in the middle of a pattern match, and to back out the
call if the match failed. AiS4 gives a lot of funky details on how
SNOBOL did this internally, which I can supply if there's any interest...
But the thing you get out of this is that you can do all of your code
generation during the pattern match. Since you do the match and schedule
(but don't execute) the function calls untill the whole match succeeds,
you can do arbitrary look-ahead. You can use conditional assignment to
handle stacking (conditionally) stuff like the branch over the contents
of an if() (if the condition is not true).
Is this just of historical interest, or is it useful? I'm not a
big-league parser person, just an unregenerate SNOBOL programmer with
all these synapses full of old code...
---Joe M.