From: notifies s. of c. c. <per...@li...> - 2007-02-16 22:06:15
|
Revision: 95 http://svn.sourceforge.net/perl-flat/?rev=95&view=rev Author: estrabd Date: 2007-02-16 14:06:13 -0800 (Fri, 16 Feb 2007) Log Message: ----------- found bug in FA->predecessors, but not sure what it really is; need to test FA::as_directed, etc Modified Paths: -------------- trunk/perl-flat/dev-scripts/bdetest.pl trunk/perl-flat/lib/FLAT/FA.pm trunk/perl-flat/lib/FLAT/NFA.pm trunk/perl-flat/lib/FLAT.pm Modified: trunk/perl-flat/dev-scripts/bdetest.pl =================================================================== --- trunk/perl-flat/dev-scripts/bdetest.pl 2007-02-16 19:59:22 UTC (rev 94) +++ trunk/perl-flat/dev-scripts/bdetest.pl 2007-02-16 22:06:13 UTC (rev 95) @@ -4,4 +4,4 @@ use lib qw(../lib); use FLAT::Regex::WithExtraOps; -print FLAT::Regex->new('a')->as_nfa->as_dfa->as_min_dfa->as_undirected; +print FLAT::Regex->new($ARGV[0])->as_nfa->as_dfa->as_min_dfa->trim_sinks->as_undirected; Modified: trunk/perl-flat/lib/FLAT/FA.pm =================================================================== --- trunk/perl-flat/lib/FLAT/FA.pm 2007-02-16 19:59:22 UTC (rev 94) +++ trunk/perl-flat/lib/FLAT/FA.pm 2007-02-16 22:06:13 UTC (rev 95) @@ -205,7 +205,9 @@ } sub predecessors { - shift->clone->reverse->successors(@_); + my $self = shift; + #$self->clone->reverse->successors(@_); + $self->clone->successors(@_); } # reverse - no change from NFA Modified: trunk/perl-flat/lib/FLAT/NFA.pm =================================================================== --- trunk/perl-flat/lib/FLAT/NFA.pm 2007-02-16 19:59:22 UTC (rev 94) +++ trunk/perl-flat/lib/FLAT/NFA.pm 2007-02-16 22:06:13 UTC (rev 95) @@ -211,24 +211,25 @@ # This format is just a undirected graph - so transition and state info is lost sub as_undirected { - my $self = shift; - my @symbols = $self->alphabet(); - my @states = $self->get_states(); - my @lines = (); - foreach (@states) { - my $s = $_; - my @conns = (); - foreach (@symbols) { - my $a = $_; - # foreach state, get all nodes connected to it; ignore symbols and - # treat transitions simply as directed - push(@conns,$self->successors($s,$a)); - push(@conns,$self->predecessors($s,$a)); #<-- something terribly wrong is going on here - } - @conns = $self->array_unique(@conns); - push(@lines,sprintf("%s (%s) %s",$s,($#conns+1),join(' ',@conns))); - } - return sprintf("%s\n%s",($#states+1),join("\n",@lines)); + return "This function is not implemented yet because of weird problem..."; +# my $self = shift; +# my @symbols = $self->alphabet(); +# my @states = $self->get_states(); +# my @lines = (); +# foreach (@states) { +# my $s = $_; +# my @conns = (); +# foreach (@symbols) { +# my $a = $_; +# # foreach state, get all nodes connected to it; ignore symbols and +# # treat transitions simply as directed +# push(@conns,$self->successors($s,$a)); +# push(@conns,$self->predecessors($s,$a)); #<-- something terribly wrong is going on here +# } +# @conns = $self->array_unique(@conns); +# push(@lines,sprintf("%s (%s) %s",$s,($#conns+1),join(' ',@conns))); +# } +# return sprintf("%s\n%s",($#states+1),join("\n",@lines)); } # Format that Dr. Sukhamay KUNDU likes to use in his assignments :) Modified: trunk/perl-flat/lib/FLAT.pm =================================================================== --- trunk/perl-flat/lib/FLAT.pm 2007-02-16 19:59:22 UTC (rev 94) +++ trunk/perl-flat/lib/FLAT.pm 2007-02-16 22:06:13 UTC (rev 95) @@ -107,17 +107,17 @@ COMMANDS: %perl -MFLAT -e - "compare 're1','re2'" # comares 2 regexs | see note [2] - "dump 're1'" # dumps parse trees | see note[1] + "compare 're1','re2'" # comares 2 regexs | see note [2] + "dump 're1'" # dumps parse trees | see note[1] "dfa2gv 're1'" # dumps graphviz graph desc | see note[1] "nfa2gv 're1'" # dumps graphviz graph desc | see note[1] "pfa2gv 're1'" # dumps graphviz graph desc | see note[1] - dfa2directed - nfa2directed - pfa2directed - dfa2undirected - nfa2undirected - pfa2undirected + dfa2directed # dumps directed graph without transitions + nfa2directed # dumps directed graph without transitions + pfa2directed # dumps directed graph without transitions + dfa2undirected #broken # dumps undirected graph without transitions + nfa2undirected #broken # dumps undirected graph without transitions + pfa2undirected #broken # dumps undirected graph without transitions random_pre random_re help @@ -244,6 +244,136 @@ } } +# dumps directed graph using Kundu notation +# Usage: +# perl -MFLAT -e "dfa2directed('a&b&c&d*e*')" +sub dfa2directed { + shift; + use FLAT::Regex::WithExtraOps; + use FLAT::DFA; + use FLAT::NFA; + use FLAT::PFA; + # trims sink states from min-dfa since transitions are gone + if (@_) + { foreach (@_) + { my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa()->as_dfa->as_min_dfa->trim_sinks(); + print $FA->as_directed;} } + else + { while (<STDIN>) + { chomp; + my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa()->as_dfa->as_min_dfa->trim_sinks(); + print $FA->as_directed;} + } + print "\n"; +} + +# dumps directed graph using Kundu notation +# Usage: +# perl -MFLAT -e "nfa2directed('a&b&c&d*e*')" +sub nfa2directed { + shift; + use FLAT::Regex::WithExtraOps; + use FLAT::DFA; + use FLAT::NFA; + use FLAT::PFA; + if (@_) + { foreach (@_) + { my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa(); + print $FA->as_directed;} } + else + { while (<STDIN>) + { chomp; + my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa(); + print $FA->as_directed;} + } + print "\n"; +} + +# dumps directed graph using Kundu notation +# Usage: +# perl -MFLAT -e "pfa2directed('a&b&c&d*e*')" +sub pfa2directed { + shift; + use FLAT::Regex::WithExtraOps; + use FLAT::PFA; + if (@_) + { foreach (@_) + { my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa(); + print $FA->as_directed;} } + else + { while (<STDIN>) + { chomp; + my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa(); + print $FA->as_directed;} + } + print "\n"; +} + +# dumps undirected graph using Kundu notation +# Usage: +# perl -MFLAT -e "dfa2undirected('a&b&c&d*e*')" +sub dfa2undirected { + shift; + use FLAT::Regex::WithExtraOps; + use FLAT::DFA; + use FLAT::NFA; + use FLAT::PFA; + # trims sink states from min-dfa since transitions are gone + if (@_) + { foreach (@_) + { my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa()->as_dfa->as_min_dfa->trim_sinks(); + print $FA->as_undirected;} } + else + { while (<STDIN>) + { chomp; + my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa()->as_dfa->as_min_dfa->trim_sinks(); + print $FA->as_undirected;} + } + print "\n"; +} + +# dumps undirected graph using Kundu notation +# Usage: +# perl -MFLAT -e "nfa2undirected('a&b&c&d*e*')" +sub nfa2undirected { + shift; + use FLAT::Regex::WithExtraOps; + use FLAT::DFA; + use FLAT::NFA; + use FLAT::PFA; + if (@_) + { foreach (@_) + { my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa(); + print $FA->as_undirected;} } + else + { while (<STDIN>) + { chomp; + my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa()->as_nfa(); + print $FA->as_undirected;} + } + print "\n"; +} + +# dumps undirected graph using Kundu notation +# Usage: +# perl -MFLAT -e "pfa2undirected('a&b&c&d*e*')" +sub pfa2undirected { + shift; + use FLAT::Regex::WithExtraOps; + use FLAT::PFA; + if (@_) + { foreach (@_) + { my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa(); + print $FA->as_undirected;} } + else + { while (<STDIN>) + { chomp; + my $FA = FLAT::Regex::WithExtraOps->new($_)->as_pfa(); + print $FA->as_undirected;} + } + print "\n"; +} + # compares 2 give PREs # Usage: # perl -MFLAT -e "compare('a','a&b&c&d*e*')" #<-- no match, btw This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |