I wouldn't use it in production (right now it only works in perl5.8.3) but I was able to get it to work. I did experience a few segfaults as I tried different features. Some of the other error indications spew mightily!
If you already know lex (or flex), Perl6::Rules will make a lot of sense. I like the way that the rules are declarative. This means that I can change the order of the rules without changing the functionality.
I suspect that Perl6::Rules and Parse::RecDescent can be combined to provide a decent API to implement the front end of a compiler. These may be an acceptable substitute for lex and yacc (or flex and bison).
Perl is already very strong in the data-format-translation domain, and will become much stronger in Perl6. This is because of the re-use capabilities inherent in the collections of regular expressions, which are called grammars.
Here is a simple example that checks if a string represents a number, including scientific notation. For example, it detects that -12e3 is a number but does not say that 1e.2 is a number. Notice that the code defines a grammar, which will be reusable in the same way that a module is reusable. Reusable grammars will increase a perl programmers productivity, since presumably many grammars will be available from CPAN.
use Perl6::Rules; grammar P6G_IsNumeric { rule oporm { <[+-]>? } rule fixed { <oporm> <digit>+ \.? <digit>* | <oporm> <digit>* \.? <digit>+ } rule scino { <fixed> <[eE]> <oporm> <digit>+ | <fixed> | <digit>+ + } } sub is_scino { my $num = shift; if ($num =~ m/^<P6G_IsNumeric.scino>$/) { $num = $num + 0; # is this really necessary? return $num; } return undef; } sub is_fixed { my $num = shift; if ($num =~ m/^<P6G_IsNumeric.fixed>$/) { $num = $num + 0; return $num; } return undef; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl6::Rules Rules
by hv (Prior) on Aug 04, 2004 at 08:23 UTC | |
by duff (Parson) on Aug 04, 2004 at 14:34 UTC | |
by Aristotle (Chancellor) on Aug 04, 2004 at 18:33 UTC | |
|
Re: Perl6::Rules Rules
by tilly (Archbishop) on Aug 04, 2004 at 14:55 UTC | |
|
Perl5 version
by sleepingsquirrel (Chaplain) on Aug 04, 2004 at 17:30 UTC |