Update of /cvsroot/perl-flat/blokhead/dev-scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2283/dev-scripts
Modified Files:
regex-stress.pl
Added Files:
pregex-stress.pl
Log Message:
playing with some dev-scripts
--- NEW FILE: pregex-stress.pl ---
#!/usr/bin/env perl -l
use strict;
use lib qw(../lib);
use FLAT;
use FLAT::Regex::WithExtraOps;
use Data::Dumper;
use Getopt::Long; # used to process commandline options
$|++;
# skirt around deep recursion warning annoyance
local $SIG{__WARN__} = sub { $_[0] =~ /^Deep recursion/ or warn $_[0] };
srand $$;
my %CMDLINEOPTS = ();
# Percent chance of each operator occuring
$CMDLINEOPTS{LENGTH} = 5;
$CMDLINEOPTS{AND} = 10;
$CMDLINEOPTS{OR} = 6;
$CMDLINEOPTS{STAR} = 10;
$CMDLINEOPTS{NEGATE} = 0;
$CMDLINEOPTS{OPEN} = 5;
$CMDLINEOPTS{CLOSE} = 0;
$CMDLINEOPTS{n} = 100;
GetOptions("l=s" => \$CMDLINEOPTS{LENGTH},
"n=s" => \$CMDLINEOPTS{n},
"and=s" => \$CMDLINEOPTS{AND},
"or=s" => \$CMDLINEOPTS{OR},
"star=s" => \$CMDLINEOPTS{STAR},
"neg=s" => \$CMDLINEOPTS{NEGATE},
"open=s" => \$CMDLINEOPTS{OPEN},
"close=s" => \$CMDLINEOPTS{CLOSE},
);
sub getRandomChar {
my $ch = '';
# Get a random character between 0 and 127.
do {
$ch = int(rand 2);
} while ($ch !~ m/[a-zA-Z0-9]/);
return $ch;
}
sub getRandomRE {
my $str = '';
my @closeparens = ();
for (1..$CMDLINEOPTS{LENGTH}) {
$str .= getRandomChar();
# % chance of an "or"
if (int(rand 100) < $CMDLINEOPTS{OR}) {
$str .= "|[]";
} elsif (int(rand 100) < $CMDLINEOPTS{AND}) {
$str .= "&[]";
} elsif (int(rand 100) < $CMDLINEOPTS{STAR}) {
$str .= "*";
} elsif (int(rand 100) < $CMDLINEOPTS{NEGATE}) {
$str .= "~".getRandomChar();
} elsif (int(rand 100) < $CMDLINEOPTS{OPEN}) {
$str .= "(";
push(@closeparens,'[])');
} elsif (int(rand 100) < $CMDLINEOPTS{CLOSE} && @closeparens) {
$str .= pop(@closeparens);
}
}
# empty out @closeparens if there are still some left
if (@closeparens) {
$str .= join('',@closeparens);
}
return $str;
}
for (1..$CMDLINEOPTS{n}) {
my $str = getRandomRE();
my $RE = FLAT::Regex::WithExtraOps->new($str);
print "$str : ".$RE->as_string;
}
Index: regex-stress.pl
===================================================================
RCS file: /cvsroot/perl-flat/blokhead/dev-scripts/regex-stress.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** regex-stress.pl 16 Nov 2005 04:02:30 -0000 1.2
--- regex-stress.pl 24 Feb 2006 07:35:35 -0000 1.3
***************
*** 4,9 ****
use lib qw(../lib);
use FLAT;
! use FLAT::Regex::WithExtraOps;
! use Data::Dumper;
use Getopt::Long; # used to process commandline options
$|++;
--- 4,10 ----
use lib qw(../lib);
use FLAT;
! use FLAT::Regex;
! use FLAT::NFA;
! use FLAT::DFA;
use Getopt::Long; # used to process commandline options
$|++;
***************
*** 16,23 ****
# Percent chance of each operator occuring
$CMDLINEOPTS{LENGTH} = 5;
- $CMDLINEOPTS{AND} = 10;
$CMDLINEOPTS{OR} = 6;
$CMDLINEOPTS{STAR} = 10;
- $CMDLINEOPTS{NEGATE} = 3;
$CMDLINEOPTS{OPEN} = 5;
$CMDLINEOPTS{CLOSE} = 0;
--- 17,22 ----
***************
*** 26,33 ****
GetOptions("l=s" => \$CMDLINEOPTS{LENGTH},
"n=s" => \$CMDLINEOPTS{n},
- "and=s" => \$CMDLINEOPTS{AND},
"or=s" => \$CMDLINEOPTS{OR},
"star=s" => \$CMDLINEOPTS{STAR},
- "neg=s" => \$CMDLINEOPTS{NEGATE},
"open=s" => \$CMDLINEOPTS{OPEN},
"close=s" => \$CMDLINEOPTS{CLOSE},
--- 25,30 ----
***************
*** 51,60 ****
if (int(rand 100) < $CMDLINEOPTS{OR}) {
$str .= "|[]";
- } elsif (int(rand 100) < $CMDLINEOPTS{AND}) {
- $str .= "&[]";
} elsif (int(rand 100) < $CMDLINEOPTS{STAR}) {
$str .= "*";
- } elsif (int(rand 100) < $CMDLINEOPTS{NEGATE}) {
- $str .= "~".getRandomChar();
} elsif (int(rand 100) < $CMDLINEOPTS{OPEN}) {
$str .= "(";
--- 48,53 ----
***************
*** 73,77 ****
for (1..$CMDLINEOPTS{n}) {
my $str = getRandomRE();
! my $RE = FLAT::Regex::WithExtraOps->new($str);
! print "$str : ".$RE->as_string;
}
--- 66,71 ----
for (1..$CMDLINEOPTS{n}) {
my $str = getRandomRE();
! my $RE = FLAT::Regex->new($str);
! print $RE->as_regex();
! print $RE->as_nfa()->as_dfa()->as_min_dfa()->as_summary();
}
|