Units/Grammar.pm

filter: Statementstmt 52.1% 87 / 167 Branchbran 41.0% 32 / 78 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 45.8% 11 / 24 Podpod n/a totaltotal 44.8% 131 / 292 CC 46 SCAR 36.9
CC
46
Cov
46%
_Parse
92.7
_DBLoad
21.7
YYSemval
12.0
CRAP 40.2
↑ Summary Units/Convert/Date.pm »
1 ####################################################################
2 #
3 # This file was generated using Parse::Yapp version 1.04.
4 #
5 # Don't edit this file, use source file instead.
6 #
7 # ANY CHANGE MADE HERE WILL BE LOST !
8 #
9 ####################################################################
10 package Math::Calc::Units::Grammar;
11 1 ▶use vars qw ( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 @ISA= qw ( Parse::Yapp::Driver );
15 #Included Parse/Yapp/Driver.pm file----------------------------------------
16 {
17 #
18 # Module Parse::Yapp::Driver
19 #
20 # This module is part of the Parse::Yapp package available on your
21 # nearest CPAN
22 #
23 # Any use of this module in a standalone parser make the included
24 # text under the same copyright as the Parse::Yapp module itself.
25 #
26 # This notice should remain unchanged.
27 #
28 # (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved.
29 # (see the pod text in Parse::Yapp module for use and distribution rights)
30 #
31  
32 package Parse::Yapp::Driver;
33  
34 require 5.004;
35  
36 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 ▶use vars qw ( $VERSION $COMPATIBLE $FILENAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 $VERSION = '1.04';
41 $COMPATIBLE = '0.07';
42 $FILENAME=__FILE__;
43  
44 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 #Known parameters, all starting with YY (leading YY will be discarded)
47 my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '',
48 YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => '');
49 #Mandatory parameters
50 my(@params)=('LEX','RULES','STATES');
51  
52 109 ▶sub new {
Subroutine new: called CC=4 SCAR=14.8
53 109 my($class)=shift;
54 109 my($errst,$nberr,$token,$value,$check,$dotpos);
55 109 my($self)={ ERROR => \&_Error,
56 ERRST => \$errst,
57 NBERR => \$nberr,
58 TOKEN => \$token,
59 VALUE => \$value,
60 DOTPOS => \$dotpos,
61 STACK => [],
62 DEBUG => 0,
63 CHECK => \$check };
64  
65 109 _CheckParams( [], \%params, \@_, $self );
66  
67 exists($$self{VERSION})
68 109 ▶ 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 109 109
Condition33%1/3
exists $self->{"VERSION"} and $self->{"VERSION"} < $Parse::Yapp::Driver::COMPATIBLE
!ll&&!rl&&r
01090
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
69 and croak "Yapp driver version $VERSION ".
70 "incompatible with version $$self{VERSION}:\n".
71 "Please recompile parser module.";
72  
73 109 ▶ ref($class)
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 109 109
74 and $class=ref($class);
75  
76 109 bless($self,$class);
77 }
78  
79 109 ▶sub YYParse {
Subroutine YYParse: called CC=3 SCAR=13.6
80 109 my($self)=shift;
81 109 my($retval);
82  
83 109 _CheckParams( \@params, \%params, \@_, $self );
84  
85 109 ▶ if($$self{DEBUG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'DEBUG'}) { } 0 109 109
86 0 _DBLoad();
87 0 $retval = eval '$self->_DBParse()';#Do not create stab entry on compile
88 0 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 0 0
89 }
90 else {
91 109 $retval = $self->_Parse();
92 }
93 105 $retval
94 }
95  
96 0 ▶sub YYData {
Subroutine YYData: not called CC=2 SCAR=17.9
97 0 my($self)=shift;
98  
99 exists($$self{USER})
100 0 ▶ or $$self{USER}={};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"USER"} or $self->{"USER"} = {} 0 0 0
101  
102 0 $$self{USER};
103
104 }
105  
106 0 ▶sub YYErrok {
Subroutine YYErrok: not called CC=1 SCAR=6.9
107 0 my($self)=shift;
108  
109 0 ${$$self{ERRST}}=0;
110 0 undef;
111 }
112  
113 0 ▶sub YYNberr {
Subroutine YYNberr: not called CC=1 SCAR=6.9
114 0 my($self)=shift;
115  
116 0 ${$$self{NBERR}};
117 }
118  
119 0 ▶sub YYRecovering {
Subroutine YYRecovering: not called CC=1 SCAR=6.9
120 0 my($self)=shift;
121  
122 0 ${$$self{ERRST}} != 0;
123 }
124  
125 0 ▶sub YYAbort {
Subroutine YYAbort: not called CC=1 SCAR=6.9
126 0 my($self)=shift;
127  
128 0 ${$$self{CHECK}}='ABORT';
129 0 undef;
130 }
131  
132 105 ▶sub YYAccept {
Subroutine YYAccept: called CC=1 SCAR=0.0
133 105 my($self)=shift;
134  
135 105 ${$$self{CHECK}}='ACCEPT';
136 105 undef;
137 }
138  
139 0 ▶sub YYError {
Subroutine YYError: not called CC=1 SCAR=6.9
140 0 my($self)=shift;
141  
142 0 ${$$self{CHECK}}='ERROR';
143 0 undef;
144 }
145  
146 0 ▶sub YYSemval {
Subroutine YYSemval: not called CC=3 SCAR=24.8
147 0 my($self)=shift;
148 0 my($index)= $_[0] - ${$$self{DOTPOS}} - 1;
149  
150 $index < 0
151 0 and -$index <= @{$$self{STACK}}
152 0 ▶ and return $$self{STACK}[$index][1];
Branch: 1 branch
BranchTrueFalseTotal
$index < 0 and -$index <= @{$self->{"STACK"};} and return $self->{"STACK"}[$index][1] 0 0 0
Condition0%0/3
$index < 0 and -$index <= @{$self->{"STACK"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$index < 0 and -$index <= @{$self->{"STACK"};}
$index < 0 -$index <= @{$self->{"STACK"};}
Truth table0%0/3
A and B
A= $index < 0B= -$index <= @{$self->{"STACK"};}
ABresult
0X0
100
111
153  
154 0 undef; #Invalid index
155 }
156  
157 0 ▶sub YYCurtok {
Subroutine YYCurtok: not called CC=2 SCAR=17.9
158 0 my($self)=shift;
159  
160 @_
161 0 ▶ and ${$$self{TOKEN}}=$_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and ${$$self{"TOKEN"};} = $_[0] 0 0 0
162 0 ${$$self{TOKEN}};
163 }
164  
165 0 ▶sub YYCurval {
Subroutine YYCurval: not called CC=2 SCAR=17.9
166 0 my($self)=shift;
167  
168 @_
169 0 ▶ and ${$$self{VALUE}}=$_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and ${$$self{"VALUE"};} = $_[0] 0 0 0
170 0 ${$$self{VALUE}};
171 }
172  
173 0 ▶sub YYExpect {
Subroutine YYExpect: not called CC=1 SCAR=6.9
174 0 my($self)=shift;
175  
176 0 keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
177 }
178  
179 0 ▶sub YYLexer {
Subroutine YYLexer: not called CC=1 SCAR=6.9
180 0 my($self)=shift;
181  
182 0 $$self{LEX};
183 }
184  
185  
186 #################
187 # Private stuff #
188 #################
189  
190  
191 218 ▶sub _CheckParams {
Subroutine _CheckParams: called CC=6 SCAR=18.2
192 218 my($mandatory,$checklist,$inarray,$outhash)=@_;
193 218 my($prm,$value);
194 218 my($prmlst)={};
195  
196 218 ▶ while(($prm,$value)=splice(@$inarray,0,2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@$inarray, 0, 2)) 654 218 872
197 654 $prm=uc($prm);
198 654 ▶ exists($$checklist{$prm})
Branch: 1 branch
BranchTrueFalseTotal
exists $checklist->{$prm} or croak("Unknow parameter '${prm}'") 654 0 654
199 or croak("Unknow parameter '$prm'");
200 654 ▶ ref($value) eq $$checklist{$prm}
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq $checklist->{$prm} or croak("Invalid value for parameter '${prm}'") 654 0 654
201 or croak("Invalid value for parameter '$prm'");
202 654 $prm=unpack('@2A*',$prm);
203 654 $$outhash{$prm}=$value;
204 }
205 218 for (@$mandatory) {
206 327 ▶ exists($$outhash{$_})
Branch: 1 branch
BranchTrueFalseTotal
exists $outhash->{$_} or croak(q[Missing mandatory parameter '] . lc($_) . q[']) 327 0 327
207 or croak("Missing mandatory parameter '".lc($_)."'");
208 }
209 }
210  
211 0 ▶sub _Error {
Subroutine _Error: not called CC=1 SCAR=6.9
212 0 print "Parse error.\n";
213 }
214  
215 0 ▶sub _DBLoad {
Subroutine _DBLoad: not called CC=5 SCAR=30.8
216 {
217 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
218  
219 0 exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
220 0 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
exists do { "Parse::Yapp::Driver::" }->{"_DBParse"} and return 0 0 0
221 }
222 0 my($fname)=__FILE__;
223 0 my(@drv);
224 0 ▶ 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" 0 0 0
225 0 ▶ while(<DRV>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DRV)) 0 0 0
226 /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
227 0 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/ and do { s/^#DBG>//; push @drv, $_ } 0 0 0
228 0 s/^#DBG>//;
229 0 push(@drv,$_);
230 }
231 }
232 0 close(DRV);
233  
234 0 $drv[0]=~s/_P/_DBP/;
235 0 eval join('',@drv);
236 }
237  
238 #Note that for loading debugging version of the driver,
239 #this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
240 #So, DO NOT remove comment at end of sub !!!
241 109 ▶sub _Parse {
Subroutine _Parse: called CC=27 SCAR=45.3
242 109 my($self)=shift;
243  
244 my($rules,$states,$lex,$error)
245 109 = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
246 my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
247 109 = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
248  
249 #DBG> my($debug)=$$self{DEBUG};
250 #DBG> my($dbgerror)=0;
251  
252 #DBG> my($ShowCurToken) = sub {
253 #DBG> my($tok)='>';
254 #DBG> for (split('',$$token)) {
255 #DBG> $tok.= (ord($_) < 32 or ord($_) > 126)
256 #DBG> ? sprintf('<%02X>',ord($_))
257 #DBG> : $_;
258 #DBG> }
259 #DBG> $tok.='<';
260 #DBG> };
261  
262 109 $$errstatus=0;
263 109 $$nberror=0;
264 109 ($$token,$$value)=(undef,undef);
265 109 @$stack=( [ 0, undef ] );
266 109 $$check='';
267  
268 109 while(1) {
269 1150 my($actions,$act,$stateno);
270  
271 1150 $stateno=$$stack[-1][0];
272 1150 $actions=$$states[$stateno];
273  
274 #DBG> print STDERR ('-' x 40),"\n";
275 #DBG> $debug & 0x2
276 #DBG> and print STDERR "In state $stateno:\n";
277 #DBG> $debug & 0x08
278 #DBG> and print STDERR "Stack:[".
279 #DBG> join(',',map { $$_[0] } @$stack).
280 #DBG> "]\n";
281  
282  
283 1150 ▶ if (exists($$actions{ACTIONS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $actions->{'ACTIONS'}) { } 596 554 1150
284  
285 defined($$token)
286 596 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
defined $$token or do { ($$token, $$value) = &$lex($self) } 154 442 596
287 442 ($$token,$$value)=&$lex($self);
288 #DBG> $debug & 0x01
289 #DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n";
290 };
291  
292 $act= exists($$actions{ACTIONS}{$$token})
293 ? $$actions{ACTIONS}{$$token}
294 : exists($$actions{DEFAULT})
295 ? $$actions{DEFAULT}
296 596 ▶ : undef;
Branch: 2 branches
BranchTrueFalseTotal
exists $actions->{'ACTIONS'}{$$token} ? : 439 157 596
exists $actions->{'DEFAULT'} ? : 157 0 157
297 }
298 else {
299 554 $act=$$actions{DEFAULT};
300 #DBG> $debug & 0x01
301 #DBG> and print STDERR "Don't need token.\n";
302 }
303  
304 defined($act)
305 1150 ▶ 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 = "" } 1150 0 1150
306  
307 $act > 0
308 1150 ▶ 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 } 439 711 1150
309  
310 #DBG> $debug & 0x04
311 #DBG> and print STDERR "Shift and go to state $act.\n";
312  
313 $$errstatus
314 439 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus and do { --$$errstatus } 0 439 439
315 0 --$$errstatus;
316  
317 #DBG> $debug & 0x10
318 #DBG> and $dbgerror
319 #DBG> and $$errstatus == 0
320 #DBG> and do {
321 #DBG> print STDERR "**End of Error recovery.\n";
322 #DBG> $dbgerror=0;
323 #DBG> };
324 };
325  
326  
327 439 push(@$stack,[ $act, $$value ]);
328  
329 439 ▶ $$token ne '' #Don't eat the eof
Branch: 1 branch
BranchTrueFalseTotal
$$token ne "" and $$token = $$value = undef 334 105 439
330 and $$token=$$value=undef;
331 439 next;
332 };
333  
334 #reduce
335 711 my($lhs,$len,$code,@sempar,$semval);
336 711 ($lhs,$len,$code)=@{$$rules[-$act]};
337  
338 #DBG> $debug & 0x04
339 #DBG> and $act
340 #DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): ";
341  
342 711 ▶ $act
Branch: 1 branch
BranchTrueFalseTotal
$act or $self->YYAccept 606 105 711
343 or $self->YYAccept();
344  
345 711 $$dotpos=$len;
346  
347 unpack('A1',$lhs) eq '@' #In line rule
348 711 ▶ 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 } 0 711 711
349 0 ▶ $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" 0 0 0
350 or die "In line rule name '$lhs' ill formed: ".
351 "report it as a BUG.\n";
352 0 $$dotpos = $1;
353 };
354  
355 @sempar = $$dotpos
356 711 ▶ ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ]
Branch: 1 branch
BranchTrueFalseTotal
$$dotpos ? : 711 0 711
357 : ();
358  
359 711 ▶ $semval = $code ? &$code( $self, @sempar )
Branch: 2 branches
BranchTrueFalseTotal
$code ? : 501 210 711
@sempar ? : 210 0 210
360 : @sempar ? $sempar[0] : undef;
361  
362 707 splice(@$stack,-$len,$len);
363  
364 $$check eq 'ACCEPT'
365 707 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$check eq "ACCEPT" and do { return $semval } 105 602 707
366  
367 #DBG> $debug & 0x04
368 #DBG> and print STDERR "Accept.\n";
369  
370 105 return($semval);
371 };
372  
373 $$check eq 'ABORT'
374 602 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$check eq "ABORT" and do { return undef } 0 602 602
375  
376 #DBG> $debug & 0x04
377 #DBG> and print STDERR "Abort.\n";
378  
379 0 return(undef);
380  
381 };
382  
383 #DBG> $debug & 0x04
384 #DBG> and print STDERR "Back to state $$stack[-1][0], then ";
385  
386 $$check eq 'ERROR'
387 602 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$$check eq "ERROR" or do { push @$stack, [$$states[$stack->[-1][0]]{"GOTOS"}{$lhs}, $semval]; $$check = ""; next } 0 602 602
388 #DBG> $debug & 0x04
389 #DBG> and print STDERR
390 #DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n";
391  
392 #DBG> $debug & 0x10
393 #DBG> and $dbgerror
394 #DBG> and $$errstatus == 0
395 #DBG> and do {
396 #DBG> print STDERR "**End of Error recovery.\n";
397 #DBG> $dbgerror=0;
398 #DBG> };
399  
400 push(@$stack,
401 602 [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]);
402 602 $$check='';
403 602 next;
404 };
405  
406 #DBG> $debug & 0x04
407 #DBG> and print STDERR "Forced Error recovery.\n";
408  
409 0 $$check='';
410  
411 };
412  
413 #Error
414 $$errstatus
415 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus or do { $$errstatus = 1; &$error($self); $$errstatus or next; ++$$nberror } 0 0 0
416  
417 0 $$errstatus = 1;
418 0 &$error($self);
419 0 ▶ $$errstatus # if 0, then YYErrok has been called
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus or next 0 0 0
420 or next; # so continue parsing
421  
422 #DBG> $debug & 0x10
423 #DBG> and do {
424 #DBG> print STDERR "**Entering Error recovery.\n";
425 #DBG> ++$dbgerror;
426 #DBG> };
427  
428 0 ++$$nberror;
429  
430 };
431  
432 $$errstatus == 3 #The next token is not valid: discard it
433 0 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$errstatus == 3 and do { $$token eq "" and do { return undef }; $$token = $$value = undef } 0 0 0
434 $$token eq '' # End of input: no hope
435 0 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$token eq "" and do { return undef } 0 0 0
436 #DBG> $debug & 0x10
437 #DBG> and print STDERR "**At eof: aborting.\n";
438 0 return(undef);
439 };
440  
441 #DBG> $debug & 0x10
442 #DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n";
443  
444 0 $$token=$$value=undef;
445 };
446  
447 0 $$errstatus=3;
448  
449 0 ▶ 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) 0 0 0
Condition0%0/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
000
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
000
exists $$states[$stack->[-1][0]]{'ACTIONS'} && exists $$states[$stack->[-1][0]]{'ACTIONS'}{'error'}
!ll&&!rl&&r
000
MC/DC0%0/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 table0%0/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
450 and ( not exists($$states[$$stack[-1][0]]{ACTIONS})
451 or not exists($$states[$$stack[-1][0]]{ACTIONS}{error})
452 or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) {
453  
454 #DBG> $debug & 0x10
455 #DBG> and print STDERR "**Pop state $$stack[-1][0].\n";
456  
457 0 pop(@$stack);
458 }
459  
460 @$stack
461 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
@$stack or do { return undef } 0 0 0
462  
463 #DBG> $debug & 0x10
464 #DBG> and print STDERR "**No state left on stack: aborting.\n";
465  
466 0 return(undef);
467 };
468  
469 #shift the error token
470  
471 #DBG> $debug & 0x10
472 #DBG> and print STDERR "**Shift \$error token and go to state ".
473 #DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}.
474 #DBG> ".\n";
475  
476 0 push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]);
477  
478 }
479  
480 #never reached
481 0 croak("Error in driver logic. Please, report it as a BUG");
482  
483 }#_Parse
484 #DO NOT remove comment
485  
486 1;
487  
488 }
489 #End of include--------------------------------------------------
490  
491  
492 #line 3 "Grammar.y"
493  
494 use Math::Calc::Units::Compute qw(plus minus mult divide power construct);
495  
496  
497 sub new {
498 my($class)=shift;
499 ref($class)
500 and $class=ref($class);
501  
502 my($self)=$class->SUPER::new( yyversion => '1.04',
503 yystates =>
504 [
505 {#State 0
506 ACTIONS => {
507 'NUMBER' => 5,
508 "#" => 2,
509 "-" => 6,
510 'WORD' => 7,
511 'CONSTRUCT' => 3,
512 "\@" => 9,
513 "(" => 4
514 },
515 GOTOS => {
516 'unit' => 1,
517 'value' => 8,
518 'START' => 10,
519 'expr' => 11
520 }
521 },
522 {#State 1
523 DEFAULT => -12
524 },
525 {#State 2
526 ACTIONS => {
527 'WORD' => 7
528 },
529 GOTOS => {
530 'unit' => 12
531 }
532 },
533 {#State 3
534 DEFAULT => -16
535 },
536 {#State 4
537 ACTIONS => {
538 'NUMBER' => 5,
539 "-" => 6,
540 'WORD' => 7,
541 'CONSTRUCT' => 3,
542 "\@" => 9,
543 "(" => 4
544 },
545 GOTOS => {
546 'unit' => 1,
547 'value' => 8,
548 'expr' => 13
549 }
550 },
551 {#State 5
552 ACTIONS => {
553 'WORD' => 7
554 },
555 DEFAULT => -13,
556 GOTOS => {
557 'unit' => 14
558 }
559 },
560 {#State 6
561 ACTIONS => {
562 'NUMBER' => 15
563 }
564 },
565 {#State 7
566 DEFAULT => -17
567 },
568 {#State 8
569 DEFAULT => -9
570 },
571 {#State 9
572 ACTIONS => {
573 'NUMBER' => 17
574 }
575 },
576 {#State 10
577 ACTIONS => {
578 '' => 18
579 }
580 },
581 {#State 11
582 ACTIONS => {
583 "*" => 21,
584 "+" => 22,
585 "**" => 20,
586 "-" => 23,
587 'WORD' => 7,
588 "/" => 24
589 },
590 DEFAULT => -1,
591 GOTOS => {
592 'unit' => 19
593 }
594 },
595 {#State 12
596 DEFAULT => -2
597 },
598 {#State 13
599 ACTIONS => {
600 "*" => 21,
601 "+" => 22,
602 "**" => 20,
603 "-" => 23,
604 'WORD' => 7,
605 "/" => 24,
606 ")" => 25
607 },
608 GOTOS => {
609 'unit' => 19
610 }
611 },
612 {#State 14
613 DEFAULT => -11
614 },
615 {#State 15
616 DEFAULT => -14
617 },
618 {#State 16
619 DEFAULT => -18
620 },
621 {#State 17
622 DEFAULT => -15
623 },
624 {#State 18
625 DEFAULT => -0
626 },
627 {#State 19
628 DEFAULT => -10
629 },
630 {#State 20
631 ACTIONS => {
632 'NUMBER' => 5,
633 "-" => 6,
634 'WORD' => 7,
635 'CONSTRUCT' => 3,
636 "\@" => 9,
637 "(" => 4
638 },
639 GOTOS => {
640 'unit' => 1,
641 'value' => 8,
642 'expr' => 26
643 }
644 },
645 {#State 21
646 ACTIONS => {
647 'NUMBER' => 5,
648 "-" => 6,
649 'WORD' => 7,
650 'CONSTRUCT' => 3,
651 "\@" => 9,
652 "(" => 4
653 },
654 GOTOS => {
655 'unit' => 1,
656 'value' => 8,
657 'expr' => 27
658 }
659 },
660 {#State 22
661 ACTIONS => {
662 'NUMBER' => 5,
663 "-" => 6,
664 'WORD' => 7,
665 'CONSTRUCT' => 3,
666 "\@" => 9,
667 "(" => 4
668 },
669 GOTOS => {
670 'unit' => 1,
671 'value' => 8,
672 'expr' => 28
673 }
674 },
675 {#State 23
676 ACTIONS => {
677 'NUMBER' => 5,
678 "-" => 6,
679 'WORD' => 7,
680 'CONSTRUCT' => 3,
681 "\@" => 9,
682 "(" => 4
683 },
684 GOTOS => {
685 'unit' => 1,
686 'value' => 8,
687 'expr' => 29
688 }
689 },
690 {#State 24
691 ACTIONS => {
692 'NUMBER' => 5,
693 "-" => 6,
694 'WORD' => 7,
695 'CONSTRUCT' => 3,
696 "\@" => 9,
697 "(" => 4
698 },
699 GOTOS => {
700 'unit' => 1,
701 'value' => 8,
702 'expr' => 30
703 }
704 },
705 {#State 25
706 DEFAULT => -8
707 },
708 {#State 26
709 DEFAULT => -7,
710 GOTOS => {
711 'unit' => 19
712 }
713 },
714 {#State 27
715 ACTIONS => {
716 "**" => 20,
717 'WORD' => 7
718 },
719 DEFAULT => -5,
720 GOTOS => {
721 'unit' => 19
722 }
723 },
724 {#State 28
725 ACTIONS => {
726 "**" => 20,
727 "*" => 21,
728 'WORD' => 7,
729 "/" => 24
730 },
731 DEFAULT => -3,
732 GOTOS => {
733 'unit' => 19
734 }
735 },
736 {#State 29
737 ACTIONS => {
738 "**" => 20,
739 "*" => 21,
740 'WORD' => 7,
741 "/" => 24
742 },
743 DEFAULT => -4,
744 GOTOS => {
745 'unit' => 19
746 }
747 },
748 {#State 30
749 ACTIONS => {
750 "**" => 20,
751 'WORD' => 7
752 },
753 DEFAULT => -6,
754 GOTOS => {
755 'unit' => 19
756 }
757 }
758 ],
759 yyrules =>
760 [
761 [#Rule 0
762 '$start', 2, undef
763 ],
764 [#Rule 1
765 'START', 1, undef
766 ],
767 [#Rule 2
768 'START', 2, undef
769 ],
770 [#Rule 3
771 'expr', 3,
772 sub
773 #line 22 "Grammar.y"
774 { return plus($_[1], $_[3]); }
775 ],
776 [#Rule 4
777 'expr', 3,
778 sub
779 #line 23 "Grammar.y"
780 { return minus($_[1], $_[3]); }
781 ],
782 [#Rule 5
783 'expr', 3,
784 sub
785 #line 24 "Grammar.y"
786 { return mult($_[1], $_[3]); }
787 ],
788 [#Rule 6
789 'expr', 3,
790 sub
791 #line 25 "Grammar.y"
792 { return divide($_[1], $_[3]); }
793 ],
794 [#Rule 7
795 'expr', 3,
796 sub
797 #line 26 "Grammar.y"
798 { return power($_[1], $_[3]); }
799 ],
800 [#Rule 8
801 'expr', 3,
802 sub
803 #line 27 "Grammar.y"
804 { return $_[2]; }
805 ],
806 [#Rule 9
807 'expr', 1,
808 sub
809 #line 28 "Grammar.y"
810 { return $_[1]; }
811 ],
812 [#Rule 10
813 'expr', 2,
814 sub
815 #line 29 "Grammar.y"
816 { return mult($_[1], [ 1, $_[2] ]); }
817 ],
818 [#Rule 11
819 'value', 2,
820 sub
821 #line 33 "Grammar.y"
822 { return [ $_[1] => $_[2] ] }
823 ],
824 [#Rule 12
825 'value', 1,
826 sub
827 #line 35 "Grammar.y"
828 { return [ 1 => $_[1] ] }
829 ],
830 [#Rule 13
831 'value', 1,
832 sub
833 #line 36 "Grammar.y"
834 { return [ $_[1] => {} ] }
835 ],
836 [#Rule 14
837 'value', 2,
838 sub
839 #line 37 "Grammar.y"
840 { return [ -$_[2] => {} ] }
841 ],
842 [#Rule 15
843 'value', 2,
844 sub
845 #line 38 "Grammar.y"
846 { return [ $_[2] => { 'timestamp' => 1 } ] }
847 ],
848 [#Rule 16
849 'value', 1,
850 sub
851 #line 39 "Grammar.y"
852 { return construct($_[1]) }
853 ],
854 [#Rule 17
855 'unit', 1,
856 sub
857 #line 42 "Grammar.y"
858 { return { $_[1] => 1 } }
859 ],
860 [#Rule 18
861 'unit', 2,
862 sub
863 #line 43 "Grammar.y"
864 { my $u = {}; $u->{$_[1]}++; $u->{$_[2]}++; return $u; }
865 ]
866 ],
867 @_);
868 bless($self,$class);
869 }
870  
871 #line 46 "Grammar.y"
872  
873  
874 1;
↑ Summary Units/Convert/Date.pm »