line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Revision: 1.5 $ $Date: 2006/03/02 21:00:28 $ $Author: estrabd $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package FLAT::Legacy::FA; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
54236
|
use base 'FLAT'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1054
|
|
6
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
55
|
|
7
|
3
|
|
|
3
|
|
11
|
use Carp; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
131
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1586
|
use Data::Dumper; |
|
3
|
|
|
|
|
23950
|
|
|
3
|
|
|
|
|
3917
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub set_start { |
12
|
2640
|
|
|
2640
|
0
|
2192
|
my $self = shift; |
13
|
2640
|
|
|
|
|
1945
|
my $state = shift; |
14
|
2640
|
|
|
|
|
2809
|
chomp($state); |
15
|
2640
|
|
|
|
|
2430
|
$self->{_START_STATE} = $state; |
16
|
|
|
|
|
|
|
# add to state list if not already there |
17
|
2640
|
|
|
|
|
2986
|
$self->add_state($state); |
18
|
2640
|
|
|
|
|
2863
|
return; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub get_start { |
22
|
2520
|
|
|
2520
|
0
|
2061
|
my $self = shift; |
23
|
2520
|
|
|
|
|
4350
|
return $self->{_START_STATE}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub is_start { |
27
|
1355
|
|
|
1355
|
0
|
1132
|
my $self = shift; |
28
|
1355
|
|
|
|
|
990
|
my $test = shift; |
29
|
1355
|
|
|
|
|
1424
|
chomp($test); |
30
|
1355
|
|
|
|
|
1001
|
my $ok = 0; |
31
|
1355
|
50
|
|
|
|
2029
|
if ($self->{_START_STATE} eq $test) {$ok++}; |
|
0
|
|
|
|
|
0
|
|
32
|
1355
|
|
|
|
|
2812
|
return $ok; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_state { |
36
|
41679
|
|
|
41679
|
0
|
29036
|
my $self = shift; |
37
|
41679
|
|
|
|
|
38776
|
foreach my $state (@_) { |
38
|
45847
|
100
|
|
|
|
47720
|
if (!$self->is_state($state)) { |
39
|
18699
|
|
|
|
|
12463
|
push(@{$self->{_STATES}},$state); |
|
18699
|
|
|
|
|
52120
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
41679
|
|
|
|
|
49529
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Returns array of states |
46
|
|
|
|
|
|
|
sub get_states { |
47
|
127718
|
|
|
127718
|
0
|
87966
|
my $self = shift; |
48
|
127718
|
|
|
|
|
73896
|
return @{$self->{_STATES}}; |
|
127718
|
|
|
|
|
1351750
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub ensure_unique_states { |
52
|
1134
|
|
|
1134
|
0
|
1099
|
my $self = shift; |
53
|
1134
|
|
|
|
|
954
|
my $NFA1 = shift; |
54
|
1134
|
|
|
|
|
913
|
my $disambigator = shift; |
55
|
1134
|
|
|
|
|
1234
|
chomp($disambigator); |
56
|
1134
|
|
|
|
|
1704
|
foreach ($self->get_states()) { |
57
|
21634
|
|
|
|
|
15935
|
my $state1 = $_; |
58
|
21634
|
|
66
|
|
|
21794
|
while ($NFA1->is_state($state1) && !$self->is_state($disambigator)) { |
59
|
1
|
|
|
|
|
13
|
$self->rename_state($state1,$disambigator); |
60
|
|
|
|
|
|
|
# re-assign $state1 with new name |
61
|
1
|
|
|
|
|
2
|
$state1 = $disambigator; |
62
|
|
|
|
|
|
|
# get new disambiguator just incase this is not unique |
63
|
1
|
|
|
|
|
71
|
$disambigator = crypt(rand 8,join('',[rand 8, rand 8])); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
1134
|
|
|
|
|
2676
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub number_states { |
70
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
71
|
0
|
|
|
|
|
0
|
my $number = 0; |
72
|
|
|
|
|
|
|
# generate 5 character string of random numbers |
73
|
0
|
|
|
|
|
0
|
my $prefix = crypt(rand 8,join('',[rand 8, rand 8])); |
74
|
|
|
|
|
|
|
# add random prefix to state names |
75
|
0
|
|
|
|
|
0
|
foreach ($self->get_states()) { |
76
|
0
|
|
|
|
|
0
|
$self->rename_state($_,$prefix."_$number"); |
77
|
0
|
|
|
|
|
0
|
$number++; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
# rename states as actual numbers |
80
|
0
|
|
|
|
|
0
|
$number = 0; |
81
|
0
|
|
|
|
|
0
|
foreach ($self->get_states()) { |
82
|
0
|
|
|
|
|
0
|
$self->rename_state($_,$number); |
83
|
0
|
|
|
|
|
0
|
$number++; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
0
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub append_state_names { |
89
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
90
|
0
|
|
|
|
|
0
|
my $suffix = shift; |
91
|
0
|
0
|
|
|
|
0
|
if (defined($suffix)) { |
92
|
0
|
|
|
|
|
0
|
chomp($suffix); |
93
|
|
|
|
|
|
|
} else { |
94
|
0
|
|
|
|
|
0
|
$suffix = ''; |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
0
|
foreach ($self->get_states()) { |
97
|
0
|
|
|
|
|
0
|
$self->rename_state($_,"$_".$suffix); |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
0
|
return; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub prepend_state_names { |
103
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
104
|
0
|
|
|
|
|
0
|
my $prefix = shift; |
105
|
0
|
0
|
|
|
|
0
|
if (defined($prefix)) { |
106
|
0
|
|
|
|
|
0
|
chomp($prefix); |
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
0
|
$prefix = ''; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
0
|
foreach ($self->get_states()) { |
111
|
0
|
|
|
|
|
0
|
$self->rename_state($_,$prefix."$_"); |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
0
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Will test if the string passed to it is the same as a label of any state |
117
|
|
|
|
|
|
|
sub is_state { |
118
|
121931
|
|
|
121931
|
0
|
84280
|
my $self = shift; |
119
|
121931
|
|
|
|
|
135431
|
return $self->is_member(shift,$self->get_states()); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Adds state to final (accepting) state stack |
123
|
|
|
|
|
|
|
sub add_final { |
124
|
6279
|
|
|
6279
|
0
|
4375
|
my $self = shift; |
125
|
6279
|
|
|
|
|
5571
|
foreach my $state (@_) { |
126
|
6300
|
50
|
|
|
|
6952
|
if (!$self->is_final($state)) { |
127
|
|
|
|
|
|
|
# ensure state is in set of states - uniqueness enforced! |
128
|
6300
|
|
|
|
|
7182
|
$self->add_state($state); |
129
|
6300
|
50
|
|
|
|
6723
|
if (!$self->is_final($state)) { |
130
|
6300
|
|
|
|
|
4243
|
push(@{$self->{_FINAL_STATES}},$state); |
|
6300
|
|
|
|
|
9167
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
6279
|
|
|
|
|
8909
|
return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub remove_final { |
138
|
88
|
|
|
88
|
0
|
131
|
my $self = shift; |
139
|
88
|
|
|
|
|
108
|
my $remove = shift; |
140
|
88
|
|
|
|
|
94
|
my $i = 0; |
141
|
88
|
|
|
|
|
181
|
foreach ($self->get_final()) { |
142
|
309
|
100
|
|
|
|
426
|
if ($remove eq $_) { |
143
|
88
|
|
|
|
|
87
|
splice(@{$self->{_FINAL_STATES}},$i); |
|
88
|
|
|
|
|
186
|
|
144
|
|
|
|
|
|
|
} |
145
|
309
|
|
|
|
|
290
|
$i++; |
146
|
|
|
|
|
|
|
} |
147
|
88
|
|
|
|
|
164
|
return; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# Returns array of final states |
151
|
|
|
|
|
|
|
sub get_final { |
152
|
32284
|
|
|
32284
|
0
|
21401
|
my $self = shift; |
153
|
32284
|
|
|
|
|
19264
|
return @{$self->{_FINAL_STATES}} |
|
32284
|
|
|
|
|
45843
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# Will test if the string passed to it is the same as a label of any state |
157
|
|
|
|
|
|
|
sub is_final { |
158
|
28565
|
|
|
28565
|
0
|
20492
|
my $self = shift; |
159
|
28565
|
|
|
|
|
29715
|
return $self->is_member(shift,$self->get_final()); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Adds symbol |
163
|
|
|
|
|
|
|
sub add_symbol { |
164
|
31867
|
|
|
31867
|
0
|
25421
|
my $self = shift; |
165
|
31867
|
|
|
|
|
27858
|
foreach my $symbol (@_) { |
166
|
32103
|
100
|
|
|
|
35088
|
if (!$self->is_symbol($symbol)) { |
167
|
4578
|
|
|
|
|
3045
|
push(@{$self->{_SYMBOLS}},$symbol); |
|
4578
|
|
|
|
|
6387
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
31867
|
|
|
|
|
36658
|
return; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Will test if the string passed to it is the same as a label of any symbol |
174
|
|
|
|
|
|
|
sub is_symbol { |
175
|
71981
|
|
|
71981
|
0
|
52647
|
my $self = shift; |
176
|
71981
|
|
|
|
|
48510
|
return $self->is_member(shift,@{$self->{_SYMBOLS}}); |
|
71981
|
|
|
|
|
93078
|
|
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Returns array of all symbols |
180
|
|
|
|
|
|
|
sub get_symbols { |
181
|
12275
|
|
|
12275
|
0
|
9588
|
my $self = shift; |
182
|
12275
|
|
|
|
|
8002
|
return @{$self->{_SYMBOLS}}; |
|
12275
|
|
|
|
|
25741
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Returns a hash of all transitions (symbols and next states) for specified state |
186
|
|
|
|
|
|
|
sub get_transition { |
187
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
188
|
0
|
|
|
|
|
0
|
my $state = shift; |
189
|
0
|
|
|
|
|
0
|
print Dumper(caller); |
190
|
0
|
|
|
|
|
0
|
return %{$self->{_TRANSITIONS}{$state}}; |
|
0
|
|
|
|
|
0
|
|
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub get_all_transitions { |
194
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
195
|
0
|
|
|
|
|
0
|
return %{$self->{_TRANSITIONS}}; |
|
0
|
|
|
|
|
0
|
|
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub has_transition_on { |
199
|
4056
|
|
|
4056
|
0
|
2751
|
my $self = shift; |
200
|
4056
|
|
|
|
|
2636
|
my $state = shift; |
201
|
4056
|
|
|
|
|
2674
|
my $symbol = shift; |
202
|
4056
|
|
|
|
|
2497
|
my $ok = 0; |
203
|
4056
|
100
|
|
|
|
9804
|
if (defined($self->{_TRANSITIONS}{$state}{$symbol})) { |
204
|
2541
|
|
|
|
|
1605
|
$ok++; |
205
|
|
|
|
|
|
|
} |
206
|
4056
|
|
|
|
|
7384
|
return $ok; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub has_transitions { |
210
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
211
|
0
|
|
|
|
|
0
|
my $state = shift; |
212
|
0
|
|
|
|
|
0
|
my $ok = 0; |
213
|
0
|
0
|
|
|
|
0
|
if (defined($self->{_TRANSITIONS}{$state})) { |
214
|
0
|
|
|
|
|
0
|
$ok++; |
215
|
|
|
|
|
|
|
} |
216
|
0
|
|
|
|
|
0
|
return $ok; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub delete_transition { |
220
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
221
|
0
|
|
|
|
|
0
|
my $state = shift; |
222
|
0
|
|
|
|
|
0
|
my $symbol = shift; |
223
|
0
|
0
|
0
|
|
|
0
|
if ($self->is_state($state) && $self->is_symbol($symbol)) { |
224
|
0
|
|
|
|
|
0
|
delete($self->{_TRANSITIONS}{$state}{$symbol}); |
225
|
|
|
|
|
|
|
} |
226
|
0
|
|
|
|
|
0
|
return; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub to_file { |
230
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
231
|
0
|
|
|
|
|
0
|
my $file = shift; |
232
|
0
|
|
|
|
|
0
|
chomp($file); |
233
|
0
|
|
|
|
|
0
|
open(FH,">$file"); |
234
|
0
|
|
|
|
|
0
|
print FH $self->to_string(); |
235
|
0
|
|
|
|
|
0
|
close(FH); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub compliment { |
239
|
8772
|
|
|
8772
|
0
|
6809
|
my $self = shift; |
240
|
8772
|
|
|
|
|
5908
|
my $set1 = shift; |
241
|
8772
|
|
|
|
|
6194
|
my $set2 = shift; |
242
|
8772
|
|
|
|
|
6710
|
my @ret = (); |
243
|
|
|
|
|
|
|
# convert set1 to a hash |
244
|
8772
|
|
|
|
|
5824
|
my %set1hash = map {$_ => 1} @{$set1}; |
|
30205
|
|
|
|
|
37735
|
|
|
8772
|
|
|
|
|
7525
|
|
245
|
|
|
|
|
|
|
# iterate of set2 and test if $set1 |
246
|
8772
|
|
|
|
|
7568
|
foreach (@{$set2}) { |
|
8772
|
|
|
|
|
8386
|
|
247
|
9041
|
50
|
|
|
|
16945
|
if (!defined $set1hash{$_}) { |
248
|
0
|
|
|
|
|
0
|
push(@ret,$_); |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
## Now do the same using $set2 |
252
|
|
|
|
|
|
|
# convert set2 to a hash |
253
|
8772
|
|
|
|
|
6191
|
my %set2hash = map {$_ => 1} @{$set2}; |
|
9041
|
|
|
|
|
13106
|
|
|
8772
|
|
|
|
|
7825
|
|
254
|
|
|
|
|
|
|
# iterate of set1 and test if $set1 |
255
|
8772
|
|
|
|
|
6607
|
foreach (@{$set1}) { |
|
8772
|
|
|
|
|
7532
|
|
256
|
30205
|
100
|
|
|
|
39952
|
if (!defined $set2hash{$_}) { |
257
|
21164
|
|
|
|
|
19335
|
push(@ret,$_); |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
# now @ret contains all items in $set1 not in $set 2 and all |
261
|
|
|
|
|
|
|
# items in $set2 not in $set1 |
262
|
8772
|
|
|
|
|
21927
|
return @ret; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# General subroutine used to test if an element is already in an array |
266
|
|
|
|
|
|
|
sub is_member { |
267
|
325302
|
|
|
325302
|
0
|
230411
|
my $self = shift; |
268
|
325302
|
|
|
|
|
219702
|
my $test = shift; |
269
|
325302
|
|
|
|
|
197544
|
my $ret = 0; |
270
|
325302
|
100
|
|
|
|
394785
|
if (defined($test)) { |
271
|
|
|
|
|
|
|
# This way to test if something is a member is significantly faster..thanks, PM! |
272
|
322601
|
100
|
|
|
|
319828
|
if (grep {$_ eq $test} @_) { |
|
15968020
|
|
|
|
|
14326069
|
|
273
|
173971
|
|
|
|
|
116639
|
$ret++; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
} |
276
|
325302
|
|
|
|
|
840036
|
return $ret; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub DESTROY { |
280
|
0
|
|
|
0
|
|
|
return; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
1; |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
__END__ |