blib/lib/Parse/Yapp/Driver.pm

filter: Statementstmt 82.4% 216 / 262 Branchbran 70.7% 116 / 164 Conditioncond 57.1% 24 / 42 MC/DCmcdc 22.7% 5 / 22 Subroutinesub 66.6% 16 / 24 Podpod 0.0% 0 / 14 totaltotal 71.4% 377 / 528 CC 99 SCAR 38.4
CC
99
Cov
76%
_DBParse
93.4
_Parse
28.3
_CheckParams
6.1
CRAP 46.7
« blib/lib/Parse/Yapp/Lalr.pm ↑ Summary blib/lib/Parse/Yapp/Grammar.pm »
1 #
2 # Module Parse::Yapp::Driver
3 #
4 # This module is part of the Parse::Yapp package available on your
5 # nearest CPAN
6 #
7 # Any use of this module in a standalone parser make the included
8 # text under the same copyright as the Parse::Yapp module itself.
9 #
10 # This notice should remain unchanged.
11 #
12 # Copyright © 1998, 1999, 2000, 2001, Francois Desarmenien.
13 # Copyright © 2017 William N. Braswell, Jr.
14 # (see the pod text in Parse::Yapp module for use and distribution rights)
15 #
16  
17 package Parse::Yapp::Driver;
18  
19 3 require 5.004;
20  
21 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use vars qw ( $VERSION $COMPATIBLE $FILENAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # CORRELATION #py001: $VERSION must be changed in both Parse::Yapp & Parse::Yapp::Driver
26 3 $VERSION = '1.21';
27 3 $COMPATIBLE = '0.07';
28 3 $FILENAME=__FILE__;
29  
30 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 #Known parameters, all starting with YY (leading YY will be discarded)
33 3 my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '',
34 YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => '');
35 #Mandatory parameters
36 3 my(@params)=('LEX','RULES','STATES');
37  
38 19 ▶sub new {
Subroutine new: called CC=4 SCAR=14.8
Pod undocumented
39 19 my($class)=shift;
40 19 my($errst,$nberr,$token,$value,$check,$dotpos);
41 19 my($self)={ ERROR => \&_Error,
42 ERRST => \$errst,
43 NBERR => \$nberr,
44 TOKEN => \$token,
45 VALUE => \$value,
46 DOTPOS => \$dotpos,
47 STACK => [],
48 DEBUG => 0,
49 CHECK => \$check };
50  
51 19 _CheckParams( [], \%params, \@_, $self );
52  
53 exists($$self{VERSION})
54 19 ▶ and $$self{VERSION} < $COMPATIBLE
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"VERSION"} and $self->{"VERSION"} < $Parse::Yapp::Driver::COMPATIBLE and croak("Yapp driver version $Parse::Yapp::Driver::VERSION " . qq[incompatible with version $self->{"VERSION"}:\n] . 'Please recompile parser module.') 0 19 19
Condition33%1/3
exists $self->{"VERSION"} and $self->{"VERSION"} < $Parse::Yapp::Driver::COMPATIBLE
!ll&&!rl&&r
0190
MC/DC0%0/2
exists $self->{"VERSION"} and $self->{"VERSION"} < $Parse::Yapp::Driver::COMPATIBLE
exists $self->{"VERSION"} $self->{"VERSION"} < $Parse::Yapp::Driver::COMPATIBLE
Truth table33%1/3
A and B
A= exists $self->{"VERSION"}B= $self->{"VERSION"} < $Parse::Yapp::Driver::COMPATIBLE
ABresult
0X0
100
111
55 and croak "Yapp driver version $VERSION ".
56 "incompatible with version $$self{VERSION}:\n".
57 "Please recompile parser module.";
58  
59 19 ▶ ref($class)
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 19 19
60 and $class=ref($class);
61  
62 19 bless($self,$class);
63 }
64  
65 22 ▶sub YYParse {
Subroutine YYParse: called CC=3 SCAR=11.0
Pod undocumented
66 22 my($self)=shift;
67 22 my($retval);
68  
69 22 _CheckParams( \@params, \%params, \@_, $self );
70  
71 22 ▶ if($$self{DEBUG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'DEBUG'}) { } 1 21 22
72 1 _DBLoad();
73 1 $retval = eval '$self->_DBParse()';#Do not create stab entry on compile
74 1 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
75 }
76 else {
77 21 $retval = $self->_Parse();
78 }
79 22 $retval
80 }
81  
82 489 ▶sub YYData {
Subroutine YYData: called CC=2 SCAR=6.9
Pod undocumented
83 489 my($self)=shift;
84  
85 exists($$self{USER})
86 489 ▶ or $$self{USER}={};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"USER"} or $self->{"USER"} = {} 488 1 489
87  
88 489 $$self{USER};
89
90 }
91  
92 3 ▶sub YYErrok {
Subroutine YYErrok: called CC=1 SCAR=0.0
Pod undocumented
93 3 my($self)=shift;
94  
95 3 ${$$self{ERRST}}=0;
96 3 undef;
97 }
98  
99 1 ▶sub YYNberr {
Subroutine YYNberr: called CC=1 SCAR=0.0
Pod undocumented
100 1 my($self)=shift;
101  
102 1 ${$$self{NBERR}};
103 }
104  
105 0 ▶sub YYRecovering {
Subroutine YYRecovering: not called CC=1 SCAR=6.9
Pod undocumented
106 0 my($self)=shift;
107  
108 0 ${$$self{ERRST}} != 0;
109 }
110  
111 0 ▶sub YYAbort {
Subroutine YYAbort: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my($self)=shift;
113  
114 0 ${$$self{CHECK}}='ABORT';
115 0 undef;
116 }
117  
118 22 ▶sub YYAccept {
Subroutine YYAccept: called CC=1 SCAR=0.0
Pod undocumented
119 22 my($self)=shift;
120  
121 22 ${$$self{CHECK}}='ACCEPT';
122 22 undef;
123 }
124  
125 0 ▶sub YYError {
Subroutine YYError: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my($self)=shift;
127  
128 0 ${$$self{CHECK}}='ERROR';
129 0 undef;
130 }
131  
132 6 ▶sub YYSemval {
Subroutine YYSemval: called CC=3 SCAR=12.3
Pod undocumented
133 6 my($self)=shift;
134 6 my($index)= $_[0] - ${$$self{DOTPOS}} - 1;
135  
136 $index < 0
137 6 and -$index <= @{$$self{STACK}}
138 6 ▶ and return $$self{STACK}[$index][1];
Branch: 1 branch
BranchTrueFalseTotal
$index < 0 and -$index <= @{$self->{"STACK"};} and return $self->{"STACK"}[$index][1] 6 0 6
Condition33%1/3
$index < 0 and -$index <= @{$self->{"STACK"};}
!ll&&!rl&&r
006
MC/DC0%0/2
$index < 0 and -$index <= @{$self->{"STACK"};}
$index < 0 -$index <= @{$self->{"STACK"};}
Truth table33%1/3
A and B
A= $index < 0B= -$index <= @{$self->{"STACK"};}
ABresult
0X0
100
111
139  
140 0 undef; #Invalid index
141 }
142  
143 0 ▶sub YYCurtok {
Subroutine YYCurtok: not called CC=2 SCAR=17.9
Pod undocumented
144 0 my($self)=shift;
145  
146 @_
147 0 ▶ and ${$$self{TOKEN}}=$_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and ${$$self{"TOKEN"};} = $_[0] 0 0 0
148 0 ${$$self{TOKEN}};
149 }
150  
151 0 ▶sub YYCurval {
Subroutine YYCurval: not called CC=2 SCAR=17.9
Pod undocumented
152 0 my($self)=shift;
153  
154 @_
155 0 ▶ and ${$$self{VALUE}}=$_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and ${$$self{"VALUE"};} = $_[0] 0 0 0
156 0 ${$$self{VALUE}};
157 }
158  
159 0 ▶sub YYExpect {
Subroutine YYExpect: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my($self)=shift;
161  
162 0 keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
163 }
164  
165 0 ▶sub YYLexer {
Subroutine YYLexer: not called CC=1 SCAR=6.9
Pod undocumented
166 0 my($self)=shift;
167  
168 0 $$self{LEX};
169 }
170  
171  
172 #################
173 # Private stuff #
174 #################
175  
176  
177 41 ▶sub _CheckParams {
Subroutine _CheckParams: called CC=6 SCAR=18.2
178 41 my($mandatory,$checklist,$inarray,$outhash)=@_;
179 41 my($prm,$value);
180 41 my($prmlst)={};
181  
182 41 ▶ while(($prm,$value)=splice(@$inarray,0,2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@$inarray, 0, 2)) 101 41 142
183 101 $prm=uc($prm);
184 101 ▶ exists($$checklist{$prm})
Branch: 1 branch
BranchTrueFalseTotal
exists $checklist->{$prm} or croak("Unknow parameter '${prm}'") 101 0 101
185 or croak("Unknow parameter '$prm'");
186 101 ▶ ref($value) eq $$checklist{$prm}
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq $checklist->{$prm} or croak("Invalid value for parameter '${prm}'") 101 0 101
187 or croak("Invalid value for parameter '$prm'");
188 101 $prm=unpack('@2A*',$prm);
189 101 $$outhash{$prm}=$value;
190 }
191 41 for (@$mandatory) {
192 66 ▶ exists($$outhash{$_})
Branch: 1 branch
BranchTrueFalseTotal
exists $outhash->{$_} or croak(q[Missing mandatory parameter '] . lc($_) . q[']) 66 0 66
193 or croak("Missing mandatory parameter '".lc($_)."'");
194 }
195 }
196  
197 0 ▶sub _Error {
Subroutine _Error: not called CC=1 SCAR=6.9
198 0 print "Parse error.\n";
199 }
200  
201 1 ▶sub _DBLoad {
Subroutine _DBLoad: called CC=5 SCAR=16.7
202 {
203 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 1 exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
206 1 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
exists do { "Parse::Yapp::Driver::" }->{"_DBParse"} and return 0 1 1
207 }
208 1 my($fname)=__FILE__;
209 1 my(@drv);
210 1 ▶ open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
Branch: 1 branch
BranchTrueFalseTotal
open DRV, "<$fname" or die "Report this as a BUG: Cannot open $fname" 1 0 1
211 1 ▶ while(<DRV>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DRV)) 473 1 474
212 /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
213 473 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/ and do { s/^#DBG>//; push @drv, $_ } 243 230 473
214 243 s/^#DBG>//;
215 243 push(@drv,$_);
216 }
217 }
218 1 close(DRV);
219  
220 1 $drv[0]=~s/_P/_DBP/;
221 0 ▶ eval join('',@drv);
Subroutine _DBParse: called CC=51 SCAR=45.4
Subroutine __ANON__: called CC=4 SCAR=14.5
Branch: 43 branches
BranchTrueFalseTotal
$debug & 2 and print STDERR "In state ${stateno}:\n" 59 0 59
$debug & 8 and print STDERR 'Stack:[' . join(",", map({$_->[0];} @$stack)) . "]\n" 59 0 59
if (exists $actions->{'ACTIONS'}) { } 41 18 59
defined $$token or do { ($$token, $$value) = &$lex($self); $debug & 1 and print STDERR 'Need token. Got ' . &$ShowCurToken . "\n" } 11 30 41
$debug & 1 and print STDERR 'Need token. Got ' . &$ShowCurToken . "\n" 30 0 30
exists $actions->{'ACTIONS'}{$$token} ? : 28 13 41
exists $actions->{'DEFAULT'} ? : 10 3 13
$debug & 1 and print STDERR "Don't need token.\n" 18 0 18
defined $act and do { $act > 0 and do { $debug & 4 and print STDERR "Shift and go to state $act.\n"; $$errstatus and do { --$$errstatus; $debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 } }; push @$stack, [$act, $$value]; $$token ne "" and $$token = $$value = undef; next }; my($lhs, $len, $code, @sempar, $semval); () = @{$$rules[-$act];}; $debug & 4 and $act and print STDERR 'Reduce using rule ' . -$act . " ($lhs,$len): "; $act or $self->YYAccept; $$dotpos = $len; unpack("A1", $lhs) eq "\@" and do { $lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '${lhs}' ill formed: " . "report it as a BUG.\n"; $$dotpos = $1 }; @sempar = $$dotpos ? map({$_->[1];} @$stack[-$$dotpos .. -1]) : (); $semval = $code ? &$code($self, @sempar) : (@sempar ? $sempar[0] : undef); splice @$stack, -$len, $len; $$check eq "ACCEPT" and do { $debug & 4 and print STDERR "Accept.\n"; return $semval }; $$check eq "ABORT" and do { $debug & 4 and print STDERR "Abort.\n"; return undef }; $debug & 4 and print STDERR "Back to state $stack->[-1][0], then "; $$check eq "ERROR" or do { $debug & 4 and print STDERR qq[go to state $$states[$stack->[-1][0]]{"GOTOS"}{$lhs}.\n]; $debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 }; push @$stack, [$$states[$stack->[-1][0]]{"GOTOS"}{$lhs}, $semval]; $$check = ""; next }; $debug & 4 and print STDERR "Forced Error recovery.\n"; $$check = "" } 56 3 59
$act > 0 and do { $debug & 4 and print STDERR "Shift and go to state $act.\n"; $$errstatus and do { --$$errstatus; $debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 } }; push @$stack, [$act, $$value]; $$token ne "" and $$token = $$value = undef; next } 28 28 56
$debug & 4 and print STDERR "Shift and go to state $act.\n" 28 0 28
$$errstatus and do { --$$errstatus; $debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 } } 1 27 28
$debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 } 0 1 1
$$token ne "" and $$token = $$value = undef 27 1 28
$debug & 4 and $act and print STDERR 'Reduce using rule ' . -$act . " ($lhs,$len): " 27 1 28
$act or $self->YYAccept 27 1 28
unpack("A1", $lhs) eq "\@" and do { $lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '${lhs}' ill formed: " . "report it as a BUG.\n"; $$dotpos = $1 } 0 28 28
$lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '${lhs}' ill formed: " . "report it as a BUG.\n" 0 0 0
$$dotpos ? : 27 1 28
$code ? : 20 8 28
@sempar ? : 7 1 8
$$check eq "ACCEPT" and do { $debug & 4 and print STDERR "Accept.\n"; return $semval } 1 27 28
$debug & 4 and print STDERR "Accept.\n" 1 0 1
$$check eq "ABORT" and do { $debug & 4 and print STDERR "Abort.\n"; return undef } 0 27 27
$debug & 4 and print STDERR "Abort.\n" 0 0 0
$debug & 4 and print STDERR "Back to state $stack->[-1][0], then " 27 0 27
$$check eq "ERROR" or do { $debug & 4 and print STDERR qq[go to state $$states[$stack->[-1][0]]{"GOTOS"}{$lhs}.\n]; $debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 }; push @$stack, [$$states[$stack->[-1][0]]{"GOTOS"}{$lhs}, $semval]; $$check = ""; next } 0 27 27
$debug & 4 and print STDERR qq[go to state $$states[$stack->[-1][0]]{"GOTOS"}{$lhs}.\n] 27 0 27
$debug & 16 and $dbgerror and $$errstatus == 0 and do { print STDERR "**End of Error recovery.\n"; $dbgerror = 0 } 1 26 27
$debug & 4 and print STDERR "Forced Error recovery.\n" 0 0 0
$$errstatus or do { $$errstatus = 1; &$error($self); $$errstatus or next; $debug & 16 and do { print STDERR "**Entering Error recovery.\n"; ++$dbgerror }; ++$$nberror } 2 1 3
$$errstatus or next 1 0 1
$debug & 16 and do { print STDERR "**Entering Error recovery.\n"; ++$dbgerror } 1 0 1
$$errstatus == 3 and do { $$token eq "" and do { $debug & 16 and print STDERR "**At eof: aborting.\n"; return undef }; $debug & 16 and print STDERR '**Dicard invalid token ' . &$ShowCurToken . ".\n"; $$token = $$value = undef } 2 1 3
$$token eq "" and do { $debug & 16 and print STDERR "**At eof: aborting.\n"; return undef } 0 2 2
$debug & 16 and print STDERR "**At eof: aborting.\n" 0 0 0
$debug & 16 and print STDERR '**Dicard invalid token ' . &$ShowCurToken . ".\n" 2 0 2
if (@$stack and !(exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"}) || $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0) 3 3 6
$debug & 16 and print STDERR "**Pop state $stack->[-1][0].\n" 3 0 3
@$stack or do { $debug & 16 and print STDERR "**No state left on stack: aborting.\n"; return undef } 3 0 3
$debug & 16 and print STDERR "**No state left on stack: aborting.\n" 0 0 0
$debug & 16 and print STDERR '**Shift $error token and go to state ' . $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} . ".\n" 3 0 3
ord $_ < 32 || ord $_ > 126 ? : 4 51 55
Condition59%16/27
$debug & 16 and $dbgerror and $$errstatus == 0
!ll&&!rl&&r
010
$debug & 16 and $dbgerror
!ll&&!rl&&r
001
$debug & 4 and $act
!ll&&!rl&&r
0127
$debug & 16 and $dbgerror and $$errstatus == 0
!ll&&!rl&&r
2601
$debug & 16 and $dbgerror
!ll&&!rl&&r
0261
@$stack and !(exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"}) || $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
!ll&&!rl&&r
033
not exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} or $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
l!l&&r!l&&!r
303
exists $$states[$stack->[-1][0]]{'ACTIONS'} && exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'}
!ll&&!rl&&r
033
ord $_ < 32 or ord $_ > 126
l!l&&r!l&&!r
4051
MC/DC0%0/3
$debug & 16 and $dbgerror and $$errstatus == 0
$debug & 16 $dbgerror $$errstatus == 0
MC/DC50%1/2
$debug & 4 and $act
$debug & 4 $act
MC/DC33%1/3
$debug & 16 and $dbgerror and $$errstatus == 0
$debug & 16 $dbgerror $$errstatus == 0
MC/DC25%1/4
@$stack and !(exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"}) || $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
@$stack exists $$states[$stack->[-1][0]]{'ACTIONS'} exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'} $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
MC/DC50%1/2
ord $_ < 32 or ord $_ > 126
ord $_ < 32 ord $_ > 126
Truth table25%1/4
A and B and C
A= $debug & 16B= $dbgerrorC= $$errstatus == 0
ABCresult
0XX0
10X0
1100
1111
Truth table66%2/3
A and B
A= $debug & 4B= $act
ABresult
0X0
100
111
Truth table50%2/4
A and B and C
A= $debug & 16B= $dbgerrorC= $$errstatus == 0
ABCresult
0XX0
10X0
1100
1111
Truth table40%2/5
A and not(B && C) or D
A= @$stackB= exists $$states[$stack->[-1][0]]{'ACTIONS'}C= exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'}D= $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
ABCDresult
0XXX0
11100
10XX1
110X1
11111
Truth table66%2/3
A or B
A= ord $_ < 32B= ord $_ > 126
ABresult
1X1
011
000
222 }
223  
224 #Note that for loading debugging version of the driver,
225 #this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
226 #So, DO NOT remove comment at end of sub !!!
227 21 ▶sub _Parse {
Subroutine _Parse: called CC=27 SCAR=33.4
228 21 my($self)=shift;
229  
230 my($rules,$states,$lex,$error)
231 21 = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
232 my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
233 21 = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
234  
235 #DBG> my($debug)=$$self{DEBUG};
236 #DBG> my($dbgerror)=0;
237  
238 #DBG> my($ShowCurToken) = sub {
239 #DBG> my($tok)='>';
240 #DBG> for (split('',$$token)) {
241 #DBG> $tok.= (ord($_) < 32 or ord($_) > 126)
242 #DBG> ? sprintf('<%02X>',ord($_))
243 #DBG> : $_;
244 #DBG> }
245 #DBG> $tok.='<';
246 #DBG> };
247  
248 21 $$errstatus=0;
249 21 $$nberror=0;
250 21 ($$token,$$value)=(undef,undef);
251 21 @$stack=( [ 0, undef ] );
252 21 $$check='';
253  
254 21 while(1) {
255 16339 my($actions,$act,$stateno);
256  
257 16339 $stateno=$$stack[-1][0];
258 16339 $actions=$$states[$stateno];
259  
260 #DBG> print STDERR ('-' x 40),"\n";
261 #DBG> $debug & 0x2
262 #DBG> and print STDERR "In state $stateno:\n";
263 #DBG> $debug & 0x08
264 #DBG> and print STDERR "Stack:[".
265 #DBG> join(',',map { $$_[0] } @$stack).
266 #DBG> "]\n";
267  
268  
269 16339 ▶ if (exists($$actions{ACTIONS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $actions->{'ACTIONS'}) { } 6037 10302 16339
270  
271 defined($$token)
272 6037 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
defined $$token or do { ($$token, $$value) = &$lex($self) } 1854 4183 6037
273 4183 ($$token,$$value)=&$lex($self);
274 #DBG> $debug & 0x01
275 #DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n";
276 };
277  
278 $act= exists($$actions{ACTIONS}{$$token})
279 ? $$actions{ACTIONS}{$$token}
280 : exists($$actions{DEFAULT})
281 ? $$actions{DEFAULT}
282 6037 ▶ : undef;
Branch: 2 branches
BranchTrueFalseTotal
exists $actions->{'ACTIONS'}{$$token} ? : 4183 1854 6037
exists $actions->{'DEFAULT'} ? : 1841 13 1854
283 }
284 else {
285 10302 $act=$$actions{DEFAULT};
286 #DBG> $debug & 0x01
287 #DBG> and print STDERR "Don't need token.\n";
288 }
289  
290 defined($act)
291 16339 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
defined $act and do { $act > 0 and do { $$errstatus and do { --$$errstatus }; push @$stack, [$act, $$value]; $$token ne "" and $$token = $$value = undef; next }; my($lhs, $len, $code, @sempar, $semval); () = @{$$rules[-$act];}; $act or $self->YYAccept; $$dotpos = $len; unpack("A1", $lhs) eq "\@" and do { $lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '${lhs}' ill formed: " . "report it as a BUG.\n"; $$dotpos = $1 }; @sempar = $$dotpos ? map({$_->[1];} @$stack[-$$dotpos .. -1]) : (); $semval = $code ? &$code($self, @sempar) : (@sempar ? $sempar[0] : undef); splice @$stack, -$len, $len; $$check eq "ACCEPT" and do { return $semval }; $$check eq "ABORT" and do { return undef }; $$check eq "ERROR" or do { push @$stack, [$$states[$stack->[-1][0]]{"GOTOS"}{$lhs}, $semval]; $$check = ""; next }; $$check = "" } 16324 15 16339
292  
293 $act > 0
294 16324 ▶ and do { #shift
Branch: 1 branch
BranchTrueFalseTotal
$act > 0 and do { $$errstatus and do { --$$errstatus }; push @$stack, [$act, $$value]; $$token ne "" and $$token = $$value = undef; next } 4171 12153 16324
295  
296 #DBG> $debug & 0x04
297 #DBG> and print STDERR "Shift and go to state $act.\n";
298  
299 $$errstatus
300 4171 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus and do { --$$errstatus } 3 4168 4171
301 3 --$$errstatus;
302  
303 #DBG> $debug & 0x10
304 #DBG> and $dbgerror
305 #DBG> and $$errstatus == 0
306 #DBG> and do {
307 #DBG> print STDERR "**End of Error recovery.\n";
308 #DBG> $dbgerror=0;
309 #DBG> };
310 };
311  
312  
313 4171 push(@$stack,[ $act, $$value ]);
314  
315 4171 ▶ $$token ne '' #Don't eat the eof
Branch: 1 branch
BranchTrueFalseTotal
$$token ne "" and $$token = $$value = undef 4150 21 4171
316 and $$token=$$value=undef;
317 4171 next;
318 };
319  
320 #reduce
321 12153 my($lhs,$len,$code,@sempar,$semval);
322 12153 ($lhs,$len,$code)=@{$$rules[-$act]};
323  
324 #DBG> $debug & 0x04
325 #DBG> and $act
326 #DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): ";
327  
328 12153 ▶ $act
Branch: 1 branch
BranchTrueFalseTotal
$act or $self->YYAccept 12132 21 12153
329 or $self->YYAccept();
330  
331 12153 $$dotpos=$len;
332  
333 unpack('A1',$lhs) eq '@' #In line rule
334 12153 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
unpack("A1", $lhs) eq "\@" and do { $lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '${lhs}' ill formed: " . "report it as a BUG.\n"; $$dotpos = $1 } 3 12150 12153
335 3 ▶ $lhs =~ /^\@[0-9]+\-([0-9]+)$/
Branch: 1 branch
BranchTrueFalseTotal
$lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '${lhs}' ill formed: " . "report it as a BUG.\n" 3 0 3
336 or die "In line rule name '$lhs' ill formed: ".
337 "report it as a BUG.\n";
338 3 $$dotpos = $1;
339 };
340  
341 @sempar = $$dotpos
342 12153 ▶ ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ]
Branch: 1 branch
BranchTrueFalseTotal
$$dotpos ? : 11931 222 12153
343 : ();
344  
345 12153 ▶ $semval = $code ? &$code( $self, @sempar )
Branch: 2 branches
BranchTrueFalseTotal
$code ? : 8931 3222 12153
@sempar ? : 3114 108 3222
346 : @sempar ? $sempar[0] : undef;
347  
348 12153 splice(@$stack,-$len,$len);
349  
350 $$check eq 'ACCEPT'
351 12153 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$check eq "ACCEPT" and do { return $semval } 21 12132 12153
352  
353 #DBG> $debug & 0x04
354 #DBG> and print STDERR "Accept.\n";
355  
356 21 return($semval);
357 };
358  
359 $$check eq 'ABORT'
360 12132 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$check eq "ABORT" and do { return undef } 0 12132 12132
361  
362 #DBG> $debug & 0x04
363 #DBG> and print STDERR "Abort.\n";
364  
365 0 return(undef);
366  
367 };
368  
369 #DBG> $debug & 0x04
370 #DBG> and print STDERR "Back to state $$stack[-1][0], then ";
371  
372 $$check eq 'ERROR'
373 12132 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$$check eq "ERROR" or do { push @$stack, [$$states[$stack->[-1][0]]{"GOTOS"}{$lhs}, $semval]; $$check = ""; next } 0 12132 12132
374 #DBG> $debug & 0x04
375 #DBG> and print STDERR
376 #DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n";
377  
378 #DBG> $debug & 0x10
379 #DBG> and $dbgerror
380 #DBG> and $$errstatus == 0
381 #DBG> and do {
382 #DBG> print STDERR "**End of Error recovery.\n";
383 #DBG> $dbgerror=0;
384 #DBG> };
385  
386 push(@$stack,
387 12132 [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]);
388 12132 $$check='';
389 12132 next;
390 };
391  
392 #DBG> $debug & 0x04
393 #DBG> and print STDERR "Forced Error recovery.\n";
394  
395 0 $$check='';
396  
397 };
398  
399 #Error
400 $$errstatus
401 15 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus or do { $$errstatus = 1; &$error($self); $$errstatus or next; ++$$nberror } 12 3 15
402  
403 3 $$errstatus = 1;
404 3 &$error($self);
405 3 ▶ $$errstatus # if 0, then YYErrok has been called
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus or next 3 0 3
406 or next; # so continue parsing
407  
408 #DBG> $debug & 0x10
409 #DBG> and do {
410 #DBG> print STDERR "**Entering Error recovery.\n";
411 #DBG> ++$dbgerror;
412 #DBG> };
413  
414 3 ++$$nberror;
415  
416 };
417  
418 $$errstatus == 3 #The next token is not valid: discard it
419 15 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus == 3 and do { $$token eq "" and do { return undef }; $$token = $$value = undef } 12 3 15
420 $$token eq '' # End of input: no hope
421 12 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$token eq "" and do { return undef } 0 12 12
422 #DBG> $debug & 0x10
423 #DBG> and print STDERR "**At eof: aborting.\n";
424 0 return(undef);
425 };
426  
427 #DBG> $debug & 0x10
428 #DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n";
429  
430 12 $$token=$$value=undef;
431 };
432  
433 15 $$errstatus=3;
434  
435 15 ▶ while( @$stack
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack and !(exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"}) || $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0) 16 15 31
Condition66%6/9
@$stack and !(exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"}) || $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
!ll&&!rl&&r
01516
not exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} or $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
l!l&&r!l&&!r
16015
exists $$states[$stack->[-1][0]]{'ACTIONS'} && exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'}
!ll&&!rl&&r
01615
MC/DC25%1/4
@$stack and !(exists $$states[$stack->[-1][0]]{"ACTIONS"} && exists $$states[$stack->[-1][0]]{"ACTIONS"}{"error"}) || $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
@$stack exists $$states[$stack->[-1][0]]{'ACTIONS'} exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'} $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
Truth table40%2/5
A and not(B && C) or D
A= @$stackB= exists $$states[$stack->[-1][0]]{'ACTIONS'}C= exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'}D= $$states[$stack->[-1][0]]{"ACTIONS"}{"error"} <= 0
ABCDresult
0XXX0
11100
10XX1
110X1
11111
436 and ( not exists($$states[$$stack[-1][0]]{ACTIONS})
437 or not exists($$states[$$stack[-1][0]]{ACTIONS}{error})
438 or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) {
439  
440 #DBG> $debug & 0x10
441 #DBG> and print STDERR "**Pop state $$stack[-1][0].\n";
442  
443 16 pop(@$stack);
444 }
445  
446 @$stack
447 15 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
@$stack or do { return undef } 15 0 15
448  
449 #DBG> $debug & 0x10
450 #DBG> and print STDERR "**No state left on stack: aborting.\n";
451  
452 0 return(undef);
453 };
454  
455 #shift the error token
456  
457 #DBG> $debug & 0x10
458 #DBG> and print STDERR "**Shift \$error token and go to state ".
459 #DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}.
460 #DBG> ".\n";
461  
462 15 push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]);
463  
464 }
465  
466 #never reached
467 0 croak("Error in driver logic. Please, report it as a BUG");
468  
469 }#_Parse
470 #DO NOT remove comment
471  
472 3 1;
473  
« blib/lib/Parse/Yapp/Lalr.pm ↑ Summary blib/lib/Parse/Yapp/Grammar.pm »