On Mon, Jun 04, 2001 at 03:43:43PM -0400, Dan Sugalski wrote:
> I think he's looking for something that turns a regex into perl that
> doesn't involve regexes.
Oh, well, if we follow Larry's suggestion and have regexp matching ops,
then we could claim that the regex *is* Perl, it's just written in a
slightly different language. :)
OK, here's how you do it. Run perl -Mre=debug -e '/your regexp/',
and use Perl to parse the bit in the middle. That's a state machine,
so we can emulate it with subroutines.
So, for instance: perl -Mre=debug -e '/fo+bar/'
...
1: EXACT <f>(3)
3: PLUS(6)
4: EXACT <o>(0)
6: EXACT <bar>(8)
8: END(0)
...
Now we translate that to something like this:
sub node_1 {
$state = shift;
while ($_ = substr($state->{string},0,1,"")) {
if ($_ eq "f") {
return success if $state->node_3;
}
}
return failure;
}
... and so on ...
In keeping with tradition, implementation is left as an exercise for
the reader. :)
> (Which isn't to say that I'm not interested in run time for something
> like that if it's to be used in perl 6, but that's a separate issue)
Oh, I see, I see. Sorry, was confusing "implemention of thing for Perl 6"
and "implementation of this handy tool for exploration purposes".
Simon
--
"The elder gods went to Suggoth and all I got was this lousy T-shirt."
- RE: Stacks, registers, and bytecode. (Oh, my!) Hong Zhang
- Re: Stacks, registers, and bytecode. (Oh, my!) David L. Nicol
- Re: Stacks, registers, and bytecode. (Oh, my!) mooring
- Re: Stacks, registers, and bytecode. (Oh, my!) mooring
- Re: Stacks, registers, and bytecode. (Oh, my!) Dan Sugalski
- Re: Stacks, registers, and bytecode. (Oh, my!) Larry Wall
- Re: Stacks, registers, and bytecode. (Oh, my!) Jarkko Hietaniemi
- Re: Stacks, registers, and bytecode. (Oh, my!) David L. Nicol
- Re: Stacks, registers, and bytecode. (Oh, my!) Simon Cozens
- Re: Stacks, registers, and bytecode. (Oh, my!) Dan Sugalski
- Re: Stacks, registers, and bytecode. (Oh, my!) Simon Cozens
- Re: Stacks, registers, and bytecode. (Oh, my!) Jarkko Hietaniemi
- Re: Stacks, registers, and bytecode. (Oh, my!) Dan Sugalski
- Re: Stacks, registers, and bytecode. (Oh, my!) David L. Nicol
- Re: Stacks, registers, and bytecode. (Oh, my!) Uri Guttman
- Re: Stacks, registers, and bytecode. (Oh, my!) Simon Cozens
- Re: Stacks, registers, and bytecode. (Oh, my!) Dan Sugalski
- Re: Stacks, registers, and bytecode. (Oh, my!) Dan Sugalski
- Re: Stacks, registers, and bytecode. (Oh, my!) Uri Guttman
- Re: Stacks, registers, and bytecode. (Oh, my!) Nick Ing-Simmons
- Re: Stacks, registers, and bytecode. (Oh, my!) Dan Sugalski
