- or download this
expr := number
| expr ws unary_operator
...
ws := ' ' | '\t' | '\r' | '\n'
Note: I use "chs" as shorthand for 'c' 'h' 's'
- or download this
digit -> /(?<digit> \d )/msx
number -> /(?<number> (?&digit)+ (?:[.](?&digit)*)
| [.](?&digit)+ )/msx
- or download this
qr{
(?(DEFINE)
...
)
\A \s* (?&expr) \s* \z
}msx;
- or download this
String found where operator expected at (re_eval 10) line 1, near "say
+ "matching at ""
(Do you need to predeclare say?)
syntax error at (re_eval 10) line 1, near "say "matching at ""
Compilation failed in regexp at rpg.pl line 137.
- or download this
(?(DEFINE)
(?<expr>
...
\A \s* (?&expr) \s* \z
(?(?{ $^R != 1 }) (*FAIL) )
}msx
- or download this
/(?<NAME>(?&NAME_PAT))(?<ADDR>(?&ADDRESS_PAT))
(?(DEFINE)
(?<NAME_PAT>....)
(?<ADRESS_PAT>....)
)/x
- or download this
(?<number>
( (?> \d+ (?: [.] \d* )? | [.] \d+ ) )
(?{ local @stack = ( @stack, $^N ) })
)
- or download this
qr{
(?(DEFINE)
...
(?{ $result = undef }) (*FAIL)
}msx
- or download this
qr{
(?{ @stack = ();
...
(?(?{ @stack != 1 }) (*FAIL) )
(?{ $result = $stack[0] })
}msx,
- or download this
my $input = join ' ', (1) x 1_001, ('+') x 1_000;
...
s/iter recursive flat
recursive 1.35 -- -99%
iterative 1.47e-02 9103% --
- or download this
# my $input = join ' ', 1, ('1 +') x 1_000;
Rate recursive iterative
recursive 40.5/s -- -40%
iterative 67.6/s 67% --
- or download this
# my $input = join ' ', (1) x 4, ('+') x 3;
Rate recursive iterative
recursive 14306/s -- -17%
iterative 17271/s 21% --
- or download this
qr{
\A \s*
...
\s* \z
(?(?{ $^R != 1 }) (*FAIL) )
}msx,
- or download this
# my $input = join ' ', (1) x 1_001, ('+') x 1_000;
Rate recursive iterative
...
Rate recursive iterative
recursive 28249/s -- -69%
iterative 92593/s 228% --
- or download this
#!//net/perl/5.10.0/bin/perl
use warnings;
...
say "FAILED: $line got $result, expected $input{$line}";
}
}