From: notifies s. of c. c. <per...@li...> - 2007-02-22 22:27:12
|
Revision: 102 http://svn.sourceforge.net/perl-flat/?rev=102&view=rev Author: estrabd Date: 2007-02-22 14:27:12 -0800 (Thu, 22 Feb 2007) Log Message: ----------- dft needs more testing Modified Paths: -------------- trunk/perl-flat/dev-scripts/bdetest.pl trunk/perl-flat/lib/FLAT/DFA.pm Modified: trunk/perl-flat/dev-scripts/bdetest.pl =================================================================== --- trunk/perl-flat/dev-scripts/bdetest.pl 2007-02-22 05:27:24 UTC (rev 101) +++ trunk/perl-flat/dev-scripts/bdetest.pl 2007-02-22 22:27:12 UTC (rev 102) @@ -7,9 +7,12 @@ use FLAT::PFA; use FLAT::Regex::WithExtraOps; -my $dfa = FLAT::Regex->new($ARGV[0])->as_nfa->as_dfa; +my $dfa = FLAT::Regex::WithExtraOps->new($ARGV[0])->as_pfa->as_nfa->as_dfa; use Data::Dumper; +$Data::Dumper::Deepcopy = 1; + #print Dumper($dfa->as_node_list); -$dfa->as_depth_first_tree(); +my $tree = $dfa->as_depth_first_tree(); +print Dumper($tree); Modified: trunk/perl-flat/lib/FLAT/DFA.pm =================================================================== --- trunk/perl-flat/lib/FLAT/DFA.pm 2007-02-22 05:27:24 UTC (rev 101) +++ trunk/perl-flat/lib/FLAT/DFA.pm 2007-02-22 22:27:12 UTC (rev 102) @@ -185,52 +185,55 @@ my %low = (); # "global" lookup table for low my $lastDFLabel = 0; my $recurse_level = 0; # tracks recurse level - my $search = sub { + my $search = sub { }; + $search = sub { my $startNode = shift; - my %treeNode = undef; # initialize + my %treeNode; # initialize $recurse_level++; # <- tracker if (!exists($dflabel{$startNode})) { $dflabel{$startNode} = ++$lastDFLabel; # the order inwhich this link was explored $low{$startNode} = $lastDFLabel; $backtracked{$startNode} = 0; # marks this node as visited before - for cross edge detection # tree node "struct" - really a hash.. - %treeNode = { + %treeNode = ( node => $startNode, parent => undef, - leftchild => undef, - rightchild => undef, + left => undef, + right => undef, first => undef, last => undef, - }; + ); foreach my $adjacent (keys(%{$nodes{$startNode}})) { if (!exists($dflabel{$adjacent})) { # initial tree edge - print "tree edge! $startNode -> $adjacent\n"; # for testing only +# print "tree edge! $startNode -> $adjacent\n"; # for testing only } elsif (-1 == ($dflabel{$adjacent} - $dflabel{$startNode})){ # detects child visiting a parent - print "tree edge, 2nd visit! $startNode is child of $adjacent!\n"; # for testing only +# print "tree edge, 2nd visit! $startNode is child of $adjacent!\n"; # for testing only } elsif ($dflabel{$adjacent} < $dflabel{$startNode}) { # back edge - print "back edge!"; +# print "back edge!"; } elsif ($dflabel{$adjacent} < $dflabel{$startNode}) { # back edge - print "back edge, 2nd visit!\n"; +# print "back edge, 2nd visit!\n"; } - my $child = $search->($adjacentNode); + my $child = $search->($adjacent); if (defined($child)) { $child->{right} = undef; $child->{left} = undef; - $child->{parent} => \%treeNode; - if (!defined($treeNode->{first})) { - $treeNode->{first} = $child; - $treeNode->{last} = $child; + $child->{parent} = \%treeNode; + if (!defined($treeNode{first})) { + $treeNode{first} = $child; + $treeNode{last} = $child; } else { - $child->{left} = $treeNode->{last}; - $treeNode->{last}->{right} = $child; - $treeNode->{last} = $child; + $child->{left} = $treeNode{last}; + $treeNode{last}->{right} = $child; + $treeNode{last} = $child; } } } + # leave + $recurse_level--; # <- tracker + return \%treeNode; } - # leave $recurse_level--; # <- tracker - return \%treeNode; + return undef; }; # start the recursive dft search This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |