FLAT.pm

filter: Statementstmt 71.4% 30 / 42 Branchbran 100% 2 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 10 / 16 Podpod 100% 8 / 8 totaltotal 68.4% 50 / 73 CC 4 SCAR 7.2
CC
4
Cov
68%
__ANON__
6.0
BEGIN
2.5
as_dfa
2.0
CRAP 2.1
« FLAT/Regex/WithExtraOps.pm ↑ Summary FLAT/Symbol.pm »
1 package FLAT;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use FLAT::Regex;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use FLAT::DFA;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $VERSION = q{1.0.4};
10  
11 =head1 NAME
12  
13 FLAT - Formal Language & Automata Toolkit
14  
15 =head2 Name Change Possibility
16  
17 Future releases of this module may very well reflect a name change that is
18 considered to me more I<normal> for Perl modules. When this was originally
19 written (2006) as a homework assignment, the original author was not very
20 well versed in the idiomatic aspects of C<PERL>. Shortly after, a friendly
21 fellow traveller rewrote it. Since then, this module has patiently sat on
22 CPAN waiting for a use. Recently, this use has come in the form of a module
23 for managing sequential consistency in Perl C<&> perl - L<Sub::Genius>.
24  
25 =head1 SYNOPSIS
26  
27 FLAT.pm is the base class of all regular language objects. For more
28 information, see other POD pages. It provides full support for the
29 I<shuffle> operator, which is useful for expressing the regular interleaving
30 of regular languages.
31  
32 =head1 DESCRIPTION
33  
34 This module provides an interface for manipulating the formal language
35 concept of Regular Expressions, which are used to describe Regular
36 Languages, and their equivalent forms of Automata.
37  
38 It's notable that this module supports, in addition to the traditional
39 Regular Expression operators, the C<shuffle> operator (see [1]). This
40 is expressed as an ampersand, C<&>. In addition to this, logical symbols
41 may be multiple characters. This leads to some interesting applications.
42  
43 While the module can do a lot, i.e.:
44  
45 =over 4
46  
47 =item * parse a regular expression (RE) (of the formal regular language
48 variety)
49  
50 =item * convert a RE to a NFA (and similarly, a I<shuffle> of two regular
51 languages to a I<parallel> NFA (PFA))
52  
53 =item * convert a PFA to a NFA (note, PFAs are equivalent to PetriNets
54 (see [2], L<Graph::PetriNet>)
55  
56 =item * convert a NFA to a DFA
57  
58 =item * convert a DFA to a minimal DFA
59  
60 =item * generate strings that may be accepted by a DFA
61  
62 =back
63  
64 It is still missing some capabilities that one would expect:
65  
66 =over 4
67  
68 =item * generate equivalent REs from a NFA or DFA
69  
70 =item * provide targeted conversion of PFAs, NFAs, DFAs to their more
71 explicit state forms; this is particularly interested to have in the case
72 of the PFA.
73  
74 =item * provide targeted serialization of PREs (REs with a shuffle)
75 using direct, explicit manuplation of the AST produced by the parser
76  
77 =item * provide other interesting graph-based manipulations that might
78 prove useful, particular when applied to a graph that represents some
79 form of a finite automata (FA)
80  
81 =back
82  
83 In addition to the above deficiencies, application of this toolkit in
84 interesting areas would naturally generate ideas for new and interesting
85 capabilities.
86  
87 =head2 Sequential Consistency and PREs
88  
89 Valid strings accepted by the shuffle of one or more regular languages is
90 necessarily I<sequentially consistent>. This results from the conversions
91 to a DFA that may be traversed inorder to discover valid string paths
92 necessarily obeys the total ordering constraints of each constituent
93 language of the two being shuffled; and the partial ordering that results
94 among valid string accepted by both (see [2] for more on how PetriNets
95 fit in).
96  
97 =head1 USAGE
98  
99 All regular language objects in FLAT implement the following methods.
100 Specific regular language representations (regex, NFA, DFA) may implement
101 additional methods that are outlined in the repsective POD pages.
102  
103 =cut
104  
105 ## let subclasses implement a minimal set of closure properties.
106 ## they can override these with more efficient versions if they like.
107  
108 0 ▶sub as_dfa {
Subroutine as_dfa: not called CC=1 SCAR=6.9
Pod documented
109 0 my @params = @_;
110 0 return $params[0]->as_nfa->as_dfa;
111 }
112  
113 0 ▶sub as_min_dfa {
Subroutine as_min_dfa: not called CC=1 SCAR=6.9
Pod documented
114 0 my @params = @_;
115 0 return $params[0]->as_dfa->as_min_dfa;
116 }
117  
118 0 ▶sub is_infinite {
Subroutine is_infinite: not called CC=1 SCAR=6.9
Pod documented
119 0 my @params = @_;
120 0 return !$params[0]->is_finite;
121 }
122  
123 0 ▶sub star {
Subroutine star: not called CC=1 SCAR=6.9
Pod documented
124 0 my @params = @_;
125 0 return $params[0]->kleene
126 }
127  
128 6 ▶sub difference {
Subroutine difference: called CC=1 SCAR=0.0
Pod documented
129 6 my @params = @_;
130 6 return $params[0]->intersect($params[1]->complement);
131 }
132  
133 6 ▶sub symdiff {
Subroutine symdiff: called CC=2 SCAR=6.9
Pod documented
134 6 my $self = shift;
135 6 ▶ return $self if not @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 3 3 6
136 3 my $next = shift()->symdiff(@_);
137 3 return ($self->difference($next))->union($next->difference($self));
138 }
139  
140 3 ▶sub equals {
Subroutine equals: called CC=1 SCAR=0.0
Pod documented
141 3 my @params = @_;
142 3 return $params[0]->symdiff($params[1])->is_empty();
143 }
144  
145 0 ▶sub is_subset_of {
Subroutine is_subset_of: not called CC=1 SCAR=6.9
Pod documented
146 0 my @params = @_;
147 0 return $params[0]->difference($params[1])->is_empty;
148 }
149  
150 6 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=9.2
151 6 for my $method (
152 qw[ as_nfa as_regex union intersect complement concat
153 kleene reverse is_empty is_finite ]
154 ) {
155 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
156 0 ▶ *$method = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
157 0 ▶ my $pkg = ref $_[0] || $_[0];
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
158 0 carp "$pkg does not (yet) implement $method";
159 60 };
160 }
161 }
162  
163 6 1;
164  
165 __END__
« FLAT/Regex/WithExtraOps.pm ↑ Summary FLAT/Symbol.pm »