bin/bc

filter: Statementstmt 72.2% 713 / 987 Branchbran 65.5% 363 / 554 Conditioncond 72.1% 132 / 183 MC/DCmcdc 55.4% 56 / 101 Subroutinesub 56.7% 21 / 37 Podpod n/a totaltotal 69.0% 1285 / 1862 CC 339 SCAR 55.3
CC
339
Cov
70%
exec_stmt
561.7
yyparse
188.6
yy_err_recover
156.0
CRAP 252.4
« blib/lib/PerlPowerTools/SymbolicMode.pm ↑ Summary bin/ls »
1 #!/usr/bin/perl
2  
3 =begin metadata
4  
5 Name: bc
6 Description: an arbitrary precision calculator language
7 Author: Philip A. Nelson, phil@cs.wwu.edu
8 License: gpl
9  
10 =end metadata
11  
12 =cut
13  
14 =head1 NAME
15  
16 bc - an arbitrary precision calculator language
17  
18 =head1 SYNOPSIS
19  
20 Run a bc program from FILE
21  
22 bc [-bdiqswy] FILE...
23  
24 Start an interactive bc session
25  
26 bc [-bdiqswy]
27  
28 =head1 DESCRIPTION
29  
30 This is the PerlPowerTools implementation of the GNU version of bc, a
31 standard calculator language. This is documented at:
32  
33 https://www.gnu.org/software/bc/manual/html_mono/bc.html
34  
35 =head2 Options
36  
37 =over
38  
39 =item * -b - use Math::BigFloat
40  
41 =item * -d - turn on debugging output
42  
43 =item * -l - use mathlib
44  
45 =item * -y - turn on parser debugging output
46  
47 =back
48  
49 =head2 Environment
50  
51 There are no environment variables that affect this program.
52  
53 =head1 The bc language
54  
55 NOTE: Some of this documentation is lifted straight from the GNU
56 documentation for its version of B<bc>.
57  
58 C<bc> is a language that supports arbitrary precision numbers with
59 interactive execution of statements. There are some similarities in
60 the syntax to the C programming language.
61  
62 =begin comment ### XXX hidden because function support generate syntax errors
63  
64 A standard math library is
65 available by command line option. If requested, the math library is
66 defined before processing any files.
67  
68 =end comment
69  
70 C<bc> starts by processing code from all the files listed on the
71 command line in the order listed. If no files are listed, then stdin
72 is read. If a file contains a command to halt the processor,
73 C<bc> will never read from the standard input.
74  
75 Dash ('-') is a pseudo-filename which represents stdin. This makes
76 it possible to do something like C<bc fileA - fileB> and have bc
77 run commands from fileA before prompting for input, and then run
78 commands from fileB after interactive input is finished.
79  
80 =begin comment ### XXX for accuracy, the following is superceded by the above
81  
82 C<bc> starts by processing code from all the files listed on the
83 command line in the order listed. After all files have been
84 processed, C<bc> reads from the standard input. All code is executed
85 as it is read. (If a file contains a command to halt the processor,
86 C<bc> will never read from the standard input.)
87  
88 =end comment
89  
90 C<bc> will terminate interactive input via stdin if you enter C<quit>
91 or press C<CTRL-C>.
92  
93 =head1 BASIC ELEMENTS
94  
95 =head2 Numbers
96  
97 The most basic element in C<bc> is the number. Numbers are arbitrary
98 precision numbers. This precision is both in the integer part and the
99 fractional part. All numbers are represented internally in decimal and
100 all computation is done in decimal.
101  
102 =begin comment ### hidden because it doesn't seem to be true in this implementation
103  
104 (This version truncates results
105 from divide and multiply operations.)
106  
107 =end comment
108  
109  
110 There are two attributes of
111 numbers, the length and the scale. The length is the total number of
112 significant decimal digits in a number and the scale is the total number
113 of decimal digits after the decimal point. For example, .000001 has a
114 length of 6 and scale of 6, while 1935.000 has a length of 7 and a scale
115 of 3.
116  
117 =head2 Variables
118  
119 Numbers are stored in two types of variables, simple variables and
120 arrays. Both simple variables and array variables are named. Names
121 begin with a letter followed by any number of letters, digits and
122 underscores. All letters must be lower case.
123  
124 =begin comment ### hidden because it's not applicable and confusing
125  
126 (Full alphanumeric names
127 are an extension. In POSIX C<bc> all names are a single lower case
128 letter.)
129  
130 =end comment
131  
132 The type of variable is clear by the context because all
133 array variable names will be followed by brackets ( [ ] ).
134  
135 =head2 Special Variables
136  
137 =over 8
138  
139 =item C<scale>
140  
141 Defines how some operations use digits after the decimal point.
142 The default value is 0.
143  
144 =item C<ibase>
145  
146 Defines the conversion base for input numbers. Defaults to 10.
147  
148 =item C<obase>
149  
150 Defines the conversion base for output numbers. Defaults to 10.
151  
152 =back
153  
154 =head2 Comments
155  
156 Comments in C<bc> start with the characters '/*' and end with the
157 characters '*/'. Comments may start anywhere and appear as a single
158 space in the input. Note that this causes comments to delimit other
159 input items, therefore a comment cannot be included the middle of a
160 variable name. Comments include any newlines (end of line) between
161 the start and the end of the comment.
162  
163 To support the use of scripts for C<bc>, a single line comment has
164 been added as an extension. A single line comment starts at a '#'
165 character and continues to the next end of the line. The end of line
166 character is not part of the comment and is processed normally.
167  
168 =head1 EXPRESSIONS
169  
170 Numbers are manipulated by expressions and statements. Since
171 the language was designed to be interactive, statements and expressions
172 are executed as soon as possible. There is no main program. Instead,
173 code is executed as it is encountered.
174  
175 A simple expression is just a constant. C<bc> converts constants into
176 internal decimal numbers using the current input base, specified by the
177 variable C<ibase>.
178  
179 Full expressions are similar to many other high level languages.
180 Since there is only one kind of number, there are no rules for mixing
181 types. Instead, there are rules on the scale of expressions. Every
182 expression has a scale. This is derived from the scale of original
183 numbers, the operation performed and in many cases, the value of the
184 variable C<scale>.
185  
186 =begin comment ### replace by the above for accurary w.r.t this implementation
187  
188 The numbers are manipulated by expressions and statements. Since the language was designed to be interactive, statements and expressions are executed as soon as possible. There is no main program. Instead, code is executed as it is encountered. (Functions, discussed in detail later, are defined when encountered.)
189  
190 A simple expression is just a constant. bc converts constants into internal decimal numbers using the current input base, specified by the variable ibase. (There is an exception in functions.) The legal values of ibase are 2 through 16. Assigning a value outside this range to ibase will result in a value of 2 or 16. Input numbers may contain the characters 0-9 and A-F. (Note: They must be capitals. Lower case letters are variable names.) Single digit numbers always have the value of the digit regardless of the value of ibase. (i.e. A = 10.) For multi-digit numbers, bc changes all input digits greater or equal to ibase to the value of ibase-1. This makes the number FFF always be the largest 3 digit number of the input base.
191  
192 Full expressions are similar to many other high level languages. Since there is only one kind of number, there are no rules for mixing types. Instead, there are rules on the scale of expressions. Every expression has a scale. This is derived from the scale of original numbers, the operation performed and in many cases, the value of the variable scale. Legal values of the variable scale are 0 to the maximum number representable by a C integer.
193  
194 =end comment
195  
196 =head2 Basic Expressions
197  
198 In the following descriptions of legal expressions, "expr" refers to
199 a complete expression and "VAR" refers to a simple or an array variable.
200 A simple variable is just a NAME and an array variable is specified as
201 NAME[EXPR].
202  
203 Unless specifically mentioned the scale of the result is the maximum
204 scale of the expressions involved.
205  
206 =over 4
207  
208 =item C<- expr>
209  
210 The result is the negation of the expression.
211  
212 =item C<++ VAR>
213  
214 The variable is incremented by one and the new value is the result
215 of the expression.
216  
217 =item C<-- VAR>
218  
219 The variable is decremented by one and the new value is the result
220 of the expression.
221  
222 =item C<VAR ++>
223  
224 The result of the expression is the value of the variable and then
225 the variable is incremented by one.
226  
227 =item C<VAR -->
228  
229 The result of the expression is the value of the variable and then
230 the variable is decremented by one.
231  
232 =item C<expr + expr>
233  
234 The result of the expression is the sum of the two expressions.
235  
236 =item C<expr - expr>
237  
238 The result of the expression is the difference of the two
239 expressions.
240  
241 =item C<expr * expr>
242  
243 The result of the expression is the product of the two expressions.
244  
245 =item C<expr / expr>
246  
247 The result of the expression is the quotient of the two
248 expressions. The scale of the result is the value of the variable
249 C<scale>
250  
251 =item C<expr % expr>
252  
253 The result of the expression is the "remainder" and it is computed
254 in the following way. To compute a%b, first a/b is computed to
255 SCALE digits. That result is used to compute a-(a/b)*b to the
256 scale of the maximum of SCALE+scale(b) and scale(a). If SCALE is
257 set to zero and both expressions are integers this expression is
258 the integer remainder function.
259  
260 =item C<expr ^ expr>
261  
262 The result of the expression is the value of the first raised to
263 the second.
264  
265 =begin comment ### hidden because it doesn't seem to be true in the implementation
266  
267 The second expression must be an integer. (If the
268 second expression is not an integer, a warning is generated and the
269 expression is truncated to get an integer value.)
270  
271 =end comment
272  
273 The scale of the result is SCALE if the exponent is negative. If the
274 exponent is positive the scale of the result is the minimum of the
275 scale of the first expression times the value of the exponent and the
276 maximum of SCALE and the scale of the first expression. (e.g.
277 scale(a^b) = min(scale(a)*b, max(SCALE, scale(a))).) It should be
278 noted that expr^0 will always return the value of 1.
279  
280  
281 =item C<( expr )>
282  
283 This alters the standard precedence to force the evaluation of the
284 expression.
285  
286 =item C<VAR = expr>
287  
288 The variable is assigned the value of the expression.
289  
290 =item C<VAR op= expr>
291  
292 This is equivalent to "VAR = VAR op expr" with the exception
293 that the "VAR" part is evaluated only once. This can make a
294 difference if "VAR" is an array.
295  
296 =back
297  
298 =head2 Relational Expressions
299  
300 Relational expressions are a special kind of expression that always
301 evaluate to 0 or 1, 0 if the relation is false and 1 if the relation is
302 true. These may appear in any legal expression. (POSIX C<bc> requires
303 that relational expressions are used only in C<if>, C<while>, and C<for>
304 statements and that only one relational test may be done in them.) The
305 relational operators are
306  
307 =over 4
308  
309 =item expr1 < expr2
310  
311 The result is 1 if expr1 is strictly less than expr2.
312  
313 =item expr1 <= expr2
314  
315 The result is 1 if expr1 is less than or equal to expr2.
316  
317 =item expr1 > expr2
318  
319 The result is 1 if expr1 is strictly greater than expr2.
320  
321 =item expr1 >= expr2
322  
323 The result is 1 if expr1 is greater than or equal to expr2.
324  
325 =item expr1 == expr2
326  
327 The result is 1 if expr1 is equal to expr2.
328  
329 =item expr1 != expr2
330  
331 The result is 1 if expr1 is not equal to expr2.
332  
333 =back
334  
335 =head2 Boolean Expressions
336  
337 Boolean operations are also legal. (POSIX C<bc> does NOT have
338 boolean operations). The result of all boolean operations are 0 and 1
339 (for false and true) as in relational expressions. The boolean
340 operators are:
341  
342 =over 4
343  
344 =item C<!expr>
345  
346 The result is 1 if expr is 0.
347  
348 =item C<expr && expr>
349  
350 The result is 1 if both expressions are non-zero.
351  
352 =item C<expr || expr>
353  
354 The result is 1 if either expression is non-zero.
355  
356 =back
357  
358 =head2 Precedence
359  
360 The expression precedence is as follows: (lowest to highest)
361  
362 = += etc operators (assignment) right associative
363 || OR operator left associative
364 && AND operator left associative
365 ! NOT operator nonassociative
366 < > etc relational operators left associative
367 + and - operators left associative
368 *, / and % operators left associative
369 ^ operator (power) right associative
370 unary - operator nonassociative
371 ++ and -- operators nonassociative
372  
373 This differs from POSIX-compliant C<bc>, which puts assignment between
374 relational operators and addition/subtraction. As a result, expressions
375 behave more like they do in most languages (including perl and C).
376  
377 =head2 Special Expressions
378  
379 There are a few more special expressions that are provided in C<bc>.
380 These have to do with user-defined functions and standard functions.
381 These are:
382  
383 =over 4
384  
385 =item C<length ( expression )>
386  
387 The value of the C<length> function is the number of significant
388 digits in the expression.
389  
390 =begin comment ### hidden because it's not supported
391  
392 =item C<read ( )>
393  
394 The C<read> function (an extension) will read a number from the
395 standard input, regardless of where the function occurs. Beware,
396 this can cause problems with the mixing of data and program in the
397 standard input. The best use for this function is in a previously
398 written program that needs input from the user, but never allows
399 program code to be input from the user. The value of the `read'
400 function is the number read from the standard input using the
401 current value of the variable C<ibase> for the conversion base.
402  
403 =end comment
404  
405 =item C<scale ( expression )>
406  
407 The value of the C<scale> function is the number of digits after the
408 decimal point in the expression.
409  
410 =item C<sqrt ( expression )>
411  
412 The value of the C<sqrt> function is the square root of the
413 expression. If the expression is negative, a run time error is
414 generated.
415  
416 =back
417  
418 =head2 Statements
419  
420 Statements (as in most algebraic languages) provide the sequencing of
421 expression evaluation. In C<bc> statements are executed "as soon as
422 possible." Execution happens when a newline is encountered and there
423 is one or more complete statements. Due to this immediate execution,
424 newlines are very important in C<bc>. In fact, both a semicolon and a
425 newline are used as statement separators. An improperly placed
426 newline will cause a syntax error.
427  
428 Because newlines are statement separators, it is possible to hide a
429 newline by using the backslash character. The sequence "\<nl>" (where
430 <nl> represents a newline your typed) appears to C<bc> as whitespace
431 instead of an actual newline.
432  
433 A statement list is a series of statements separated by semicolons
434 and newlines.
435  
436 The following is a list of C<bc> statements and what they do. Things
437 enclosed in brackets ( [ ] ) are optional parts of the statement.
438  
439 =over 4
440  
441 =item EXPRESSION
442  
443 This statement does one of two things. If the expression starts
444 with "<variable> <assignment> ...", it is considered to be an
445 assignment statement. If the expression is not an assignment
446 statement, the expression is evaluated and printed to the output.
447 After the number is printed, a newline is printed.
448  
449 For example, "a=1" is an assignment statement and "(a=1)" is an
450 expression that has an embedded assignment.
451  
452 =begin comment ### hidden because obase and last don't seem to work
453  
454 All numbers that are printed are printed in the base specified by the
455 variable OBASE. The legal values for OBASE are 2 through BC_BASE_MAX
456 (*note Environment Variables::). For bases 2 through 16, the usual
457 method of writing numbers is used. For bases greater than 16, C<bc>
458 uses a multi-character digit method of printing the numbers where each
459 higher base digit is printed as a base 10 number. The multi-character
460 digits are separated by spaces. Each digit contains the number of
461 characters required to represent the base ten value of "OBASE -1".
462 Since numbers are of arbitrary precision, some numbers may not be
463 printable on a single output line. These long numbers will be split
464 across lines using the "\" as the last character on a line. The
465 maximum number of characters printed per line is 70. Due to the
466 interactive nature of C<bc>, printing a number causes the side effect
467 of assigning the printed value to the special variable LAST. This
468 allows the user to recover the last value printed without having to
469 retype the expression that printed the number. Assigning to LAST is
470 legal and will overwrite the last printed value with the assigned
471 value. The newly assigned value will remain until the next number is
472 printed or another value is assigned to LAST. (Some installations may
473 allow the use of a single period (.) which is not part of a number as
474 a short hand notation for for LAST.)
475  
476 =end comment
477  
478 =item STRING
479  
480 The string is printed to the output. Strings start with a double
481 quote character and contain all characters until the next double
482 quote character. All characters are taken literally, including
483 any newline. No newline character is printed after the string.
484  
485 =item C<print> LIST
486  
487 The C<print> statement (an extension) provides another method of
488 output. The LIST is a list of strings and expressions separated by
489 commas. Each string or expression is printed in the order of the
490 list. No terminating newline is printed. Expressions are
491 evaluated and their value is printed and assigned to the variable
492 C<last>. Strings in the print statement are printed to the output
493 and may contain special characters. Special characters start with
494 the backslash character. The special characters include:
495  
496 \a alert or bell
497 \b backspace
498 \f form feed
499 \n newline
500 \r carriage return
501 \q double quote
502 \t tab
503 \e backslash.
504  
505 Any other character following a backslash will be ignored.
506  
507 =item { STATEMENT_LIST }
508  
509 This is the compound statement. It allows multiple statements to
510 be grouped together for execution.
511  
512 =item C<if> ( EXPRESSION ) STATEMENT
513  
514 The C<if> statement evaluates the expression and executes STATEMENT
515 depending on the value of the expression. If the expression is
516 non-zero, STATEMENT is executed. Otherwise it isn't. (The statement
517 can be a block enclosed in { }.)
518  
519 =begin comment ### if-else is not supported in this implementation
520  
521 If the expression is non-zero, statement1 is executed. If statement2
522 is present and the value of the expression is 0, then statement2 is
523 executed. (The C<else> clause is an extension.)
524  
525 =end comment
526  
527 =item C<while> ( EXPRESSION ) STATEMENT
528  
529 The while statement will execute the statement while the expression
530 is non-zero. It evaluates the expression before each execution of
531 the statement. Termination of the loop is caused by a zero
532 expression value or the execution of a C<break> statement.
533  
534 =item C<for> ( [EXPRESSION1] ; [EXPRESSION2] ; [EXPRESSION3] ) STATEMENT
535  
536 The C<for> statement controls repeated execution of the statement.
537 EXPRESSION1 is evaluated before the loop. EXPRESSION2 is
538 evaluated before each execution of the statement. If it is
539 non-zero, the statement is evaluated. If it is zero, the loop is
540 terminated.
541  
542 After each execution of the statement, EXPRESSION3 is
543 evaluated before the reevaluation of expression2. If EXPRESSION1
544 or EXPRESSION3 are missing, nothing is evaluated at the point they
545 would be evaluated. If EXPRESSION2 is missing, it is the same as
546 substituting the value 1 for EXPRESSION2.
547  
548 (The optional expressions are an extension. POSIX C<bc> requires all
549 three expressions.)
550  
551 The following is equivalent code for the C<for>
552 statement:
553  
554 expression1;
555 while (expression2) {
556 statement;
557 expression3;
558 }
559  
560 =item C<break>
561  
562 This statement causes a forced exit of the most recent enclosing
563 C<while> statement or C<for> statement.
564  
565 =item C<quit>
566  
567 When the C<quit> statement is read, the C<bc> processor is
568 terminated, regardless of where the C<quit> statement is found. For
569 example, C<if (0 == 1) quit> will cause C<bc> to terminate.
570  
571 =back
572  
573 =head1 EXAMPLE
574  
575 The following illustrates how C<bc> expressions can be written in
576 script form and fed to C<bc> via stdin.
577  
578 =begin comment
579  
580 Note that the /* and */ are necessary to around the C<bc> code example
581 in order to prevent -l from processing these statements when reading <DATA>
582  
583 /*
584  
585 =end comment
586  
587 print "\nCompute balances after withdrawals\n"
588  
589 bal = 100.00
590 withdrawal = 20.00;
591  
592 while (1) {
593 print "Balance: ", "\t", bal, "\n"
594 print "Withdrawal: ", "\t", withdrawal, "\n"
595 if ( (bal - withdrawal) < 0 ) break;
596 bal -= withdrawal
597 }
598  
599 print "Balance:", bal
600  
601 quit
602  
603 =begin comment
604  
605 */
606  
607 =end comment
608  
609 =head1 BUGS AND LIMITATIONS
610  
611 This implementation of C<bc> is mostly POSIX compliant and has similar
612 extensions to GNU C<bc>. However, some features and extensions are
613 either not supported or are not working.
614  
615 Perhaps the biggest non-working feature would be Function definitions
616 via the C<define> syntax, which if used generates syntax errors. As a
617 consequence, the -l option (to load math library definitions) doesn't
618 work either.
619  
620 Setting the following variables don't seem to have the intended effects:
621  
622 scale
623 ibase
624 obase
625  
626 Hexadecimal values, for use when ibase is > 10, are not supported.
627  
628 Old style assignment operators (=+, =-, =*, =/, =%, =^) are not
629 required to be supported by the POSIX standard, and they are not
630 supported by this implementation. However, they will not generate
631 any errors. Instead you will get a result you don't expect.
632 For example:
633  
634 v=3; v += 2 # v is 5 as you would expect
635 v=3; v =+ 2 # v is 2 because the 2nd expression is seen as v = +2
636  
637 =head1 COMPARISON TO GNU C<bc> AND OTHERS
638  
639 The following C<bc> features are not supported in this implementation.
640 (Some are syntactically accepted, but simply return zero).
641  
642 * -w, --warn option
643 * -s, --standard option
644 * -q, --quiet option
645 * -v, --version option
646 * long options (e.g. --help)
647 * LC_ language and NLSPATH environment variables
648 * "last" special variable
649 * "if" statement: "else" clause
650 * "read" function
651 * "continue" statement
652 * "halt" statement
653 * "limits" pseudo statement
654 * "warranty" pseudo statement
655 * function definitions
656  
657 In addition, the GNU implementation set the precedence of assignment
658 below + and - and above relational operators (< > etc). This
659 implementation seems to make it the lowest precedence (i.e. below ||),
660 as most perl (and C) users would expect.
661  
662 =head1 REFERENCES
663  
664 POSIX C<bc> L<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html>
665  
666 GNU C<bc> L<https://www.gnu.org/software/bc/manual/html_mono/bc.html>
667  
668 =head2 GNU's mathlib
669  
670 Load the GNU math extensions with the C<-l> switch:
671  
672 % bc -l FILE
673  
674 The library provides these functions:
675  
676 =over 4
677  
678 =item * a(x) - the arctangent of X, where X is expressed in radians
679  
680 =item * c(x) - the cosine of X, where X is expressed in radians
681  
682 =item * e(X) - the natural base, e, raised to the X power
683  
684 =item * j(n,x) - the Bessel function of order n, where n is an integer
685  
686 =item * l(X) - the natural logarithm of X
687  
688 =item * s(x) - the sine of X, where X is expressed in radians
689  
690 =back
691  
692 =head1 AUTHOR
693  
694 Philip A. Nelson originally translated GNU bc to Perl for the PerlPowerTools
695 project.
696  
697 https://github.com/briandfoy/PerlPowerTools
698  
699 =head1 LICENSE
700  
701 You can use and modify this program under the terms of the GNU Public
702 License version 2. A copy of this license is in the PerlPowerTools
703 repository:
704  
705 https://github.com/briandfoy/PerlPowerTools/
706  
707 =cut
708  
709 67 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
710  
711 67 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
712 67 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
713  
714 # The symbol table : the keys are the identifiers, the value is in the
715 # "var" field if it is a variable, in the "func" field if it is a
716 # function.
717 67 my %sym_table;
718 67 my @stmt_list = ();
719 67 my @ope_stack;
720 my @backup_sym_table;
721 67 my $input;
722 67 my $cur_file = '-';
723 67 my $bignum = 0;
724 67 my $do_stdin = 0;
725 67 my $line;
726 my $var;
727 67 my $yychar;
728 67 my $yydebug;
729 67 my $yyerrflag;
730 67 my $yylval;
731 67 my $yyn;
732 67 my $yym;
733 67 my $yyssp;
734 67 my $yystate;
735 67 my $yyval;
736 67 my $yyvsp;
737  
738 67 my $debug = 0;
739 134 ▶sub debug(&) {
Subroutine debug: called CC=2 SCAR=7.2
740 134 my $fn = shift;
741 134 ▶ print STDERR "\t".&$fn()
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 134 134
742 if $debug;
743 }
744  
745 67 my $INT=257;
746 67 my $FLOAT=258;
747 67 my $STRING=259;
748 67 my $IDENT=260;
749 67 my $C_COMMENT=261;
750 67 my $BREAK=262;
751 67 my $DEFINE=263;
752 67 my $AUTO=264;
753 67 my $RETURN=265;
754 67 my $PRINT=266;
755 67 my $AUTO_LIST=267;
756 67 my $IF=268;
757 67 my $ELSE=269;
758 67 my $QUIT=270;
759 67 my $WHILE=271;
760 67 my $FOR=272;
761 67 my $EQ=273;
762 67 my $NE=274;
763 67 my $GT=275;
764 67 my $GE=276;
765 67 my $LT=277;
766 67 my $LE=278;
767 67 my $PP=279;
768 67 my $MM=280;
769 67 my $P_EQ=281;
770 67 my $M_EQ=282;
771 67 my $F_EQ=283;
772 67 my $D_EQ=284;
773 67 my $EXP_EQ=285;
774 67 my $MOD_EQ=286;
775 67 my $L_SHIFT=287;
776 67 my $R_SHIFT=288;
777 67 my $E_E=289;
778 67 my $O_O=290;
779 67 my $EXP=291;
780 67 my $UNARY=292;
781 67 my $PPP=293;
782 67 my $MMM=294;
783 67 my $YYERRCODE=256;
784 67 my @yylhs = ( -1,
785 0, 0, 1, 1, 1, 3, 4, 9, 3, 3,
786 3, 12, 3, 13, 3, 14, 3, 15, 17, 3,
787 18, 19, 20, 3, 3, 10, 10, 16, 16, 8,
788 8, 6, 6, 2, 2, 5, 5, 22, 22, 23,
789 23, 24, 24, 7, 7, 25, 25, 11, 11, 21,
790 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
791 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
792 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
793 21, 21, 21, 21, 21, 21, 21, 26, 26,
794 );
795 67 my @yylen = ( 2,
796 0, 2, 1, 2, 2, 1, 0, 0, 13, 1,
797 1, 0, 3, 0, 4, 0, 7, 0, 0, 8,
798 0, 0, 0, 13, 1, 1, 4, 0, 1, 1,
799 3, 0, 1, 1, 1, 0, 1, 1, 3, 0,
800 1, 1, 3, 0, 3, 1, 3, 1, 3, 4,
801 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
802 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
803 3, 3, 3, 2, 2, 2, 2, 2, 2, 2,
804 2, 3, 6, 1, 1, 1, 1, 1, 4,
805 );
806 67 my @yydefred = ( 1,
807 0, 0, 85, 86, 87, 0, 0, 11, 7, 0,
808 12, 0, 6, 18, 0, 0, 0, 0, 0, 0,
809 14, 0, 34, 35, 2, 3, 0, 10, 0, 0,
810 5, 0, 0, 0, 81, 0, 0, 0, 0, 0,
811 0, 0, 76, 77, 80, 74, 0, 0, 75, 4,
812 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
813 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
814 0, 0, 78, 79, 0, 0, 0, 0, 0, 0,
815 0, 0, 0, 0, 0, 29, 0, 0, 51, 0,
816 30, 0, 0, 0, 0, 0, 0, 0, 0, 0,
817 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
818 0, 0, 0, 50, 0, 0, 0, 27, 0, 16,
819 0, 21, 0, 15, 0, 0, 0, 38, 0, 0,
820 0, 0, 0, 0, 89, 31, 0, 0, 0, 33,
821 0, 19, 0, 0, 39, 17, 0, 22, 0, 20,
822 0, 0, 0, 0, 8, 23, 46, 0, 0, 0,
823 0, 45, 0, 0, 47, 9, 24,
824 );
825 67 my @yydgoto = ( 1,
826 25, 140, 86, 36, 129, 141, 155, 90, 159, 28,
827 82, 38, 48, 132, 40, 91, 147, 134, 151, 160,
828 29, 130, 77, 78, 158, 30,
829 );
830 67 my @yysindex = ( 0,
831 475, -8, 0, 0, 0, 84, -239, 0, 0, -11,
832 0, 3, 0, 0, 19, -218, -218, 899, 899, 899,
833 0, 899, 0, 0, 0, 0, -8, 0, 893, -54,
834 0, 899, 899, 899, 0, -199, 899, 899, 958, 24,
835 958, -26, 0, 0, 0, 0, -32, 958, 0, 0,
836 899, 899, 899, 899, 899, 899, 899, 899, 899, 899,
837 899, 899, 899, 899, 899, 899, 899, 899, 899, 899,
838 899, 899, 0, 0, 893, 893, 25, 48, 830, 65,
839 852, 64, 893, 27, 958, 0, 53, 899, 0, 26,
840 0, 923, 923, 142, 142, 142, 142, 416, 416, -21,
841 -21, -30, -30, -29, -29, -180, -180, 142, 142, 142,
842 142, 142, 142, 0, 899, 67, -146, 0, 899, 0,
843 85, 0, 874, 0, 958, 893, 899, 0, 86, 87,
844 893, -8, -8, 958, 0, 0, 893, -8, -127, 0,
845 958, 0, 88, 41, 0, 0, 958, 0, -8, 0,
846 958, -116, 108, -103, 0, 0, 0, 18, 958, -8,
847 -100, 0, 31, 958, 0, 0, 0,
848 );
849 67 my @yyrindex = ( 0,
850 0, 0, 0, 0, 0, -10, 0, 0, 0, 28,
851 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
852 0, 0, 0, 0, 0, 0, 0, 0, 30, 37,
853 0, 0, 127, 0, 0, 0, 0, 0, 0, 0,
854 119, 57, 0, 0, 0, 0, 0, 36, 0, 0,
855 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
856 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
857 0, 0, 0, 0, 4, -40, 0, 139, 0, 0,
858 0, 34, 66, 0, 145, 0, 0, 0, 0, 0,
859 0, 820, 822, 507, 518, 537, 551, 405, 442, 298,
860 380, 122, 192, 129, 167, 76, 99, 572, 579, 680,
861 758, 777, 799, 0, 0, 13, 149, 0, 0, 0,
862 0, 0, 0, 0, 36, -38, 0, 0, 0, 153,
863 93, 1023, 1023, 119, 0, 0, 29, 60, 0, 0,
864 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
865 145, 499, 0, 0, 0, 0, 0, 0, 36, 1023,
866 0, 0, 0, 0, 0, 0, 0,
867 );
868 67 my @yygindex = ( 0,
869 0, 358, 52, 0, 0, -108, 0, 38, 0, 0,
870 0, 0, 0, 0, 0, 337, 0, 0, 0, 0,
871 1278, 0, 0, 0, 0, 2,
872 );
873 67 my @yytable = ( 88,
874 42, 24, 43, 42, 65, 43, 65, 65, 89, 63,
875 61, 63, 62, 82, 64, 65, 64, 43, 44, 35,
876 63, 61, 89, 62, 142, 64, 88, 24, 37, 144,
877 88, 88, 88, 88, 88, 24, 88, 26, 83, 25,
878 24, 42, 39, 13, 82, 28, 84, 82, 88, 89,
879 23, 164, 27, 89, 89, 89, 89, 89, 41, 89,
880 80, 161, 82, 85, 88, 114, 88, 120, 26, 83,
881 25, 89, 83, 84, 13, 48, 23, 84, 84, 84,
882 84, 84, 88, 84, 23, 67, 26, 83, 25, 23,
883 84, 115, 13, 88, 28, 84, 82, 88, 88, 88,
884 88, 88, 49, 88, 117, 89, 48, 119, 66, 48,
885 66, 122, 67, 128, 88, 88, 67, 67, 67, 67,
886 67, 83, 67, 33, 48, 133, 138, 127, 82, 84,
887 139, 62, 145, 49, 67, 66, 49, 89, 64, 66,
888 66, 66, 66, 66, 32, 66, 148, 154, 156, 88,
889 124, 49, 26, 83, 25, 166, 157, 66, 13, 165,
890 28, 84, 62, 149, 62, 62, 62, 40, 67, 64,
891 64, 64, 64, 64, 34, 64, 65, 28, 65, 41,
892 62, 88, 32, 63, 61, 28, 62, 64, 64, 36,
893 48, 66, 146, 37, 0, 0, 163, 0, 150, 0,
894 67, 63, 0, 0, 0, 0, 0, 65, 65, 65,
895 65, 65, 0, 65, 62, 167, 0, 49, 0, 0,
896 0, 64, 0, 66, 0, 65, 67, 68, 69, 70,
897 71, 72, 63, 0, 63, 63, 63, 0, 73, 74,
898 51, 52, 53, 54, 55, 56, 62, 0, 0, 0,
899 63, 0, 0, 64, 57, 58, 59, 60, 66, 65,
900 66, 66, 88, 88, 88, 88, 88, 88, 0, 66,
901 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
902 88, 0, 88, 88, 63, 89, 89, 89, 89, 89,
903 89, 65, 0, 89, 89, 89, 89, 89, 89, 89,
904 89, 89, 89, 89, 0, 89, 89, 53, 0, 84,
905 84, 84, 84, 84, 84, 0, 63, 0, 0, 0,
906 0, 0, 0, 84, 84, 84, 84, 84, 0, 88,
907 88, 88, 88, 88, 88, 0, 0, 0, 53, 0,
908 0, 53, 0, 88, 88, 88, 88, 88, 67, 67,
909 67, 67, 67, 67, 0, 0, 53, 0, 26, 31,
910 0, 0, 67, 67, 67, 67, 0, 0, 0, 0,
911 0, 66, 66, 66, 66, 66, 66, 87, 0, 0,
912 0, 0, 0, 0, 50, 66, 66, 66, 66, 52,
913 53, 0, 0, 0, 62, 62, 62, 62, 62, 62,
914 0, 64, 64, 64, 64, 64, 64, 0, 62, 62,
915 62, 62, 0, 0, 60, 64, 64, 64, 64, 0,
916 52, 121, 53, 52, 0, 0, 0, 0, 57, 58,
917 59, 60, 66, 0, 0, 0, 0, 0, 52, 65,
918 65, 65, 65, 65, 65, 60, 0, 125, 60, 0,
919 0, 61, 65, 65, 65, 65, 65, 63, 61, 0,
920 62, 136, 64, 60, 63, 63, 63, 63, 63, 63,
921 143, 0, 52, 0, 0, 0, 0, 0, 63, 63,
922 63, 63, 61, 0, 24, 61, 0, 153, 0, 0,
923 0, 0, 0, 0, 0, 0, 0, 60, 0, 0,
924 61, 0, 0, 0, 52, 0, 152, 22, 44, 0,
925 0, 0, 7, 0, 20, 162, 56, 18, 0, 19,
926 125, 0, 0, 0, 0, 0, 0, 57, 0, 60,
927 0, 44, 0, 23, 61, 0, 44, 0, 44, 0,
928 0, 44, 0, 44, 0, 0, 58, 56, 0, 0,
929 56, 0, 0, 0, 0, 0, 0, 44, 57, 0,
930 59, 57, 0, 0, 0, 56, 61, 0, 0, 0,
931 53, 53, 53, 53, 53, 53, 57, 58, 0, 0,
932 58, 68, 0, 0, 53, 53, 53, 53, 69, 0,
933 0, 59, 0, 0, 59, 58, 0, 21, 0, 56,
934 0, 0, 0, 0, 0, 0, 0, 0, 0, 59,
935 57, 0, 68, 0, 0, 68, 0, 0, 0, 69,
936 0, 44, 69, 44, 0, 0, 0, 0, 0, 58,
937 68, 56, 0, 0, 0, 0, 0, 69, 0, 0,
938 0, 0, 57, 59, 0, 0, 0, 0, 0, 0,
939 0, 0, 52, 52, 52, 52, 52, 52, 0, 0,
940 0, 58, 0, 0, 68, 0, 52, 52, 52, 52,
941 0, 69, 0, 0, 0, 59, 0, 60, 60, 60,
942 60, 60, 60, 0, 0, 0, 0, 0, 0, 70,
943 0, 60, 60, 0, 0, 0, 68, 0, 0, 0,
944 0, 0, 0, 69, 59, 60, 66, 0, 0, 0,
945 0, 0, 0, 0, 61, 61, 61, 61, 61, 61,
946 70, 0, 0, 70, 0, 0, 0, 0, 61, 61,
947 2, 3, 4, 5, 6, 0, 8, 9, 70, 10,
948 11, 0, 12, 0, 13, 14, 15, 0, 0, 0,
949 0, 0, 0, 16, 17, 44, 44, 44, 44, 0,
950 44, 44, 0, 44, 44, 0, 44, 71, 44, 44,
951 44, 0, 70, 0, 0, 0, 0, 44, 44, 56,
952 56, 56, 56, 56, 56, 0, 72, 0, 0, 0,
953 57, 57, 57, 57, 57, 57, 0, 0, 71, 0,
954 0, 71, 0, 0, 70, 0, 0, 0, 73, 58,
955 58, 58, 58, 58, 58, 0, 71, 72, 0, 0,
956 72, 0, 0, 59, 59, 59, 59, 59, 59, 54,
957 0, 55, 0, 0, 0, 72, 0, 0, 0, 73,
958 0, 0, 73, 0, 68, 68, 68, 68, 68, 68,
959 71, 69, 69, 69, 69, 69, 69, 73, 0, 0,
960 54, 0, 55, 54, 0, 55, 65, 0, 0, 72,
961 0, 63, 61, 0, 62, 0, 64, 0, 54, 0,
962 55, 0, 71, 0, 0, 0, 0, 0, 65, 0,
963 0, 73, 118, 63, 61, 0, 62, 0, 64, 0,
964 0, 72, 0, 0, 0, 0, 0, 0, 0, 0,
965 65, 0, 54, 0, 55, 63, 61, 0, 62, 0,
966 64, 0, 116, 73, 0, 0, 0, 0, 0, 65,
967 0, 22, 0, 0, 63, 61, 7, 62, 20, 64,
968 0, 18, 0, 19, 54, 0, 55, 0, 0, 0,
969 0, 0, 70, 70, 70, 70, 70, 70, 0, 65,
970 0, 0, 0, 0, 63, 61, 135, 62, 0, 64,
971 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
972 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
973 22, 0, 0, 0, 0, 7, 0, 20, 0, 0,
974 18, 0, 19, 0, 0, 0, 0, 0, 0, 0,
975 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
976 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
977 71, 71, 71, 71, 71, 71, 0, 0, 0, 0,
978 0, 0, 0, 0, 0, 0, 0, 0, 0, 72,
979 72, 72, 72, 72, 72, 32, 0, 0, 0, 0,
980 32, 0, 32, 0, 0, 32, 0, 32, 0, 0,
981 0, 73, 73, 73, 73, 73, 73, 0, 0, 0,
982 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
983 0, 0, 54, 54, 55, 55, 0, 0, 0, 0,
984 0, 0, 51, 52, 53, 54, 55, 56, 0, 0,
985 0, 0, 0, 0, 0, 0, 57, 58, 59, 60,
986 66, 0, 0, 0, 51, 52, 53, 54, 55, 56,
987 0, 0, 0, 0, 0, 0, 0, 0, 57, 58,
988 59, 60, 66, 0, 0, 32, 51, 52, 53, 54,
989 55, 56, 0, 0, 0, 3, 4, 5, 6, 0,
990 57, 58, 59, 60, 66, 51, 52, 53, 54, 55,
991 56, 0, 0, 0, 0, 0, 0, 16, 17, 57,
992 58, 59, 60, 66, 0, 0, 0, 0, 0, 0,
993 0, 0, 0, 0, 0, 0, 0, 53, 54, 55,
994 56, 0, 0, 0, 0, 0, 0, 0, 0, 57,
995 58, 59, 60, 66, 3, 4, 5, 6, 0, 8,
996 9, 0, 10, 11, 0, 12, 0, 13, 14, 15,
997 0, 0, 0, 0, 0, 0, 16, 17, 0, 0,
998 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
999 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1000 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1001 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,
1002 32, 32, 32, 0, 32, 32, 0, 32, 32, 0,
1003 32, 0, 32, 32, 32, 45, 46, 47, 0, 49,
1004 0, 32, 32, 0, 0, 0, 0, 0, 0, 75,
1005 76, 79, 0, 0, 81, 83, 0, 0, 0, 0,
1006 0, 0, 0, 0, 0, 0, 0, 0, 92, 93,
1007 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
1008 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
1009 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1010 0, 0, 0, 0, 0, 123, 0, 0, 0, 0,
1011 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1012 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1013 0, 0, 126, 0, 0, 0, 131, 0, 0, 0,
1014 0, 0, 0, 0, 137,
1015 );
1016 67 my @yycheck = ( 10,
1017 41, 10, 41, 44, 37, 44, 37, 37, 41, 42,
1018 43, 42, 45, 10, 47, 37, 47, 16, 17, 259,
1019 42, 43, 10, 45, 133, 47, 37, 10, 40, 138,
1020 41, 42, 43, 44, 45, 10, 47, 10, 10, 10,
1021 10, 260, 40, 10, 41, 10, 10, 44, 59, 37,
1022 59, 160, 1, 41, 42, 43, 44, 45, 40, 47,
1023 260, 44, 59, 40, 91, 41, 10, 41, 41, 41,
1024 41, 59, 44, 37, 41, 10, 59, 41, 42, 43,
1025 44, 45, 93, 47, 59, 10, 59, 59, 59, 59,
1026 39, 44, 59, 37, 59, 59, 93, 41, 42, 43,
1027 44, 45, 10, 47, 40, 93, 41, 44, 10, 44,
1028 291, 59, 37, 260, 125, 59, 41, 42, 43, 44,
1029 45, 93, 47, 40, 59, 41, 41, 61, 125, 93,
1030 44, 10, 260, 41, 59, 37, 44, 125, 10, 41,
1031 42, 43, 44, 45, 61, 47, 59, 264, 41, 93,
1032 125, 59, 125, 125, 125, 125, 260, 59, 125, 260,
1033 125, 125, 41, 123, 43, 44, 45, 41, 93, 41,
1034 42, 43, 44, 45, 91, 47, 10, 59, 37, 41,
1035 59, 125, 123, 42, 43, 41, 45, 59, 47, 41,
1036 125, 93, 141, 41, -1, -1, 159, -1, 147, -1,
1037 125, 10, -1, -1, -1, -1, -1, 41, 42, 43,
1038 44, 45, -1, 47, 93, 164, -1, 125, -1, -1,
1039 -1, 93, -1, 125, -1, 59, 281, 282, 283, 284,
1040 285, 286, 41, -1, 43, 44, 45, -1, 293, 294,
1041 273, 274, 275, 276, 277, 278, 125, -1, -1, -1,
1042 59, -1, -1, 125, 287, 288, 289, 290, 291, 93,
1043 291, 291, 273, 274, 275, 276, 277, 278, -1, 291,
1044 281, 282, 283, 284, 285, 286, 287, 288, 289, 290,
1045 291, -1, 293, 294, 93, 273, 274, 275, 276, 277,
1046 278, 125, -1, 281, 282, 283, 284, 285, 286, 287,
1047 288, 289, 290, 291, -1, 293, 294, 10, -1, 273,
1048 274, 275, 276, 277, 278, -1, 125, -1, -1, -1,
1049 -1, -1, -1, 287, 288, 289, 290, 291, -1, 273,
1050 274, 275, 276, 277, 278, -1, -1, -1, 41, -1,
1051 -1, 44, -1, 287, 288, 289, 290, 291, 273, 274,
1052 275, 276, 277, 278, -1, -1, 59, -1, 1, 2,
1053 -1, -1, 287, 288, 289, 290, -1, -1, -1, -1,
1054 -1, 273, 274, 275, 276, 277, 278, 41, -1, -1,
1055 -1, -1, -1, -1, 27, 287, 288, 289, 290, 10,
1056 93, -1, -1, -1, 273, 274, 275, 276, 277, 278,
1057 -1, 273, 274, 275, 276, 277, 278, -1, 287, 288,
1058 289, 290, -1, -1, 10, 287, 288, 289, 290, -1,
1059 41, 85, 125, 44, -1, -1, -1, -1, 287, 288,
1060 289, 290, 291, -1, -1, -1, -1, -1, 59, 273,
1061 274, 275, 276, 277, 278, 41, -1, 90, 44, -1,
1062 -1, 10, 37, 287, 288, 289, 290, 42, 43, -1,
1063 45, 125, 47, 59, 273, 274, 275, 276, 277, 278,
1064 134, -1, 93, -1, -1, -1, -1, -1, 287, 288,
1065 289, 290, 41, -1, 10, 44, -1, 151, -1, -1,
1066 -1, -1, -1, -1, -1, -1, -1, 93, -1, -1,
1067 59, -1, -1, -1, 125, -1, 149, 33, 10, -1,
1068 -1, -1, 38, -1, 40, 158, 10, 43, -1, 45,
1069 163, -1, -1, -1, -1, -1, -1, 10, -1, 125,
1070 -1, 33, -1, 59, 93, -1, 38, -1, 40, -1,
1071 -1, 43, -1, 45, -1, -1, 10, 41, -1, -1,
1072 44, -1, -1, -1, -1, -1, -1, 59, 41, -1,
1073 10, 44, -1, -1, -1, 59, 125, -1, -1, -1,
1074 273, 274, 275, 276, 277, 278, 59, 41, -1, -1,
1075 44, 10, -1, -1, 287, 288, 289, 290, 10, -1,
1076 -1, 41, -1, -1, 44, 59, -1, 123, -1, 93,
1077 -1, -1, -1, -1, -1, -1, -1, -1, -1, 59,
1078 93, -1, 41, -1, -1, 44, -1, -1, -1, 41,
1079 -1, 123, 44, 125, -1, -1, -1, -1, -1, 93,
1080 59, 125, -1, -1, -1, -1, -1, 59, -1, -1,
1081 -1, -1, 125, 93, -1, -1, -1, -1, -1, -1,
1082 -1, -1, 273, 274, 275, 276, 277, 278, -1, -1,
1083 -1, 125, -1, -1, 93, -1, 287, 288, 289, 290,
1084 -1, 93, -1, -1, -1, 125, -1, 273, 274, 275,
1085 276, 277, 278, -1, -1, -1, -1, -1, -1, 10,
1086 -1, 287, 288, -1, -1, -1, 125, -1, -1, -1,
1087 -1, -1, -1, 125, 289, 290, 291, -1, -1, -1,
1088 -1, -1, -1, -1, 273, 274, 275, 276, 277, 278,
1089 41, -1, -1, 44, -1, -1, -1, -1, 287, 288,
1090 256, 257, 258, 259, 260, -1, 262, 263, 59, 265,
1091 266, -1, 268, -1, 270, 271, 272, -1, -1, -1,
1092 -1, -1, -1, 279, 280, 257, 258, 259, 260, -1,
1093 262, 263, -1, 265, 266, -1, 268, 10, 270, 271,
1094 272, -1, 93, -1, -1, -1, -1, 279, 280, 273,
1095 274, 275, 276, 277, 278, -1, 10, -1, -1, -1,
1096 273, 274, 275, 276, 277, 278, -1, -1, 41, -1,
1097 -1, 44, -1, -1, 125, -1, -1, -1, 10, 273,
1098 274, 275, 276, 277, 278, -1, 59, 41, -1, -1,
1099 44, -1, -1, 273, 274, 275, 276, 277, 278, 10,
1100 -1, 10, -1, -1, -1, 59, -1, -1, -1, 41,
1101 -1, -1, 44, -1, 273, 274, 275, 276, 277, 278,
1102 93, 273, 274, 275, 276, 277, 278, 59, -1, -1,
1103 41, -1, 41, 44, -1, 44, 37, -1, -1, 93,
1104 -1, 42, 43, -1, 45, -1, 47, -1, 59, -1,
1105 59, -1, 125, -1, -1, -1, -1, -1, 37, -1,
1106 -1, 93, 41, 42, 43, -1, 45, -1, 47, -1,
1107 -1, 125, -1, -1, -1, -1, -1, -1, -1, -1,
1108 37, -1, 93, -1, 93, 42, 43, -1, 45, -1,
1109 47, -1, 93, 125, -1, -1, -1, -1, -1, 37,
1110 -1, 33, -1, -1, 42, 43, 38, 45, 40, 47,
1111 -1, 43, -1, 45, 125, -1, 125, -1, -1, -1,
1112 -1, -1, 273, 274, 275, 276, 277, 278, -1, 37,
1113 -1, -1, -1, -1, 42, 43, 93, 45, -1, 47,
1114 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1115 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1116 33, -1, -1, -1, -1, 38, -1, 40, -1, -1,
1117 43, -1, 45, -1, -1, -1, -1, -1, -1, -1,
1118 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1119 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1120 273, 274, 275, 276, 277, 278, -1, -1, -1, -1,
1121 -1, -1, -1, -1, -1, -1, -1, -1, -1, 273,
1122 274, 275, 276, 277, 278, 33, -1, -1, -1, -1,
1123 38, -1, 40, -1, -1, 43, -1, 45, -1, -1,
1124 -1, 273, 274, 275, 276, 277, 278, -1, -1, -1,
1125 123, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1126 -1, -1, 273, 274, 273, 274, -1, -1, -1, -1,
1127 -1, -1, 273, 274, 275, 276, 277, 278, -1, -1,
1128 -1, -1, -1, -1, -1, -1, 287, 288, 289, 290,
1129 291, -1, -1, -1, 273, 274, 275, 276, 277, 278,
1130 -1, -1, -1, -1, -1, -1, -1, -1, 287, 288,
1131 289, 290, 291, -1, -1, 123, 273, 274, 275, 276,
1132 277, 278, -1, -1, -1, 257, 258, 259, 260, -1,
1133 287, 288, 289, 290, 291, 273, 274, 275, 276, 277,
1134 278, -1, -1, -1, -1, -1, -1, 279, 280, 287,
1135 288, 289, 290, 291, -1, -1, -1, -1, -1, -1,
1136 -1, -1, -1, -1, -1, -1, -1, 275, 276, 277,
1137 278, -1, -1, -1, -1, -1, -1, -1, -1, 287,
1138 288, 289, 290, 291, 257, 258, 259, 260, -1, 262,
1139 263, -1, 265, 266, -1, 268, -1, 270, 271, 272,
1140 -1, -1, -1, -1, -1, -1, 279, 280, -1, -1,
1141 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1142 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1143 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1144 -1, -1, -1, -1, -1, -1, -1, -1, -1, 257,
1145 258, 259, 260, -1, 262, 263, -1, 265, 266, -1,
1146 268, -1, 270, 271, 272, 18, 19, 20, -1, 22,
1147 -1, 279, 280, -1, -1, -1, -1, -1, -1, 32,
1148 33, 34, -1, -1, 37, 38, -1, -1, -1, -1,
1149 -1, -1, -1, -1, -1, -1, -1, -1, 51, 52,
1150 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
1151 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
1152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1153 -1, -1, -1, -1, -1, 88, -1, -1, -1, -1,
1154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1156 -1, -1, 115, -1, -1, -1, 119, -1, -1, -1,
1157 -1, -1, -1, -1, 127,
1158 );
1159 67 my $YYFINAL=1;
1160 67 my $YYMAXTOKEN=294;
1161 67 my @yyname = (
1162 "end-of-file",'','','','','','','','','',"'\\n'",'','','','','','','','','','','','','','','','','','','','',
1163 '','',"'!'",'','','',"'%'","'&'",'',"'('","')'","'*'","'+'","','","'-'","'.'","'/'",'',
1164 '','','','','','','','','','',"';'",'',"'='",'','','','','','','','','','','','','','','','','','','','','','','',
1165 '','','','','','',"'['",'',"']'",'','','','','','','','','','','','','','','','','','','','','','','','','','','',
1166 '','',"'{'","'|'","'}'",'','','','','','','','','','','','','','','','','','','','','','','','','','','','','',
1167 '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',
1168 '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',
1169 '','','','','','','','','','','','','','','','','','','','','','',"INT","FLOAT","STRING","IDENT",
1170 "C_COMMENT","BREAK","DEFINE","AUTO","RETURN","PRINT","AUTO_LIST","IF","ELSE",
1171 "QUIT","WHILE","FOR","EQ","NE","GT","GE","LT","LE","PP","MM","P_EQ","M_EQ",
1172 "F_EQ","D_EQ","EXP_EQ","MOD_EQ","L_SHIFT","R_SHIFT","E_E","O_O","EXP","UNARY",
1173 "PPP","MMM",
1174 );
1175 67 my @yyrule = (
1176 "\$accept : stmt_list_exec",
1177 "stmt_list_exec :",
1178 "stmt_list_exec : stmt_list_exec stmt_exec",
1179 "stmt_exec : terminator",
1180 "stmt_exec : stmt_compile terminator",
1181 "stmt_exec : error terminator",
1182 "stmt_compile : QUIT",
1183 "\$\$1 :",
1184 "\$\$2 :",
1185 "stmt_compile : DEFINE \$\$1 IDENT '(' arg_list ')' terminator_or_void '{' terminator auto_list \$\$2 stmt_list_block '}'",
1186 "stmt_compile : return",
1187 "stmt_compile : BREAK",
1188 "\$\$3 :",
1189 "stmt_compile : PRINT \$\$3 expr_list_commas",
1190 "\$\$4 :",
1191 "stmt_compile : '{' \$\$4 stmt_list_block '}'",
1192 "\$\$5 :",
1193 "stmt_compile : IF '(' stmt_compile ')' \$\$5 terminator_or_void stmt_compile",
1194 "\$\$6 :",
1195 "\$\$7 :",
1196 "stmt_compile : WHILE \$\$6 '(' stmt_compile_or_void ')' terminator_or_void \$\$7 stmt_compile",
1197 "\$\$8 :",
1198 "\$\$9 :",
1199 "\$\$10 :",
1200 "stmt_compile : FOR '(' stmt_compile_or_void ';' \$\$8 stmt_compile_or_void ';' \$\$9 stmt_compile_or_void ')' \$\$10 terminator_or_void stmt_compile",
1201 "stmt_compile : expr",
1202 "return : RETURN",
1203 "return : RETURN '(' expr ')'",
1204 "stmt_compile_or_void :",
1205 "stmt_compile_or_void : stmt_compile",
1206 "stmt_list_block : stmt_compile_or_void",
1207 "stmt_list_block : stmt_list_block terminator stmt_compile_or_void",
1208 "terminator_or_void :",
1209 "terminator_or_void : terminator",
1210 "terminator : ';'",
1211 "terminator : '\\n'",
1212 "arg_list :",
1213 "arg_list : arg_list_nonempty",
1214 "arg_list_nonempty : IDENT",
1215 "arg_list_nonempty : arg_list_nonempty ',' IDENT",
1216 "param_list :",
1217 "param_list : param_list_nonempty",
1218 "param_list_nonempty : expr",
1219 "param_list_nonempty : param_list_nonempty ',' expr",
1220 "auto_list :",
1221 "auto_list : AUTO auto_list_nonempty terminator",
1222 "auto_list_nonempty : IDENT",
1223 "auto_list_nonempty : auto_list_nonempty ',' IDENT",
1224 "expr_list_commas : expr",
1225 "expr_list_commas : expr_list_commas ',' expr",
1226 "expr : IDENT '(' param_list ')'",
1227 "expr : '(' expr ')'",
1228 "expr : expr O_O expr",
1229 "expr : expr E_E expr",
1230 "expr : expr EQ expr",
1231 "expr : expr NE expr",
1232 "expr : expr GT expr",
1233 "expr : expr GE expr",
1234 "expr : expr LT expr",
1235 "expr : expr LE expr",
1236 "expr : expr L_SHIFT expr",
1237 "expr : expr R_SHIFT expr",
1238 "expr : expr '+' expr",
1239 "expr : expr '-' expr",
1240 "expr : expr '*' expr",
1241 "expr : expr '/' expr",
1242 "expr : expr EXP expr",
1243 "expr : expr '%' expr",
1244 "expr : ident P_EQ expr",
1245 "expr : ident M_EQ expr",
1246 "expr : ident F_EQ expr",
1247 "expr : ident D_EQ expr",
1248 "expr : ident EXP_EQ expr",
1249 "expr : ident MOD_EQ expr",
1250 "expr : '-' expr",
1251 "expr : '!' expr",
1252 "expr : PP ident",
1253 "expr : MM ident",
1254 "expr : ident PPP",
1255 "expr : ident MMM",
1256 "expr : '+' expr",
1257 undef, # "expr : '&' STRING", # removed feature but we didn't want to disturb sequence
1258 "expr : IDENT '=' expr",
1259 "expr : IDENT '[' expr ']' '=' expr",
1260 "expr : ident",
1261 "expr : INT",
1262 "expr : FLOAT",
1263 "expr : STRING",
1264 "ident : IDENT",
1265 "ident : IDENT '[' expr ']'",
1266 );
1267 584 ▶sub yyclearin { $yychar = -1; }
Subroutine yyclearin: called CC=1 SCAR=0.0
1268 0 ▶sub yyerrok { $yyerrflag = 0; }
Subroutine yyerrok: not called CC=1 SCAR=6.9
1269 67 my $YYSTACKSIZE = 500;
1270 67 my @yyss;
1271 my @yyvs;
1272 67 $yyss[$YYSTACKSIZE] = 0;
1273 67 $yyvs[$YYSTACKSIZE] = 0;
1274  
1275 sub yy_err_recover
1276 0 ▶{
Subroutine yy_err_recover: not called CC=12 SCAR=50.5
1277 0 ▶ if ($yyerrflag < 3)
Branch: 1 branch
BranchTrueFalseTotal
if ($yyerrflag < 3) { } 0 0 0
1278 {
1279 0 $yyerrflag = 3;
1280 0 while (1)
1281 {
1282 0 ▶ if (($yyn = $yysindex[$yyss[$yyssp]]) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn = $yysindex[$yyss[$yyssp]] and ($yyn += $YYERRCODE) >= 0 and $yycheck[$yyn] == $YYERRCODE) { } 0 0 0
Condition0%0/6
$yyn = $yysindex[$yyss[$yyssp]] and ($yyn += $YYERRCODE) >= 0 and $yycheck[$yyn] == $YYERRCODE
!ll&&!rl&&r
000
$yyn = $yysindex[$yyss[$yyssp]] and ($yyn += $YYERRCODE) >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$yyn = $yysindex[$yyss[$yyssp]] and ($yyn += $YYERRCODE) >= 0 and $yycheck[$yyn] == $YYERRCODE
$yyn = $yysindex[$yyss[$yyssp]] ($yyn += $YYERRCODE) >= 0 $yycheck[$yyn] == $YYERRCODE
Truth table0%0/4
A and B and C
A= $yyn = $yysindex[$yyss[$yyssp]]B= ($yyn += $YYERRCODE) >= 0C= $yycheck[$yyn] == $YYERRCODE
ABCresult
0XX0
10X0
1100
1111
1283 ($yyn += $YYERRCODE) >= 0 &&
1284 $yycheck[$yyn] == $YYERRCODE)
1285 {
1286 0 ▶ print "yydebug: state $yyss[$yyssp], error recovery shifting",
Branch: 1 branch
BranchTrueFalseTotal
if $yydebug 0 0 0
1287 " to state $yytable[$yyn]\n" if $yydebug;
1288 0 $yyss[++$yyssp] = $yystate = $yytable[$yyn];
1289 0 $yyvs[++$yyvsp] = $yylval;
1290 0 return 1;
1291 }
1292 else
1293 {
1294 0 ▶ print "yydebug: error recovery discarding state ",
Branch: 1 branch
BranchTrueFalseTotal
if $yydebug 0 0 0
1295 $yyss[$yyssp], "\n" if $yydebug;
1296 0 ▶ return(1) if $yyssp <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $yyssp <= 0 0 0 0
1297 0 --$yyssp;
1298 0 --$yyvsp;
1299 }
1300 }
1301 }
1302 else
1303 {
1304 0 ▶ return (1) if $yychar == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $yychar == 0 0 0 0
1305 0 ▶ if ($yydebug)
Branch: 1 branch
BranchTrueFalseTotal
if ($yydebug) 0 0 0
1306 {
1307 0 my $yys = '';
1308 0 ▶ if ($yychar <= $YYMAXTOKEN) { $yys = $yyname[$yychar]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($yychar <= $YYMAXTOKEN) 0 0 0
1309 0 ▶ if (!$yys) { $yys = 'illegal-symbol'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($yys) 0 0 0
1310 0 print "yydebug: state $yystate, error recovery discards ",
1311 "token $yychar ($yys)\n";
1312 }
1313 0 return 1;
1314 }
1315 0 0;
1316 } # yy_err_recover
1317  
1318 sub clear_flags
1319 70 ▶{
Subroutine clear_flags: called CC=1 SCAR=0.0
1320 70 yyclearin();
1321 70 $yyerrflag = $yyssp = $yyvsp = $yyss[0] = $yystate = 0;
1322 }
1323  
1324 sub yyparse
1325 70 ▶{
Subroutine yyparse: called CC=105 SCAR=52.4
1326 70 yyloop: while(1)
1327 {
1328 yyreduce: {
1329 1490 ▶ last yyreduce if ($yyn = $yydefred[$yystate]);
Branch: 1 branch
BranchTrueFalseTotal
if $yyn = $yydefred[$yystate] 637 853 1490
1330 853 ▶ if ($yychar < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($yychar < 0) 395 458 853
1331 {
1332 0 ▶ if (($yychar = &yylex) < 0) { $yychar = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (($yychar = &yylex) < 0) 0 395 395
1333 395 ▶ if ($yydebug)
Branch: 1 branch
BranchTrueFalseTotal
if ($yydebug) 0 395 395
1334 {
1335 0 my $yys = '';
1336 0 ▶ if ($yychar <= $#yyname) { $yys = $yyname[$yychar]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($yychar <= $#yyname) 0 0 0
1337 0 ▶ if (!$yys) { $yys = 'illegal-symbol'; };
Branch: 1 branch
BranchTrueFalseTotal
unless ($yys) 0 0 0
1338 0 print "yydebug: state $yystate, reading $yychar ($yys)\n";
1339 }
1340 }
1341 853 ▶ if (($yyn = $yysindex[$yystate]) && ($yyn += $yychar) >= 0 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn = $yysindex[$yystate] and ($yyn += $yychar) >= 0 and $yycheck[$yyn] == $yychar) 514 339 853
Condition83%5/6
$yyn = $yysindex[$yystate] and ($yyn += $yychar) >= 0 and $yycheck[$yyn] == $yychar
!ll&&!rl&&r
51288514
$yyn = $yysindex[$yystate] and ($yyn += $yychar) >= 0
!ll&&!rl&&r
051802
MC/DC66%2/3
$yyn = $yysindex[$yystate] and ($yyn += $yychar) >= 0 and $yycheck[$yyn] == $yychar
$yyn = $yysindex[$yystate] ($yyn += $yychar) >= 0 $yycheck[$yyn] == $yychar
Truth table75%3/4
A and B and C
A= $yyn = $yysindex[$yystate]B= ($yyn += $yychar) >= 0C= $yycheck[$yyn] == $yychar
ABCresult
0XX0
10X0
1100
1111
1342 $yycheck[$yyn] == $yychar)
1343 {
1344 514 ▶ print "yydebug: state $yystate, shifting to state ",
Branch: 1 branch
BranchTrueFalseTotal
if $yydebug 0 514 514
1345 $yytable[$yyn], "\n" if $yydebug;
1346 514 $yyss[++$yyssp] = $yystate = $yytable[$yyn];
1347 514 $yyvs[++$yyvsp] = $yylval;
1348 514 yyclearin();
1349 514 ▶ --$yyerrflag if $yyerrflag > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $yyerrflag > 0 0 514 514
1350 514 next yyloop;
1351 }
1352 339 ▶ if (($yyn = $yyrindex[$yystate]) && ($yyn += $yychar) >= 0 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn = $yyrindex[$yystate] and ($yyn += $yychar) >= 0 and $yycheck[$yyn] == $yychar) 339 0 339
Condition33%2/6
$yyn = $yyrindex[$yystate] and ($yyn += $yychar) >= 0 and $yycheck[$yyn] == $yychar
!ll&&!rl&&r
00339
$yyn = $yyrindex[$yystate] and ($yyn += $yychar) >= 0
!ll&&!rl&&r
00339
MC/DC0%0/3
$yyn = $yyrindex[$yystate] and ($yyn += $yychar) >= 0 and $yycheck[$yyn] == $yychar
$yyn = $yyrindex[$yystate] ($yyn += $yychar) >= 0 $yycheck[$yyn] == $yychar
Truth table25%1/4
A and B and C
A= $yyn = $yyrindex[$yystate]B= ($yyn += $yychar) >= 0C= $yycheck[$yyn] == $yychar
ABCresult
0XX0
10X0
1100
1111
1353 $yycheck[$yyn] == $yychar)
1354 {
1355 339 $yyn = $yytable[$yyn];
1356 339 last yyreduce;
1357 }
1358 0 ▶ if (! $yyerrflag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($yyerrflag) 0 0 0
1359 0 &yyerror('syntax error');
1360 }
1361 0 ▶ return(1) if &yy_err_recover;
Branch: 1 branch
BranchTrueFalseTotal
if &yy_err_recover 0 0 0
1362 } # yyreduce
1363 976 ▶ print "yydebug: state $yystate, reducing by rule ",
Branch: 1 branch
BranchTrueFalseTotal
if $yydebug 0 976 976
1364 "$yyn ($yyrule[$yyn])\n" if $yydebug;
1365 976 $yym = $yylen[$yyn];
1366 976 $yyval = $yyvs[$yyvsp+1-$yym];
1367 switch:
1368 {
1369 976 ▶if ($yyn == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 4) 119 857 976
1370 {
1371  
1372 119 my ($res, $val) = exec_stmt(shift @stmt_list);
1373 116 ▶ if($res == 0 and defined($val) and
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 0 and defined $val and $cur_file ne "main::DATA") 59 57 116
Condition66%4/6
$res == 0 and defined $val and $cur_file ne "main::DATA"
!ll&&!rl&&r
57059
$res == 0 and defined $val
!ll&&!rl&&r
57059
MC/DC33%1/3
$res == 0 and defined $val and $cur_file ne "main::DATA"
$res == 0 defined $val $cur_file ne "main::DATA"
Truth table50%2/4
A and B and C
A= $res == 0B= defined $valC= $cur_file ne "main::DATA"
ABCresult
0XX0
10X0
1100
1111
1374 $cur_file ne 'main::DATA') {
1375 59 print "$val\n";
1376 }
1377 116 start_stmt();
1378  
1379 116 last switch;
1380 } }
1381 857 ▶if ($yyn == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 5) 0 857 857
1382 {
1383 0 @ope_stack = ();
1384 0 @stmt_list = ();
1385 0 start_stmt();
1386 0 &yyerrok;
1387  
1388 0 last switch;
1389 } }
1390 857 ▶if ($yyn == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 7) 0 857 857
1391 {
1392 0 start_stmt();
1393  
1394 0 last switch;
1395 } }
1396 857 ▶if ($yyn == 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 8) 0 857 857
1397 {
1398 0 start_stmt();
1399 0 start_stmt();
1400  
1401 0 last switch;
1402 } }
1403 857 ▶if ($yyn == 9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 9) 0 857 857
1404 {
1405 0 finish_stmt(); # The last one is empty
1406 0 push_instr('RETURN', 0);
1407 0 my $body = finish_stmt();
1408 0 push_instr('{}', $body);
1409 0 my $code = finish_stmt();
1410 0 push_instr('FUNCTION-DEF', $yyvs[$yyvsp-10], $code);
1411  
1412 0 last switch;
1413 } }
1414 857 ▶if ($yyn == 11) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 11) 1 856 857
1415 1 { push_instr('BREAK');
1416 1 last switch;
1417 } }
1418 856 ▶if ($yyn == 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 12) 10 846 856
1419 {
1420 10 push_instr(',');
1421 10 start_stmt();
1422 10 start_stmt();
1423  
1424 10 last switch;
1425 } }
1426 846 ▶if ($yyn == 13) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 13) 10 836 846
1427 {
1428 10 finish_stmt(); # The last one is empty
1429 10 my $stmt = finish_stmt();
1430 10 push_instr('PRINT', $stmt);
1431  
1432 10 last switch;
1433 } }
1434 836 ▶if ($yyn == 14) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 14) 4 832 836
1435 {
1436 4 start_stmt();
1437 4 start_stmt();
1438  
1439 4 last switch;
1440 } }
1441 832 ▶if ($yyn == 15) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 15) 4 828 832
1442 {
1443 4 finish_stmt(); # The last one is empty
1444 4 my $stmt = finish_stmt();
1445 4 push_instr('{}', $stmt);
1446  
1447 4 last switch;
1448 } }
1449 828 ▶if ($yyn == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 16) 1 827 828
1450 1 { start_stmt();
1451 1 last switch;
1452 } }
1453 827 ▶if ($yyn == 17) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 17) 1 826 827
1454 {
1455 1 my $stmt = finish_stmt();
1456 1 push_instr('IF', $stmt);
1457  
1458 1 last switch;
1459 } }
1460 826 ▶if ($yyn == 18) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 18) 1 825 826
1461 1 { start_stmt();
1462 1 last switch;
1463 } }
1464 825 ▶if ($yyn == 19) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 19) 1 824 825
1465 {
1466 1 my $stmt = finish_stmt();
1467 1 push_instr('FOR-COND', $stmt);
1468 1 start_stmt();
1469  
1470 1 last switch;
1471 } }
1472 824 ▶if ($yyn == 20) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 20) 1 823 824
1473 {
1474 1 my $stmt = finish_stmt();
1475 1 push_instr('FOR-INCR', []);
1476 1 push_instr('FOR-BODY', $stmt);
1477  
1478 1 last switch;
1479 } }
1480 823 ▶if ($yyn == 21) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 21) 2 821 823
1481 2 { start_stmt();
1482 2 last switch;
1483 } }
1484 821 ▶if ($yyn == 22) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 22) 2 819 821
1485 {
1486 2 my $stmt = finish_stmt();
1487 2 push_instr('FOR-COND', $stmt);
1488 2 start_stmt();
1489  
1490 2 last switch;
1491 } }
1492 819 ▶if ($yyn == 23) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 23) 2 817 819
1493 {
1494 2 my $stmt = finish_stmt();
1495 2 push_instr('FOR-INCR', $stmt);
1496 2 start_stmt();
1497  
1498 2 last switch;
1499 } }
1500 817 ▶if ($yyn == 24) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 24) 2 815 817
1501 {
1502 2 my $stmt = finish_stmt();
1503 2 push_instr('FOR-BODY', $stmt);
1504  
1505 2 last switch;
1506 } }
1507 815 ▶if ($yyn == 26) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 26) 0 815 815
1508 0 { push_instr('RETURN', 0);
1509 0 last switch;
1510 } }
1511 815 ▶if ($yyn == 27) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 27) 0 815 815
1512 0 { push_instr('RETURN', 1);
1513 0 last switch;
1514 } }
1515 815 ▶if ($yyn == 30) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 30) 4 811 815
1516 {
1517 4 my $stmt = finish_stmt();
1518 4 ▶ if(scalar(@$stmt) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$stmt > 0) 4 0 4
1519 4 push_instr('STMT', $stmt);
1520 }
1521 4 start_stmt();
1522  
1523 4 last switch;
1524 } }
1525 811 ▶if ($yyn == 31) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 31) 3 808 811
1526 {
1527 3 my $stmt = finish_stmt();
1528 3 ▶ if(scalar(@$stmt) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$stmt > 0) 3 0 3
1529 3 push_instr('STMT', $stmt);
1530 }
1531 3 start_stmt();
1532  
1533 3 last switch;
1534 } }
1535 808 ▶if ($yyn == 38) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 38) 0 808 808
1536 0 { push_instr('a', $yyvs[$yyvsp-0]);
1537 0 last switch;
1538 } }
1539 808 ▶if ($yyn == 39) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 39) 0 808 808
1540 0 { push_instr('a', $yyvs[$yyvsp-0]);
1541 0 last switch;
1542 } }
1543 808 ▶if ($yyn == 46) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 46) 0 808 808
1544 0 { push_instr('A', $yyvs[$yyvsp-0]);
1545 0 last switch;
1546 } }
1547 808 ▶if ($yyn == 47) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 47) 0 808 808
1548 0 { push_instr('A', $yyvs[$yyvsp-0]);
1549 0 last switch;
1550 } }
1551 808 ▶if ($yyn == 48) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 48) 10 798 808
1552 {
1553 10 my $stmt = finish_stmt();
1554 10 push_instr('PRINT-STMT', $stmt);
1555 10 start_stmt();
1556  
1557 10 last switch;
1558 } }
1559 798 ▶if ($yyn == 49) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 49) 3 795 798
1560 {
1561 3 my $stmt = finish_stmt();
1562 3 push_instr('PRINT-STMT', $stmt);
1563 3 start_stmt();
1564  
1565 3 last switch;
1566 } }
1567 795 ▶if ($yyn == 50) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 50) 6 789 795
1568 {
1569 6 push_instr('FUNCTION-CALL', $yyvs[$yyvsp-3]);
1570  
1571 6 last switch;
1572 } }
1573 789 ▶if ($yyn == 51) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 51) 4 785 789
1574 {
1575 4 last switch;
1576 } }
1577 785 ▶if ($yyn == 52) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 52) 4 781 785
1578 4 { push_instr('||_');
1579 4 last switch;
1580 } }
1581 781 ▶if ($yyn == 53) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 53) 4 777 781
1582 4 { push_instr('&&_');
1583 4 last switch;
1584 } }
1585 777 ▶if ($yyn == 54) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 54) 2 775 777
1586 2 { push_instr('==_');
1587 2 last switch;
1588 } }
1589 775 ▶if ($yyn == 55) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 55) 2 773 775
1590 2 { push_instr('!=_');
1591 2 last switch;
1592 } }
1593 773 ▶if ($yyn == 56) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 56) 2 771 773
1594 2 { push_instr('>_');
1595 2 last switch;
1596 } }
1597 771 ▶if ($yyn == 57) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 57) 2 769 771
1598 2 { push_instr('>=_');
1599 2 last switch;
1600 } }
1601 769 ▶if ($yyn == 58) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 58) 5 764 769
1602 5 { push_instr('<_');
1603 5 last switch;
1604 } }
1605 764 ▶if ($yyn == 59) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 59) 1 763 764
1606 1 { push_instr('<=_');
1607 1 last switch;
1608 } }
1609 763 ▶if ($yyn == 60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 60) 0 763 763
1610 0 { push_instr('<<_');
1611 0 last switch;
1612 } }
1613 763 ▶if ($yyn == 61) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 61) 0 763 763
1614 0 { push_instr('>>_');
1615 0 last switch;
1616 } }
1617 763 ▶if ($yyn == 62) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 62) 8 755 763
1618 8 { push_instr('+_');
1619 8 last switch;
1620 } }
1621 755 ▶if ($yyn == 63) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 63) 1 754 755
1622 1 { push_instr('-_');
1623 1 last switch;
1624 } }
1625 754 ▶if ($yyn == 64) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 64) 5 749 754
1626 5 { push_instr('*_');
1627 5 last switch;
1628 } }
1629 749 ▶if ($yyn == 65) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 65) 1 748 749
1630 1 { push_instr('/_');
1631 1 last switch;
1632 } }
1633 748 ▶if ($yyn == 66) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 66) 2 746 748
1634 2 { push_instr('^_');
1635 2 last switch;
1636 } }
1637 746 ▶if ($yyn == 67) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 67) 2 744 746
1638 2 { push_instr('%_');
1639 2 last switch;
1640 } }
1641 744 ▶if ($yyn == 68) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 68) 1 743 744
1642 {
1643 1 push_instr('+_');
1644 1 push_instr('V', $yyvs[$yyvsp-2]);
1645 1 push_instr('=V');
1646  
1647 1 last switch;
1648 } }
1649 743 ▶if ($yyn == 69) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 69) 1 742 743
1650 {
1651 1 push_instr('-_');
1652 1 push_instr('V', $yyvs[$yyvsp-2]);
1653 1 push_instr('=V');
1654  
1655 1 last switch;
1656 } }
1657 742 ▶if ($yyn == 70) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 70) 1 741 742
1658 {
1659 1 push_instr('*_');
1660 1 push_instr('V', $yyvs[$yyvsp-2]);
1661 1 push_instr('=V');
1662  
1663 1 last switch;
1664 } }
1665 741 ▶if ($yyn == 71) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 71) 3 738 741
1666 {
1667 3 push_instr('/_');
1668 3 push_instr('V', $yyvs[$yyvsp-2]);
1669 3 push_instr('=V');
1670  
1671 3 last switch;
1672 } }
1673 738 ▶if ($yyn == 72) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 72) 6 732 738
1674 {
1675 6 push_instr('^_');
1676 6 push_instr('V', $yyvs[$yyvsp-2]);
1677 6 push_instr('=V');
1678  
1679 6 last switch;
1680 } }
1681 732 ▶if ($yyn == 73) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 73) 5 727 732
1682 {
1683 5 push_instr('%_');
1684 5 push_instr('V', $yyvs[$yyvsp-2]);
1685 5 push_instr('=V');
1686  
1687 5 last switch;
1688 } }
1689 727 ▶if ($yyn == 74) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 74) 5 722 727
1690 {
1691 5 push_instr('m_');
1692  
1693 5 last switch;
1694 } }
1695 722 ▶if ($yyn == 75) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 75) 2 720 722
1696 {
1697 2 push_instr('!_');
1698  
1699 2 last switch;
1700 } }
1701 720 ▶if ($yyn == 76) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 76) 1 719 720
1702 {
1703 # 'v'.$2 has already been pushed in the 'ident' rule
1704 1 push_instr('N', 1);
1705 1 push_instr('+_');
1706 1 push_instr('V', $yyvs[$yyvsp-0]);
1707 1 push_instr('=V');
1708  
1709 1 last switch;
1710 } }
1711 719 ▶if ($yyn == 77) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 77) 1 718 719
1712 {
1713 1 push_instr('N', 1);
1714 1 push_instr('-_');
1715 1 push_instr('V', $yyvs[$yyvsp-0]);
1716 1 push_instr('=V');
1717  
1718 1 last switch;
1719 } }
1720 718 ▶if ($yyn == 78) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 78) 3 715 718
1721 {
1722 # $1 is already on the stack (see the "ident:" rule)
1723 3 push_instr('v', $yyvs[$yyvsp-1]) ;
1724 3 push_instr('V', '*tmp') ;
1725 3 push_instr('=V') ; # *tmp = $1
1726 3 push_instr(',') ;
1727  
1728 3 push_instr('N', 1) ;
1729 3 push_instr('+_') ;
1730 3 push_instr('V', $yyvs[$yyvsp-1]) ;
1731 3 push_instr('=V') ; # $1 = $1 + 1
1732 3 push_instr(',') ;
1733  
1734 3 push_instr('v', '*tmp') ; # Return *tmp
1735  
1736  
1737 3 last switch;
1738 } }
1739 715 ▶if ($yyn == 79) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 79) 2 713 715
1740 {
1741 # See PPP for comments
1742 2 push_instr('v', $yyvs[$yyvsp-1]);
1743 2 push_instr('V', '*tmp');
1744 2 push_instr('=V');
1745 2 push_instr(',');
1746 2 push_instr('N', 1);
1747 2 push_instr('-_');
1748 2 push_instr('V', $yyvs[$yyvsp-1]);
1749 2 push_instr('=V');
1750 2 push_instr(',');
1751 2 push_instr('v', '*tmp');
1752  
1753 2 last switch;
1754 } }
1755 713 ▶if ($yyn == 80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 80) 0 713 713
1756 0 { $yyval = $yyvs[$yyvsp-0];
1757 0 last switch;
1758 } }
1759 713 ▶if ($yyn == 82) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 82) 33 680 713
1760 {
1761 33 push_instr('V', $yyvs[$yyvsp-2]);
1762 33 push_instr('=V');
1763 33 $yyval = $yyvs[$yyvsp-0];
1764  
1765 33 last switch;
1766 } }
1767 680 ▶if ($yyn == 83) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 83) 0 680 680
1768 {
1769 # Add [] to the name in order to allow the same name
1770 # for an array and a scalar
1771 0 push_instr('P', $yyvs[$yyvsp-5]);
1772 0 push_instr('=P');
1773 0 $yyval = $yyvs[$yyvsp-0];
1774  
1775 0 last switch;
1776 } }
1777 680 ▶if ($yyn == 84) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 84) 33 647 680
1778 33 { $yyval = $yyvs[$yyvsp-0];
1779 33 last switch;
1780 } }
1781 647 ▶if ($yyn == 85) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 85) 118 529 647
1782 118 { push_instr('N', $yyvs[$yyvsp-0]);
1783 118 last switch;
1784 } }
1785 529 ▶if ($yyn == 86) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 86) 5 524 529
1786 5 { push_instr('N', $yyvs[$yyvsp-0]);
1787 5 last switch;
1788 } }
1789 524 ▶if ($yyn == 87) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 87) 10 514 524
1790 10 { push_instr('S', $yyvs[$yyvsp-0]);
1791 10 last switch;
1792 } }
1793 514 ▶if ($yyn == 88) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 88) 57 457 514
1794 57 { push_instr('v', $yyvs[$yyvsp-0]);
1795 57 last switch;
1796 } }
1797 457 ▶if ($yyn == 89) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn == 89) 0 457 457
1798 {
1799 0 push_instr('p', $yyvs[$yyvsp-3]);
1800 0 $yyval = $yyvs[$yyvsp-3].'[]'.$yyvs[$yyvsp-1];
1801  
1802 0 last switch;
1803 } }
1804 } # switch
1805 973 $yyssp -= $yym;
1806 973 $yystate = $yyss[$yyssp];
1807 973 $yyvsp -= $yym;
1808 973 $yym = $yylhs[$yyn];
1809 973 ▶ if ($yystate == 0 && $yym == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($yystate == 0 and $yym == 0) 186 787 973
Condition66%2/3
$yystate == 0 and $yym == 0
!ll&&!rl&&r
7870186
MC/DC50%1/2
$yystate == 0 and $yym == 0
$yystate == 0 $yym == 0
Truth table66%2/3
A and B
A= $yystate == 0B= $yym == 0
ABresult
0X0
100
111
1810 {
1811 186 ▶ print "yydebug: after reduction, shifting from state 0 ",
Branch: 1 branch
BranchTrueFalseTotal
if $yydebug 0 186 186
1812 "to state $YYFINAL\n" if $yydebug;
1813 186 $yystate = $YYFINAL;
1814 186 $yyss[++$yyssp] = $YYFINAL;
1815 186 $yyvs[++$yyvsp] = $yyval;
1816 186 ▶ if ($yychar < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($yychar < 0) 186 0 186
1817 {
1818 0 ▶ if (($yychar = &yylex) < 0) { $yychar = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (($yychar = &yylex) < 0) 0 186 186
1819 186 ▶ if ($yydebug)
Branch: 1 branch
BranchTrueFalseTotal
if ($yydebug) 0 186 186
1820 {
1821 0 my $yys = '';
1822 0 ▶ if ($yychar <= $#yyname) { $yys = $yyname[$yychar]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($yychar <= $#yyname) 0 0 0
1823 0 ▶ if (!$yys) { $yys = 'illegal-symbol'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($yys) 0 0 0
1824 0 print "yydebug: state $YYFINAL, reading $yychar ($yys)\n";
1825 }
1826 }
1827 186 ▶ return(0) if $yychar == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $yychar == 0 67 119 186
1828 119 next yyloop;
1829 }
1830 787 ▶ if (($yyn = $yygindex[$yym]) && ($yyn += $yystate) >= 0 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($yyn = $yygindex[$yym] and ($yyn += $yystate) >= 0 and $yyn <= $#yycheck and $yycheck[$yyn] == $yystate) { } 393 394 787
Condition88%8/9
$yyn = $yygindex[$yym] and ($yyn += $yystate) >= 0 and $yyn <= $#yycheck and $yycheck[$yyn] == $yystate
!ll&&!rl&&r
170224393
$yyn = $yygindex[$yym] and ($yyn += $yystate) >= 0 and $yyn <= $#yycheck
!ll&&!rl&&r
1646617
$yyn = $yygindex[$yym] and ($yyn += $yystate) >= 0
!ll&&!rl&&r
1640623
MC/DC75%3/4
$yyn = $yygindex[$yym] and ($yyn += $yystate) >= 0 and $yyn <= $#yycheck and $yycheck[$yyn] == $yystate
$yyn = $yygindex[$yym] ($yyn += $yystate) >= 0 $yyn <= $#yycheck $yycheck[$yyn] == $yystate
Truth table80%4/5
A and B and C and D
A= $yyn = $yygindex[$yym]B= ($yyn += $yystate) >= 0C= $yyn <= $#yycheckD= $yycheck[$yyn] == $yystate
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1831 $yyn <= $#yycheck && $yycheck[$yyn] == $yystate)
1832 {
1833 393 $yystate = $yytable[$yyn];
1834 } else {
1835 394 $yystate = $yydgoto[$yym];
1836 }
1837 787 ▶ print "yydebug: after reduction, shifting from state ",
Branch: 1 branch
BranchTrueFalseTotal
if $yydebug 0 787 787
1838 "$yyss[$yyssp] to state $yystate\n" if $yydebug;
1839 787 $yyss[++$yyssp] = $yystate;
1840 787 $yyvs[++$yyvsp] = $yyval;
1841 } # yyloop
1842 } # yyparse
1843  
1844 67 my @file_list;
1845 67 my $mathlib = 0;
1846 sub command_line
1847 67 ▶{
Subroutine command_line: called CC=11 SCAR=44.3
1848 67 ▶ while (@ARGV && $ARGV[0] =~ m/\A\-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV and $ARGV[0] =~ /\A\-/) 0 67 67
Condition33%1/3
@ARGV and $ARGV[0] =~ /\A\-/
!ll&&!rl&&r
0670
MC/DC0%0/2
@ARGV and $ARGV[0] =~ /\A\-/
@ARGV $ARGV[0] =~ /\A\-/
Truth table33%1/3
A and B
A= @ARGVB= $ARGV[0] =~ /\A\-/
ABresult
0X0
100
111
1849 0 my $f = shift @ARGV;
1850 0 ▶ if ($f eq '-b') {
Branch: 5 branches
BranchTrueFalseTotal
if ($f eq '-b') { } 0 0 0
elsif ($f eq '-d') { } 0 0 0
elsif ($f eq '-y') { } 0 0 0
elsif ($f eq '-l') { } 0 0 0
elsif ($f eq '--') { } 0 0 0
1851 0 ▶ eval { require Math::BigFloat } or die "This program requires the Math::BigFloat module\n";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Math::BigFloat } } or die "This program requires the Math::BigFloat module\n" 0 0 0
1852 0 $bignum = 1;
1853 } elsif ($f eq '-d') {
1854 0 ▶ eval { require Data::Dumper; Data::Dumper->import; 1; } or die "This program requires the Data::Dumper module\n";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Data::Dumper; "Data::Dumper"->import; 1 } } or die "This program requires the Data::Dumper module\n" 0 0 0
1855 0 $debug = 1;
1856 } elsif ($f eq '-y') {
1857 0 $yydebug = 1;
1858 } elsif ($f eq '-l') {
1859 0 $mathlib = 1;
1860 } elsif ($f eq '--') {
1861 0 last;
1862 } else {
1863 0 usage();
1864 }
1865 }
1866 67 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) { } 67 0 67
1867 67 @file_list = @ARGV;
1868 } else {
1869 0 $do_stdin = 1;
1870 }
1871 }
1872  
1873 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
1874 0 warn "usage: bc [-b] [-d] [-y] [-l] [file ...]\n";
1875 0 exit 1;
1876 }
1877  
1878 # After finishing a file, open the next one. Return whether there
1879 # really is a next one that was opened.
1880 sub next_file
1881 134 ▶{
Subroutine next_file: called CC=6 SCAR=19.6
1882 134 ▶ if (defined $input) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $input) 67 67 134
1883 67 close $input;
1884 67 $input = undef;
1885 }
1886 134 ▶ if ($do_stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_stdin) 0 134 134
1887 0 $input = *STDIN;
1888 0 $do_stdin = 0;
1889 0 $cur_file = '-';
1890 0 return 1;
1891 }
1892 134 ▶ if (@file_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@file_list) 67 67 134
1893 67 my $file = shift @file_list;
1894  
1895 0 ▶ debug { "reading from $file\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1896  
1897 67 ▶ die "path '$file' is a directory\n" if (-d $file);
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 0 67 67
1898 67 ▶ open($input, '<', $file) or die("cannot open '$file': $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open $input, "<", $file or die "cannot open '${file}': $!\n" 67 0 67
1899 67 $cur_file = $file;
1900 67 return 1;
1901  
1902 }
1903  
1904 0 ▶ debug { "no next file\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1905  
1906 67 return 0;
1907 }
1908  
1909 # print an error message
1910 sub yyerror
1911 3 ▶{
Subroutine yyerror: called CC=2 SCAR=7.0
1912 3 ▶ print STDERR "\"$cur_file\", " if $cur_file ne '-';
Branch: 1 branch
BranchTrueFalseTotal
if $cur_file ne "-" 3 0 3
1913 # debug { "yyerror-stmt_list : ".Dumper(\@stmt_list) };
1914  
1915 3 print STDERR "line $.: ", @_, "\n";
1916  
1917 3 @ope_stack = ();
1918 3 start_stmt();
1919 }
1920  
1921 # Hand-coded lex
1922 sub yylex
1923 581 ▶{
Subroutine yylex: called CC=72 SCAR=48.6
1924 lexloop: {
1925 # get a line of input, if we need it.
1926 581 ▶ if ($line eq '')
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 171 410 581
1927 {
1928 171 ▶ while(! ($line = <$input>)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line = readline $input) 67 104 171
1929 67 ▶ &next_file || do {
Branch: 1 branch
BranchTrueFalseTotal
&next_file or do { return 0 } 0 67 67
1930 67 return(0); };
1931 }
1932 }
1933  
1934 # Skip over white space, and grab the first character.
1935 # If there is no such character, then grab the next line.
1936 514 ▶ $line =~ s/^\s*(.|\n)// || next lexloop;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/^\s*(.|\n)// or next lexloop 514 0 514
1937 514 my $char = $1;
1938  
1939 514 ▶ if ($char eq '/' and $line =~ /^\*/) {
Branch: 24 branches
BranchTrueFalseTotal
if ($char eq '/' and $line =~ /^\*/) { } 0 514 514
elsif ($char eq '#') { } 0 514 514
elsif ($char eq '\\' and $line eq "\n") { } 0 514 514
elsif ($char =~ /^(['"])/) { } 10 504 514
elsif ($char =~ /^[\dA-F]/ or $char eq '.' and $line =~ /\d/) { } 123 381 504
elsif ($char =~ /^[a-z]/) { } 111 270 381
elsif ($char eq '^' and $line =~ s/=//) { } 6 264 270
elsif ($char eq '^') { } 2 262 264
elsif ($char eq '|' and $line =~ s/^\|//) { } 4 258 262
elsif ($char eq '&' and $line =~ s/^&//) { } 4 254 258
elsif ($char eq '%' and $line =~ s/^=//) { } 5 249 254
elsif ($char eq '!' and $line =~ s/^=//) { } 2 247 249
elsif ($char eq '=' and $line =~ s/^=//) { } 2 245 247
elsif ($char =~ /^[<>]/ and $line =~ s/^=//) { } 3 242 245
elsif ($char =~ /^[<>]/ and $line =~ s/^$char//) { } 0 242 242
elsif ($char =~ /^[<>]/) { } 7 235 242
elsif ($char eq '+' and $line =~ s/^\+(\s*\w)/$1/) { } 1 234 235
elsif ($char eq '+' and $line =~ s/^=//) { } 1 233 234
elsif ($char eq '+' and $line =~ s/^\+//) { } 3 230 233
elsif ($char eq '-' and $line =~ s/^\-(\s*\w)/$1/) { } 1 229 230
elsif ($char eq '-' and $line =~ s/^\-//) { } 2 227 229
elsif ($char eq '-' and $line =~ s/^=//) { } 1 226 227
elsif ($char eq '*' and $line =~ s/^=//) { } 1 225 226
elsif ($char eq '/' and $line =~ s/^=//) { } 3 222 225
Condition66%2/3
$char eq "/" and $line =~ /^\*/
!ll&&!rl&&r
51040
MC/DC0%0/2
$char eq "/" and $line =~ /^\*/
$char eq "/" $line =~ /^\*/
Truth table66%2/3
A and B
A= $char eq "/"B= $line =~ /^\*/
ABresult
0X0
100
111
1940 # C-style comment
1941 0 ▶ while($line !~ m%\*/%) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ m[\*/]) 0 0 0
1942 0 $line = <$input>;
1943 }
1944 0 $line =~ s%.*?\*/% %;
1945 0 yylex();
1946 }
1947  
1948 elsif ($char eq '#') {
1949 # comment, so discard the line
1950 0 $line = "\n";
1951 0 &yylex;
1952  
1953 ▶ } elsif ($char eq '\\' and $line eq "\n") {
Condition33%1/3
$char eq "\\" and $line eq "\n"
!ll&&!rl&&r
51400
MC/DC0%0/2
$char eq "\\" and $line eq "\n"
$char eq "\\" $line eq "\n"
Truth table33%1/3
A and B
A= $char eq "\\"B= $line eq "\n"
ABresult
0X0
100
111
1954  
1955 # Discard the newline
1956 0 $line = '';
1957 0 yylex();
1958  
1959 } elsif ($char =~ /^(['"])/) {
1960  
1961 10 $yylval = "";
1962  
1963 10 my $c = $1;
1964 10 ▶ while($line !~ /$c/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /$c/) 0 10 10
1965 0 $yylval .= $line;
1966 0 $line = <$input>;
1967 }
1968  
1969 10 $line =~ s%(.*?)$c% %;
1970 10 $yylval .= $1;
1971  
1972 10 $STRING;
1973  
1974 ▶ } elsif ($char =~ /^[\dA-F]/ or
Condition50%3/6
$char =~ /^[\dA-F]/ or $char eq "." and $line =~ /\d/
l!l&&r!l&&!r
1230381
$char eq "." and $line =~ /\d/
!ll&&!rl&&r
38100
MC/DC33%1/3
$char =~ /^[\dA-F]/ or $char eq "." and $line =~ /\d/
$char =~ /^[\dA-F]/ $char eq "." $line =~ /\d/
Truth table50%2/4
A or B and C
A= $char =~ /^[\dA-F]/B= $char eq "."C= $line =~ /\d/
ABCresult
1XX1
0111
00X0
0100
1975 ($char eq '.' and $line =~ /\d/)) {
1976  
1977 123 ▶ if($char =~ /[A-F]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[A-F]/) 0 123 123
1978 0 &yyerror('Sorry, hexadecimal values are not supported');
1979 }
1980  
1981 123 ▶ $line = "0.$line" if($char eq '.');
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "." 0 123 123
1982  
1983 # number, is it integer or float?
1984 123 ▶ if ($line =~ s/^(\d+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^(\d+)//) { } 16 107 123
1985 16 my $str = $char . $1;
1986 16 ▶ $yylval = $bignum ? Math::BigFloat->new($str) : int($str);
Branch: 1 branch
BranchTrueFalseTotal
$bignum ? : 0 16 16
1987 } else {
1988 107 ▶ $yylval = $bignum ? Math::BigFloat->new($char) : int($char);
Branch: 1 branch
BranchTrueFalseTotal
$bignum ? : 0 107 107
1989 }
1990 123 my $type = $INT;
1991  
1992 123 ▶ if ($line =~ s/^(\.\d*)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^(\.\d*)//) 5 118 123
1993 5 my $tmp = "0$1"; # ".1" -> "0.1"
1994 5 $yylval += $tmp;
1995 5 $type = $FLOAT;
1996 }
1997 123 ▶ if ($line =~ s/^[eE]([-+]*\d+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^[eE]([-+]*\d+)//) 0 123 123
1998 0 ▶ my $mult = $bignum ? Math::BigFloat->new('10') : 10;
Branch: 1 branch
BranchTrueFalseTotal
$bignum ? : 0 0 0
1999 0 $mult = $mult ** $1;
2000 0 $yylval *= $mult;
2001 0 $type = $FLOAT;
2002 }
2003  
2004 123 $type;
2005  
2006 } elsif ($char =~ /^[a-z]/) {
2007 # Uppercase is reserved for hexadecimal numbers
2008 111 $line =~ s/^([\w\d]*)//;
2009 111 $yylval = $char.$1;
2010  
2011 111 ▶ if($yylval eq 'auto') {
Branch: 10 branches
BranchTrueFalseTotal
if ($yylval eq 'auto') { } 0 111 111
elsif ($yylval eq 'break') { } 1 110 111
elsif ($yylval eq 'define') { } 0 110 110
elsif ($yylval eq 'for') { } 2 108 110
elsif ($yylval eq 'if') { } 1 107 108
elsif ($yylval eq 'else') { } 0 107 107
elsif ($yylval eq 'print') { } 10 97 107
elsif ($yylval eq 'quit') { } 0 97 97
elsif ($yylval eq 'return') { } 0 97 97
elsif ($yylval eq 'while') { } 1 96 97
2012 0 $AUTO;
2013 } elsif($yylval eq 'break') {
2014 1 $BREAK;
2015 } elsif($yylval eq 'define') {
2016 0 $DEFINE;
2017 } elsif($yylval eq 'for') {
2018 2 $FOR;
2019 } elsif($yylval eq 'if') {
2020 1 $IF;
2021 } elsif($yylval eq 'else') {
2022 0 $ELSE;
2023 } elsif($yylval eq 'print') {
2024 10 $PRINT;
2025 } elsif($yylval eq 'quit') {
2026 # $QUIT;
2027 # GNU bc exits immediately when it encounters quit, even if
2028 # seen in unreachable code like "if (0 == 1) quit"
2029 # OpenBSD bc acts like this too but calls it a bug
2030 0 exit;
2031 } elsif($yylval eq 'return') {
2032 0 $RETURN;
2033 } elsif($yylval eq 'while') {
2034 1 $WHILE;
2035 } else {
2036 96 $IDENT;
2037 }
2038  
2039 ▶ } elsif ($char eq '^' && $line =~ s/=//) {
Condition100%3/3
$char eq "^" and $line =~ s/=//
!ll&&!rl&&r
26226
MC/DC100%2/2
$char eq "^" and $line =~ s/=//
$char eq "^" $line =~ s/=//
Truth table100%3/3
A and B
A= $char eq "^"B= $line =~ s/=//
ABresult
0X0
100
111
2040 6 $EXP_EQ;
2041 } elsif ($char eq '^') {
2042 2 $EXP;
2043 ▶ } elsif ($char eq '|' && $line =~ s/^\|//) {
Condition66%2/3
$char eq "|" and $line =~ s/^\|//
!ll&&!rl&&r
25804
MC/DC50%1/2
$char eq "|" and $line =~ s/^\|//
$char eq "|" $line =~ s/^\|//
Truth table66%2/3
A and B
A= $char eq "|"B= $line =~ s/^\|//
ABresult
0X0
100
111
2044 4 $O_O;
2045 ▶ } elsif ($char eq '&' && $line =~ s/^&//) {
Condition66%2/3
$char eq "&" and $line =~ s/^&//
!ll&&!rl&&r
25404
MC/DC50%1/2
$char eq "&" and $line =~ s/^&//
$char eq "&" $line =~ s/^&//
Truth table66%2/3
A and B
A= $char eq "&"B= $line =~ s/^&//
ABresult
0X0
100
111
2046 4 $E_E;
2047  
2048 ▶ } elsif ($char eq '%' && $line =~ s/^=//) {
Condition100%3/3
$char eq "%" and $line =~ s/^=//
!ll&&!rl&&r
24725
MC/DC100%2/2
$char eq "%" and $line =~ s/^=//
$char eq "%" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "%"B= $line =~ s/^=//
ABresult
0X0
100
111
2049 5 $MOD_EQ;
2050 ▶ } elsif ($char eq '!' && $line =~ s/^=//) {
Condition100%3/3
$char eq "!" and $line =~ s/^=//
!ll&&!rl&&r
24522
MC/DC100%2/2
$char eq "!" and $line =~ s/^=//
$char eq "!" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "!"B= $line =~ s/^=//
ABresult
0X0
100
111
2051 2 $NE;
2052 ▶ } elsif ($char eq '=' && $line =~ s/^=//) {
Condition100%3/3
$char eq "=" and $line =~ s/^=//
!ll&&!rl&&r
212332
MC/DC100%2/2
$char eq "=" and $line =~ s/^=//
$char eq "=" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "="B= $line =~ s/^=//
ABresult
0X0
100
111
2053 2 $EQ;
2054  
2055 ▶ } elsif ($char =~ /^[<>]/ && $line =~ s/^=//) {
Condition100%3/3
$char =~ /^[<>]/ and $line =~ s/^=//
!ll&&!rl&&r
23573
MC/DC100%2/2
$char =~ /^[<>]/ and $line =~ s/^=//
$char =~ /^[<>]/ $line =~ s/^=//
Truth table100%3/3
A and B
A= $char =~ /^[<>]/B= $line =~ s/^=//
ABresult
0X0
100
111
2056 3 ▶ $char eq '<' ? $LE : $GE;
Branch: 1 branch
BranchTrueFalseTotal
$char eq '<' ? : 1 2 3
2057 ▶ } elsif ($char =~ /^[<>]/ && $line =~ s/^$char//) {
Condition66%2/3
$char =~ /^[<>]/ and $line =~ s/^$char//
!ll&&!rl&&r
23570
MC/DC0%0/2
$char =~ /^[<>]/ and $line =~ s/^$char//
$char =~ /^[<>]/ $line =~ s/^$char//
Truth table66%2/3
A and B
A= $char =~ /^[<>]/B= $line =~ s/^$char//
ABresult
0X0
100
111
2058 0 ▶ $char eq '<' ? $L_SHIFT : $R_SHIFT;
Branch: 1 branch
BranchTrueFalseTotal
$char eq '<' ? : 0 0 0
2059 } elsif ($char =~ /^[<>]/) {
2060 7 ▶ $char eq '<' ? $LT : $GT;
Branch: 1 branch
BranchTrueFalseTotal
$char eq '<' ? : 5 2 7
2061  
2062 ▶ } elsif ($char eq '+' && $line =~ s/^\+(\s*\w)/$1/) {
Condition100%3/3
$char eq "+" and $line =~ s/^\+(\s*\w)/$1/
!ll&&!rl&&r
222121
MC/DC100%2/2
$char eq "+" and $line =~ s/^\+(\s*\w)/$1/
$char eq "+" $line =~ s/^\+(\s*\w)/$1/
Truth table100%3/3
A and B
A= $char eq "+"B= $line =~ s/^\+(\s*\w)/$1/
ABresult
0X0
100
111
2063 1 $PP;
2064 ▶ } elsif ($char eq '+' && $line =~ s/^=//) {
Condition100%3/3
$char eq "+" and $line =~ s/^=//
!ll&&!rl&&r
222111
MC/DC100%2/2
$char eq "+" and $line =~ s/^=//
$char eq "+" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "+"B= $line =~ s/^=//
ABresult
0X0
100
111
2065 1 $P_EQ;
2066 ▶ } elsif ($char eq '+' && $line =~ s/^\+//) {
Condition100%3/3
$char eq "+" and $line =~ s/^\+//
!ll&&!rl&&r
22283
MC/DC100%2/2
$char eq "+" and $line =~ s/^\+//
$char eq "+" $line =~ s/^\+//
Truth table100%3/3
A and B
A= $char eq "+"B= $line =~ s/^\+//
ABresult
0X0
100
111
2067 3 $PPP;
2068 ▶ } elsif ($char eq '-' && $line =~ s/^\-(\s*\w)/$1/) {
Condition100%3/3
$char eq "-" and $line =~ s/^\-(\s*\w)/$1/
!ll&&!rl&&r
22091
MC/DC100%2/2
$char eq "-" and $line =~ s/^\-(\s*\w)/$1/
$char eq "-" $line =~ s/^\-(\s*\w)/$1/
Truth table100%3/3
A and B
A= $char eq "-"B= $line =~ s/^\-(\s*\w)/$1/
ABresult
0X0
100
111
2069 1 $MM;
2070 ▶ } elsif ($char eq '-' && $line =~ s/^\-//) {
Condition100%3/3
$char eq "-" and $line =~ s/^\-//
!ll&&!rl&&r
22072
MC/DC100%2/2
$char eq "-" and $line =~ s/^\-//
$char eq "-" $line =~ s/^\-//
Truth table100%3/3
A and B
A= $char eq "-"B= $line =~ s/^\-//
ABresult
0X0
100
111
2071 2 $MMM;
2072 ▶ } elsif ($char eq '-' && $line =~ s/^=//) {
Condition100%3/3
$char eq "-" and $line =~ s/^=//
!ll&&!rl&&r
22061
MC/DC100%2/2
$char eq "-" and $line =~ s/^=//
$char eq "-" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "-"B= $line =~ s/^=//
ABresult
0X0
100
111
2073 1 $M_EQ;
2074 ▶ } elsif ($char eq '*' && $line =~ s/^=//) {
Condition100%3/3
$char eq "*" and $line =~ s/^=//
!ll&&!rl&&r
22051
MC/DC100%2/2
$char eq "*" and $line =~ s/^=//
$char eq "*" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "*"B= $line =~ s/^=//
ABresult
0X0
100
111
2075 1 $F_EQ;
2076 ▶ } elsif ($char eq '/' && $line =~ s/^=//) {
Condition100%3/3
$char eq "/" and $line =~ s/^=//
!ll&&!rl&&r
22113
MC/DC100%2/2
$char eq "/" and $line =~ s/^=//
$char eq "/" $line =~ s/^=//
Truth table100%3/3
A and B
A= $char eq "/"B= $line =~ s/^=//
ABresult
0X0
100
111
2077 3 $D_EQ;
2078 } else {
2079 222 $yylval = $char;
2080 222 ord($char);
2081 }
2082 }
2083 }
2084  
2085 sub bi_length
2086 1 ▶{
Subroutine bi_length: called CC=4 SCAR=14.2
2087 1 my $stack = shift;
2088  
2089 1 $_ = pop @$stack;
2090 1 ▶ die "length(n): missing argument\n" unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 1 1
2091  
2092 1 my ($a, $b);
2093 1 ▶ die "NaN" unless ($a, $b) = /[-+]?(\d*)\.?(\d+)?/;
Branch: 1 branch
BranchTrueFalseTotal
unless () = /[-+]?(\d*)\.?(\d+)?/ 0 1 1
2094  
2095 1 $a =~ s/^0+//;
2096 1 $b =~ s/0+$//;
2097  
2098 1 my $len = length($a) + length($b);
2099  
2100 1 ▶ return $len == 0 ? 1 : $len;
Branch: 1 branch
BranchTrueFalseTotal
$len == 0 ? : 0 1 1
2101 }
2102  
2103 sub bi_scale
2104 1 ▶{
Subroutine bi_scale: called CC=3 SCAR=11.2
2105 1 my $stack = shift;
2106  
2107 1 $_ = pop @$stack;
2108 1 ▶ die "scale(n): missing argument\n" unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 1 1
2109  
2110 1 my ($a, $b);
2111 1 ▶ die "NaN" unless ($a, $b) = /[-+]?(\d*)\.?(\d+)?/;
Branch: 1 branch
BranchTrueFalseTotal
unless () = /[-+]?(\d*)\.?(\d+)?/ 0 1 1
2112  
2113 1 return length($b);
2114 }
2115  
2116 sub bi_sqrt
2117 4 ▶{
Subroutine bi_sqrt: called CC=2 SCAR=7.0
2118 4 my $stack = shift;
2119  
2120 4 $_ = pop @$stack;
2121 4 ▶ die "sqrt(n): missing argument\n" unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 4 4
2122  
2123 4 return sqrt($_);
2124 }
2125  
2126 # mathlib sine function
2127 sub bi_s
2128 0 ▶{
Subroutine bi_s: not called CC=3 SCAR=24.8
2129 0 my $stack = shift;
2130  
2131 0 my $val = pop @$stack;
2132 0 ▶ die "s(n): missing argument\n" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
2133 0 my $bignum = ref $val;
2134 0 ▶ $val = $val->numify() if $bignum;
Branch: 1 branch
BranchTrueFalseTotal
if $bignum 0 0 0
2135 0 return sin($val);
2136 }
2137  
2138 # mathlib cosine function
2139 sub bi_c
2140 0 ▶{
Subroutine bi_c: not called CC=3 SCAR=24.8
2141 0 my $stack = shift;
2142  
2143 0 my $val = pop @$stack;
2144 0 ▶ die "c(n): missing argument\n" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
2145 0 my $bignum = ref $val;
2146 0 ▶ $val = $val->numify() if $bignum;
Branch: 1 branch
BranchTrueFalseTotal
if $bignum 0 0 0
2147 0 return cos($val);
2148 }
2149  
2150 # mathlib arctan function
2151 sub bi_a
2152 0 ▶{
Subroutine bi_a: not called CC=3 SCAR=24.8
2153 0 my $stack = shift;
2154  
2155 0 my $val = pop @$stack;
2156 0 ▶ die "a(n): missing argument\n" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
2157 0 my $bignum = ref $val;
2158 0 ▶ $val = $val->numify() if $bignum;
Branch: 1 branch
BranchTrueFalseTotal
if $bignum 0 0 0
2159 0 return Math::Trig::atan($val);
2160 }
2161  
2162 # mathlib ln function
2163 sub bi_l
2164 0 ▶{
Subroutine bi_l: not called CC=3 SCAR=24.8
2165 0 my $stack = shift;
2166  
2167 0 my $val = pop @$stack;
2168 0 ▶ die "l(n): missing argument\n" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
2169 0 my $bignum = ref $val;
2170 0 ▶ $val = $val->numify() if $bignum;
Branch: 1 branch
BranchTrueFalseTotal
if $bignum 0 0 0
2171 0 return log($val);
2172 }
2173  
2174 # mathlib exp function
2175 sub bi_e
2176 0 ▶{
Subroutine bi_e: not called CC=3 SCAR=24.8
2177 0 my $stack = shift;
2178  
2179 0 my $val = pop @$stack;
2180 0 ▶ die "e(n): missing argument\n" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
2181 0 my $bignum = ref $val;
2182 0 ▶ $val = $val->numify() if $bignum;
Branch: 1 branch
BranchTrueFalseTotal
if $bignum 0 0 0
2183 0 return exp($val);
2184 }
2185  
2186 # mathlib jn function
2187 sub bi_j
2188 0 ▶{
Subroutine bi_j: not called CC=4 SCAR=30.0
2189 0 my $stack = shift;
2190  
2191 0 my $val = pop @$stack;
2192 0 my $n = pop @$stack;
2193 0 ▶ die "j(n,x): missing argument\n" if (!defined($n) || !defined($val));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and defined $val 0 0 0
Condition0%0/3
defined $n and defined $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $n and defined $val
defined $n defined $val
Truth table0%0/3
A and B
A= defined $nB= defined $val
ABresult
0X0
100
111
2194 0 my $bignum = ref $val;
2195 0 ▶ $val = $val->numify() if $bignum;
Branch: 1 branch
BranchTrueFalseTotal
if $bignum 0 0 0
2196 0 return POSIX::jn($n, $val);
2197 }
2198  
2199 # Initialize the symbol table
2200 sub init_table
2201 67 ▶{
Subroutine init_table: called CC=2 SCAR=8.5
2202 67 $sym_table{'scale'} = { type => 'var', value => 0};
2203 67 $sym_table{'ibase'} = { type => 'var', value => 0};
2204 67 $sym_table{'obase'} = { type => 'var', value => 0};
2205 67 $sym_table{'last'} = { type => 'var', value => 0};
2206  
2207 67 register_builtin('length', \&bi_length);
2208 67 register_builtin('scale', \&bi_scale);
2209 67 register_builtin('sqrt', \&bi_sqrt);
2210 67 ▶ if ($mathlib) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mathlib) 0 67 67
2211 0 register_builtin('a', \&bi_a);
2212 0 register_builtin('c', \&bi_c);
2213 0 register_builtin('e', \&bi_e);
2214 0 register_builtin('j', \&bi_j);
2215 0 register_builtin('l', \&bi_l);
2216 0 register_builtin('s', \&bi_s);
2217 }
2218 }
2219  
2220 201 ▶sub register_builtin {
Subroutine register_builtin: called CC=2 SCAR=7.1
2221 201 my $name = shift;
2222 201 my $func = shift;
2223  
2224 201 $name .= '()';
2225 201 ▶ if (exists $sym_table{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sym_table{$name}) 0 201 201
2226 0 die "conflicting builtin: $name\n";
2227 }
2228 201 $sym_table{$name} = { 'type' => 'builtin', 'value' => $func };
2229 201 return;
2230 }
2231  
2232 #
2233 # Pseudo-code
2234 #
2235  
2236 # Compilation time: a stack of statements is maintained. Each statement
2237 # is itself a stack of instructions.
2238 # Each instruction is appended to the statement which is on the top.
2239 # When a sub-block (IF, DEFINE...) is encountered, a
2240 # new, empty statement is pushed onto the stack, and it receives the
2241 # instructions in the sub-block.
2242  
2243 67 my $cur_stmt;
2244  
2245  
2246 # Pushes one instruction onto the current statement
2247 # First element is the type, others are 0 or more arguments, depending on
2248 # the type.
2249 sub push_instr
2250 474 ▶{
Subroutine push_instr: called CC=2 SCAR=7.1
2251 474 ▶ die "Internal error: no cur stmt" unless($cur_stmt);
Branch: 1 branch
BranchTrueFalseTotal
unless $cur_stmt 0 474 474
2252 474 my @args = @_;
2253 474 push(@$cur_stmt, [ @args ]);
2254 }
2255  
2256 # Pushes a new statement onto the stack of statements, and makes it the
2257 # current
2258 sub start_stmt
2259 243 ▶{
Subroutine start_stmt: called CC=1 SCAR=0.0
2260 243 $cur_stmt = [];
2261 243 push(@stmt_list, $cur_stmt);
2262 }
2263  
2264 # Closes a statement, and returns a reference on it.
2265 sub finish_stmt
2266 57 ▶{
Subroutine finish_stmt: called CC=1 SCAR=0.0
2267 57 my $stmt = pop @stmt_list;
2268 57 $cur_stmt = $stmt_list[$#stmt_list];
2269 57 return $stmt;
2270 }
2271  
2272 67 my ($res, $val);
2273  
2274 #
2275 # exec_stmt
2276 # Really executes a statement. Calls itself recursively when it
2277 # encounters sub-statements (in block, loops, functions...)
2278 #
2279 sub exec_stmt
2280 239 ▶{
Subroutine exec_stmt: called CC=111 SCAR=63.3
2281 239 my $stmt = shift;
2282  
2283 239 my $return = 0; # 1 if a "return" statement is encountered
2284  
2285 239 my @stmt_s = @$stmt;
2286 # print STDERR "ko\n";"executing statement: ".Dumper(\@stmt_s);
2287  
2288  
2289 # Each instruction in the stack is an array which first element gives
2290 # the type. Others elements may contain references to sub-statements
2291  
2292 239 my $instr;
2293  
2294 239 ▶ INSTR: while (defined($instr = shift @stmt_s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($instr = shift @stmt_s)) 688 231 919
2295  
2296 688 $_ = $instr->[0];
2297  
2298 688 ▶ print STDERR ("instruction: ".join(', ', @$instr)."\n" ) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 688 688
2299  
2300 # remove the stack top value, and forget about it
2301 688 ▶ if($_ eq ',') {
Branch: 23 branches
BranchTrueFalseTotal
if ($_ eq ',') { } 53 635 688
elsif ($_ eq 'N') { } 152 483 635
elsif ($_ eq '+_' or $_ eq '-_' or $_ eq '*_' or $_ eq '/_' or $_ eq '^_' or $_ eq '%_' or $_ eq '==_' or $_ eq '!=_' or $_ eq '>_' or $_ eq '>=_' or $_ eq '<_' or $_ eq '<=_' or $_ eq '<<_' or $_ eq '>>_' or $_ eq '||_' or $_ eq '&&_') { } 87 396 483
elsif ($_ eq 'm_') { } 5 391 396
elsif ($_ eq '!_') { } 2 389 391
elsif ($_ eq 'V') { } 81 308 389
elsif ($_ eq 'P') { } 0 308 308
elsif ($_ eq 'v') { } 122 186 308
elsif ($_ eq 'p') { } 0 186 186
elsif ($_ eq '=V') { } 81 105 186
elsif ($_ eq '=P') { } 0 105 105
elsif ($_ eq 'IF') { } 4 101 105
elsif ($_ eq 'FOR-COND') { } 3 98 101
elsif ($_ eq 'FUNCTION-CALL') { } 6 92 98
elsif ($_ eq 'a' or $_ eq 'A') { } 0 92 92
elsif ($_ eq '{}') { } 15 77 92
elsif ($_ eq 'STMT') { } 21 56 77
elsif ($_ eq 'RETURN') { } 0 56 56
elsif ($_ eq 'BREAK') { } 1 55 56
elsif ($_ eq 'PRINT') { } 21 34 55
elsif ($_ eq 'PRINT-STMT') { } 24 10 34
elsif ($_ eq 'FUNCTION-DEF') { } 0 10 10
elsif ($_ eq 'S') { } 10 0 10
2302 53 $res = pop @ope_stack;
2303 53 next INSTR;
2304  
2305 } elsif($_ eq 'N') {
2306  
2307 # N for number
2308 152 push(@ope_stack, 0 + $instr->[1]);
2309 152 next INSTR;
2310  
2311 ▶ } elsif($_ eq '+_' or $_ eq '-_' or $_ eq '*_' or $_ eq '/_' or
Condition95%43/45
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_" or $_ eq "<=_" or $_ eq "<<_" or $_ eq ">>_" or $_ eq "||_" or $_ eq "&&_"
l!l&&r!l&&!r
834396
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_" or $_ eq "<=_" or $_ eq "<<_" or $_ eq ">>_" or $_ eq "||_"
l!l&&r!l&&!r
794400
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_" or $_ eq "<=_" or $_ eq "<<_" or $_ eq ">>_"
l!l&&r!l&&!r
790404
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_" or $_ eq "<=_" or $_ eq "<<_"
l!l&&r!l&&!r
790404
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_" or $_ eq "<=_"
l!l&&r!l&&!r
781404
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_"
l!l&&r!l&&!r
6513405
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_"
l!l&&r!l&&!r
632418
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_"
l!l&&r!l&&!r
585420
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_"
l!l&&r!l&&!r
562425
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_"
l!l&&r!l&&!r
542427
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_"
l!l&&r!l&&!r
477429
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_"
l!l&&r!l&&!r
398436
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_"
l!l&&r!l&&!r
354444
$_ eq "+_" or $_ eq "-_" or $_ eq "*_"
l!l&&r!l&&!r
296448
$_ eq "+_" or $_ eq "-_"
l!l&&r!l&&!r
1910454
MC/DC87%14/16
$_ eq "+_" or $_ eq "-_" or $_ eq "*_" or $_ eq "/_" or $_ eq "^_" or $_ eq "%_" or $_ eq "==_" or $_ eq "!=_" or $_ eq ">_" or $_ eq ">=_" or $_ eq "<_" or $_ eq "<=_" or $_ eq "<<_" or $_ eq ">>_" or $_ eq "||_" or $_ eq "&&_"
$_ eq "+_" $_ eq "-_" $_ eq "*_" $_ eq "/_" $_ eq "^_" $_ eq "%_" $_ eq "==_" $_ eq "!=_" $_ eq ">_" $_ eq ">=_" $_ eq "<_" $_ eq "<=_" $_ eq "<<_" $_ eq ">>_" $_ eq "||_" $_ eq "&&_"
Truth table88%15/17
A or B or C or D or E or F or G or H or I or J or K or L or M or N or O or P
A= $_ eq "+_"B= $_ eq "-_"C= $_ eq "*_"D= $_ eq "/_"E= $_ eq "^_"F= $_ eq "%_"G= $_ eq "==_"H= $_ eq "!=_"I= $_ eq ">_"J= $_ eq ">=_"K= $_ eq "<_"L= $_ eq "<=_"M= $_ eq "<<_"N= $_ eq ">>_"O= $_ eq "||_"P= $_ eq "&&_"
ABCDEFGHIJKLMNOPresult
1XXXXXXXXXXXXXXX1
01XXXXXXXXXXXXXX1
001XXXXXXXXXXXXX1
0001XXXXXXXXXXXX1
00001XXXXXXXXXXX1
000001XXXXXXXXXX1
0000001XXXXXXXXX1
00000001XXXXXXXX1
000000001XXXXXXX1
0000000001XXXXXX1
00000000001XXXXX1
000000000001XXXX1
0000000000001XXX1
00000000000001XX1
000000000000001X1
00000000000000011
00000000000000000
2312 $_ eq '^_' or $_ eq '%_' or $_ eq '==_' or $_ eq '!=_' or
2313 $_ eq '>_' or $_ eq '>=_' or $_ eq '<_' or $_ eq '<=_' or
2314 $_ eq '<<_' or $_ eq '>>_' or $_ eq '||_' or $_ eq '&&_') {
2315  
2316 # Binary operators
2317 87 my $b = pop(@ope_stack); my $a = pop(@ope_stack);
2318  
2319 87 ▶ if ($_ eq '+_') { $res = $a + $b ; 1 }
Branch: 16 branches
BranchTrueFalseTotal
if ($_ eq '+_') { } 19 68 87
elsif ($_ eq '-_') { } 10 58 68
elsif ($_ eq '*_') { } 6 52 58
elsif ($_ eq '/_') { } 4 48 52
elsif ($_ eq '^_') { } 8 40 48
elsif ($_ eq '%_') { } 7 33 40
elsif ($_ eq '==_') { } 2 31 33
elsif ($_ eq '!=_') { } 2 29 31
elsif ($_ eq '>_') { } 5 24 29
elsif ($_ eq '>=_') { } 2 22 24
elsif ($_ eq '<_') { } 13 9 22
elsif ($_ eq '<=_') { } 1 8 9
elsif ($_ eq '<<_') { } 0 8 8
elsif ($_ eq '>>_') { } 0 8 8
elsif ($_ eq '||_') { } 4 4 8
elsif ($_ eq '&&_') { } 4 0 4
2320 10 elsif($_ eq '-_') { $res = $a - $b ; 1 }
2321 6 elsif($_ eq '*_') { $res = $a * $b ; 1 }
2322 4 ▶ elsif($_ eq '/_') { die 'divide by 0' if ($bignum ? $b->is_zero : $b == 0); $res = $a / $b }
Branch: 2 branches
BranchTrueFalseTotal
if $bignum ? $b->is_zero : $b == 0 1 3 4
$bignum ? : 0 4 4
2323 8 elsif($_ eq '^_') { $res = $a ** $b ; 1 }
2324 7 ▶ elsif($_ eq '%_') { die 'modulo by 0' if ($bignum ? $b->is_zero : $b == 0); $res = $a % $b }
Branch: 2 branches
BranchTrueFalseTotal
if $bignum ? $b->is_zero : $b == 0 1 6 7
$bignum ? : 0 7 7
2325  
2326 2 elsif($_ eq '==_') { $res = 0 + ($a == $b) ; 1 }
2327 2 elsif($_ eq '!=_') { $res = 0 + ($a != $b) ; 1 }
2328 5 elsif($_ eq '>_') { $res = 0 + ($a > $b) ; 1 }
2329 2 elsif($_ eq '>=_') { $res = 0 + ($a >= $b) ; 1 }
2330 13 elsif($_ eq '<_') { $res = 0 + ($a < $b) ; 1 }
2331 1 elsif($_ eq '<=_') { $res = 0 + ($a <= $b) ; 1 }
2332  
2333 0 elsif($_ eq '<<_') { $res = ($a << $b) ; 1 }
2334 0 elsif($_ eq '>>_') { $res = ($a >> $b) ; 1 }
2335  
2336 4 ▶ elsif($_ eq '||_') { $res = ($a || $b) ? 1 : 0 ; 1 }
Branch: 1 branch
BranchTrueFalseTotal
$a || $b ? : 3 1 4
Condition100%3/3
$a or $b
l!l&&r!l&&!r
211
MC/DC100%2/2
$a or $b
$a $b
Truth table100%3/3
A or B
A= $aB= $b
ABresult
1X1
011
000
2337 4 ▶ elsif($_ eq '&&_') { $res = ($a && $b) ? 1 : 0 ; 1 }
Branch: 1 branch
BranchTrueFalseTotal
$a && $b ? : 1 3 4
Condition100%3/3
$a and $b
!ll&&!rl&&r
211
MC/DC100%2/2
$a and $b
$a $b
Truth table100%3/3
A and B
A= $aB= $b
ABresult
0X0
100
111
2338  
2339 ;
2340  
2341 84 push(@ope_stack, $res);
2342 84 next INSTR;
2343  
2344  
2345 # Unary operators
2346  
2347 } elsif($_ eq 'm_') {
2348  
2349 5 $res = pop(@ope_stack);
2350 5 push(@ope_stack, -$res);
2351 5 next INSTR;
2352  
2353 } elsif($_ eq '!_') {
2354  
2355 2 $res = pop(@ope_stack);
2356 2 push(@ope_stack, 0+!$res);
2357 2 next INSTR;
2358  
2359 } elsif($_ eq 'V') {
2360  
2361 # Variable or array identifier
2362 81 push(@ope_stack, $instr->[1]);
2363 81 next INSTR;
2364  
2365 } elsif($_ eq 'P') {
2366 0 my $index = splice @ope_stack, -2, 1; # rval remains top of stack
2367 0 $index = floor_idx($index);
2368 0 ▶ if ($index == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index == -1) 0 0 0
2369 0 print STDERR "Non-integer index $index for array\n";
2370 0 $return = 3;
2371 0 @ope_stack = ();
2372 0 @stmt_list=();
2373 0 last INSTR;
2374 }
2375 0 push @ope_stack, $instr->[1] . '[]' . $index;
2376 0 next INSTR;
2377  
2378 } elsif($_ eq 'v') {
2379  
2380 # Variable value : initialized to 0
2381 # '*' is reserved for internal variables
2382  
2383 122 my $name = $instr->[1];
2384 122 ▶ unless (defined($sym_table{$name})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sym_table{$name} and $sym_table{$name}{"type"} eq "var") 0 122 122
Condition33%1/3
defined $sym_table{$name} and $sym_table{$name}{"type"} eq "var"
!ll&&!rl&&r
00122
MC/DC0%0/2
defined $sym_table{$name} and $sym_table{$name}{"type"} eq "var"
defined $sym_table{$name} $sym_table{$name}{"type"} eq "var"
Truth table33%1/3
A and B
A= defined $sym_table{$name}B= $sym_table{$name}{"type"} eq "var"
ABresult
0X0
100
111
2385 and $sym_table{$name}{'type'} eq 'var') {
2386 0 $sym_table{$name}{'value'} = 0;
2387 0 $sym_table{$name}{'type'} = 'var';
2388 }
2389 122 push(@ope_stack, $sym_table{$name}{'value'});
2390 122 next INSTR;
2391  
2392 } elsif($_ eq 'p') {
2393  
2394 # Array value : initialized to 0
2395 0 my ($name, $idx) = ($instr->[1], pop(@ope_stack));
2396 0 $idx = floor_idx($idx);
2397 0 ▶ if ($idx == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx == -1) 0 0 0
2398 0 print STDERR "Non-integer index $idx for array\n";
2399 0 $return = 3;
2400 0 @ope_stack = ();
2401 0 @stmt_list=();
2402 0 last INSTR;
2403 }
2404  
2405 # debug {"p: $name, $idx.\n"};
2406 0 $name .= '[]';
2407 0 ▶ unless (defined($sym_table{$name})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sym_table{$name} and $sym_table{$name}{"type"} eq "array") 0 0 0
Condition0%0/3
defined $sym_table{$name} and $sym_table{$name}{"type"} eq "array"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sym_table{$name} and $sym_table{$name}{"type"} eq "array"
defined $sym_table{$name} $sym_table{$name}{"type"} eq "array"
Truth table0%0/3
A and B
A= defined $sym_table{$name}B= $sym_table{$name}{"type"} eq "array"
ABresult
0X0
100
111
2408 and $sym_table{$name}{'type'} eq 'array') {
2409  
2410 0 $sym_table{$name} = { type => 'array'};
2411 }
2412 0 ▶ unless ($sym_table{$name}{'value'}[$idx]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sym_table{$name}{"value"}[$idx]) 0 0 0
2413 0 $sym_table{$name}{'value'}[$idx] = { type => 'var',
2414 value => 0 };
2415 }
2416 0 push(@ope_stack, $sym_table{$name}{'value'}[$idx]{'value'});
2417 0 next INSTR;
2418  
2419 } elsif($_ eq '=V') {
2420  
2421 # Attribution of a value to a variable
2422 # ope_stack ends with a NUMBER and an IDENTIFIER
2423 81 my $varName = pop(@ope_stack);
2424 81 my $value = pop(@ope_stack);
2425 81 $sym_table{$varName} = { type => 'var',
2426 value => $value };
2427 81 push(@ope_stack, $value);
2428 81 $return = 3; # do not print result
2429 81 next INSTR;
2430  
2431 } elsif($_ eq '=P') {
2432  
2433 0 my $varName = pop(@ope_stack);
2434 0 my $value = pop(@ope_stack);
2435 0 my ($name, $idx) = split /\[\]/, $varName, 2;
2436 0 $name .= '[]';
2437 0 ▶ unless (defined($sym_table{$name})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sym_table{$name} and $sym_table{$name}{"type"} eq "array") 0 0 0
Condition0%0/3
defined $sym_table{$name} and $sym_table{$name}{"type"} eq "array"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sym_table{$name} and $sym_table{$name}{"type"} eq "array"
defined $sym_table{$name} $sym_table{$name}{"type"} eq "array"
Truth table0%0/3
A and B
A= defined $sym_table{$name}B= $sym_table{$name}{"type"} eq "array"
ABresult
0X0
100
111
2438 and $sym_table{$name}{'type'} eq 'array')
2439 {
2440 0 $sym_table{$name} = { type => 'array',
2441 value => [] };
2442 }
2443 0 $sym_table{$name}{'value'}[$idx] = { type => 'var',
2444 value => $value };
2445 0 push(@ope_stack, $value);
2446 0 $return = 3; # do not print result
2447 0 next INSTR;
2448  
2449 } elsif($_ eq 'IF') {
2450 # IF statement
2451  
2452 4 my $cond = pop @ope_stack;
2453 4 ▶ if($cond) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond) { } 1 3 4
2454 1 ($return, $val) = exec_stmt($instr->[1]);
2455 1 ▶ push(@ope_stack, $val), last INSTR if $return;
Branch: 1 branch
BranchTrueFalseTotal
if $return 1 0 1
2456 } else {
2457 3 $val = undef;
2458 }
2459  
2460 # debug {"IF: $val.\n"};
2461 3 push(@ope_stack, $val);
2462 # debug {"IF: ope_stack=".Dumper(\@ope_stack)};
2463 3 next INSTR;
2464  
2465 } elsif($_ eq 'FOR-COND') {
2466 # WHILE and FOR statement
2467  
2468 # debug {"while-cond: stmt_s=".Dumper(\@stmt_s)};
2469  
2470 3 my $i_cond = $instr;
2471 3 my $i_incr = shift @stmt_s;
2472 3 my $i_body = shift @stmt_s;
2473  
2474 3 $val = 1;
2475  
2476 # debug { "cond: ".Dumper($i_cond) };
2477  
2478 3 LOOP: while(1) {
2479  
2480 16 @ope_stack=();
2481 16 ▶ if($#{ $i_cond->[1] } >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$i_cond[1];} >= 0) 16 0 16
2482 16 ($return, $val) = exec_stmt($i_cond->[1]);
2483 # debug {"results of cond: $return, $val"};
2484 16 ▶ push(@ope_stack, $val), last INSTR
Branch: 1 branch
BranchTrueFalseTotal
if $return == 1 or $return == 2 0 16 16
Condition33%1/3
$return == 1 or $return == 2
l!l&&r!l&&!r
0016
MC/DC0%0/2
$return == 1 or $return == 2
$return == 1 $return == 2
Truth table33%1/3
A or B
A= $return == 1B= $return == 2
ABresult
1X1
011
000
2485 if($return == 1 or $return == 2);
2486 16 ▶ last LOOP if $val == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $val == 0 2 14 16
2487 }
2488  
2489 # debug {"while: executing a body\n"};
2490  
2491 14 ▶ if($#{ $i_body->[1] } >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$i_body[1];} >= 0) 14 0 14
2492 14 ($return, $val) = exec_stmt($i_body->[1]);
2493 14 push(@ope_stack, $val);
2494  
2495 14 ▶ if($return == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($return == 1) { } 1 13 14
elsif ($return == 2) { } 0 13 13
2496 1 last INSTR;
2497 } elsif($return == 2) {
2498 0 $return = 0 ;
2499 0 last INSTR;
2500 }
2501 }
2502  
2503 13 ▶ if($#{ $i_incr->[1] } >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$i_incr[1];} >= 0) 8 5 13
2504 # debug {"for: executing the increment: ".Dumper($i_incr)};
2505 8 @ope_stack = ();
2506 8 ($return, $val) = exec_stmt($i_incr->[1]);
2507 8 push(@ope_stack, $val);
2508 8 ▶ last INSTR if($return == 1 or $return == 2);
Branch: 1 branch
BranchTrueFalseTotal
if $return == 1 or $return == 2 0 8 8
Condition33%1/3
$return == 1 or $return == 2
l!l&&r!l&&!r
008
MC/DC0%0/2
$return == 1 or $return == 2
$return == 1 $return == 2
Truth table33%1/3
A or B
A= $return == 1B= $return == 2
ABresult
1X1
011
000
2509 }
2510  
2511 }
2512 2 $return = 3;
2513 2 push(@ope_stack, 1); # whatever
2514 2 next INSTR;
2515  
2516 } elsif($_ eq 'FUNCTION-CALL') {
2517  
2518 # Function call
2519 6 push @backup_sym_table, undef; # Hmmm...
2520  
2521 6 my $name = $instr->[1];
2522 6 $name .= '()';
2523  
2524 6 ▶ unless($sym_table{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sym_table{$name}) 0 6 6
2525 0 print STDERR "No function $name has been defined\n";
2526 0 @ope_stack = (0);
2527 0 $return = 3;
2528 0 last INSTR;
2529 }
2530  
2531 6 ▶ if($sym_table{$name}{type} eq 'builtin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym_table{$name}{'type'} eq 'builtin') { } 6 0 6
2532 ($return, $val) =
2533 6 (1, &{ $sym_table{$name}{value} }(\@ope_stack));
2534 } else {
2535 0 ($return, $val) = exec_stmt($sym_table{$name}{'value'});
2536  
2537 # Restore the symbols temporarily pushed in 'a' and 'A' instructions
2538 0 ▶ debug {"restoring backup: ".Dumper(\@backup_sym_table)};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2539  
2540 # pop @backup_sym_table; # The first is undef
2541 0 ▶ while($var = pop @backup_sym_table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var = pop @backup_sym_table) 0 0 0
2542 0 ▶ debug {"restoring var: ".Dumper($var)};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2543 0 ▶ if($var->{'type'} eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->{'type'} eq 'undef') { } 0 0 0
2544 0 delete $sym_table{$var->{'name'}};;
2545 } else {
2546 0 $sym_table{$var->{'name'}} = $var->{'entry'};
2547 }
2548 }
2549  
2550 # push @backup_sym_table, undef;
2551 }
2552  
2553 # debug {"result from function $name: $return, $val.\n"};
2554 6 push(@ope_stack, $val);
2555  
2556 6 ▶ if($return == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($return == 1) { } 6 0 6
elsif ($return == 2) { } 0 0 0
elsif ($return == 3) { } 0 0 0
2557 6 $return = 0; # so the result will be printed
2558 } elsif($return == 2) {
2559 0 print STDERR "No enclosing while or for";
2560 0 yy_err_recover();
2561 } elsif($return == 3) {
2562 0 $return = 0;
2563 }
2564 6 next INSTR;
2565  
2566 ▶ } elsif($_ eq 'a' or $_ eq 'A') {
Condition33%1/3
$_ eq "a" or $_ eq "A"
l!l&&r!l&&!r
0092
MC/DC0%0/2
$_ eq "a" or $_ eq "A"
$_ eq "a" $_ eq "A"
Truth table33%1/3
A or B
A= $_ eq "a"B= $_ eq "A"
ABresult
1X1
011
000
2567  
2568 # Function arguments and auto list declaration
2569 # The difference is that function arguments are initialized from the
2570 # operation stack, while auto variables are initialized to zero
2571 0 my ($where, $name) = ($_, $instr->[1]);
2572  
2573 0 ▶ if(defined $sym_table{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sym_table{$name}) { } 0 0 0
2574 0 ▶ debug { "backup $name, $sym_table{$name}\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2575 push @backup_sym_table, { name => $name,
2576 0 entry => $sym_table{$name} };
2577 } else {
2578 0 ▶ debug { "backup $name, undef \n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2579 0 push @backup_sym_table, { name => $name,
2580 type => 'undef' };
2581 }
2582 0 ▶ $sym_table{$name} = { type => 'var',
Branch: 1 branch
BranchTrueFalseTotal
$where eq 'a' ? : 0 0 0
2583 value => ($where eq 'a' ?
2584 shift(@ope_stack) : 0) };
2585  
2586 # debug { "new entry $name in sym table: $sym_table{$name}{'value'}" };
2587 0 next INSTR;
2588  
2589 } elsif($_ eq '{}') {
2590  
2591 # Grouped statements
2592 15 ▶ if(scalar @{ $instr->[1] } > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$instr->[1];} > 0) { } 15 0 15
2593 15 ($return, $val) = exec_stmt($instr->[1]);
2594 } else {
2595 0 ($return, $val) = (0, 0);
2596 }
2597  
2598 15 ▶ push(@ope_stack, $val), last INSTR
Branch: 1 branch
BranchTrueFalseTotal
if $return eq 1 or $return eq 2 1 14 15
Condition66%2/3
$return eq 1 or $return eq 2
l!l&&r!l&&!r
1014
MC/DC50%1/2
$return eq 1 or $return eq 2
$return eq 1 $return eq 2
Truth table66%2/3
A or B
A= $return eq 1B= $return eq 2
ABresult
1X1
011
000
2599 if($return eq 1 or $return eq 2);
2600  
2601 14 $return = 3;
2602 14 push(@ope_stack, $val);
2603 14 next INSTR;
2604  
2605 } elsif($_ eq 'STMT') {
2606  
2607 21 @ope_stack=();
2608 21 ▶ if(scalar $instr->[1] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $instr->[1] > 0) { } 21 0 21
2609 21 ($return, $val) = exec_stmt($instr->[1]);
2610 } else {
2611 0 ($return, $val) = (3, undef);
2612 }
2613  
2614 21 ▶ @ope_stack = ($val), last INSTR
Branch: 1 branch
BranchTrueFalseTotal
if $return eq 1 or $return eq 2 1 20 21
Condition66%2/3
$return eq 1 or $return eq 2
l!l&&r!l&&!r
1020
MC/DC50%1/2
$return eq 1 or $return eq 2
$return eq 1 $return eq 2
Truth table66%2/3
A or B
A= $return eq 1B= $return eq 2
ABresult
1X1
011
000
2615 if($return eq 1 or $return eq 2);
2616  
2617 20 $return = 3;
2618 20 @ope_stack = ($val);
2619  
2620 20 next INSTR;
2621  
2622 } elsif($_ eq 'RETURN') {
2623 # Return statement
2624  
2625 # debug {"returning $instr->[1].\n"};
2626 0 ▶ my $value = ($instr->[1] == 0) ? 0
Branch: 1 branch
BranchTrueFalseTotal
$instr->[1] == 0 ? : 0 0 0
2627 : pop(@ope_stack);
2628  
2629 0 $return = 1;
2630 0 @ope_stack = ($value);
2631  
2632 0 last INSTR;
2633  
2634 } elsif($_ eq 'BREAK') {
2635 # Break statement
2636  
2637 # debug {"breaking.\n"};
2638  
2639 1 $return = 1;
2640 1 push(@ope_stack, 0);
2641  
2642 1 last INSTR;
2643  
2644 } elsif($_ eq 'PRINT') {
2645 # PRINT statement
2646  
2647 21 ▶ if(scalar @{ $instr->[1] } > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$instr->[1];} > 0) { } 21 0 21
2648 21 ($return, $val) = exec_stmt($instr->[1]);
2649 } else {
2650 0 ($return, $val) = (0, 0);
2651 }
2652  
2653 21 ▶ push(@ope_stack, $val), last INSTR
Branch: 1 branch
BranchTrueFalseTotal
if $return eq 1 or $return eq 2 0 21 21
Condition33%1/3
$return eq 1 or $return eq 2
l!l&&r!l&&!r
0021
MC/DC0%0/2
$return eq 1 or $return eq 2
$return eq 1 $return eq 2
Truth table33%1/3
A or B
A= $return eq 1B= $return eq 2
ABresult
1X1
011
000
2654 if($return eq 1 or $return eq 2);
2655  
2656 21 $return = 3;
2657 21 next INSTR;
2658  
2659 } elsif($_ eq 'PRINT-STMT') {
2660  
2661 24 @ope_stack=();
2662 24 ▶ if(scalar $instr->[1] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $instr->[1] > 0) { } 24 0 24
2663 24 ($return, $val) = exec_stmt($instr->[1]);
2664 } else {
2665 0 ($return, $val) = (3, undef);
2666 }
2667  
2668 24 ▶ last INSTR if($return eq 1 or $return eq 2);
Branch: 1 branch
BranchTrueFalseTotal
if $return eq 1 or $return eq 2 0 24 24
Condition33%1/3
$return eq 1 or $return eq 2
l!l&&r!l&&!r
0024
MC/DC0%0/2
$return eq 1 or $return eq 2
$return eq 1 $return eq 2
Truth table33%1/3
A or B
A= $return eq 1B= $return eq 2
ABresult
1X1
011
000
2669  
2670 24 $return = 3;
2671  
2672 24 print $val;
2673 24 next INSTR;
2674  
2675 } elsif($_ eq 'FUNCTION-DEF') {
2676  
2677 # Function definition
2678 0 my ($name, $code) = ($instr->[1], $instr->[2]);
2679 0 push(@$code, ["RETURN", 0]);
2680 0 $sym_table{$name.'()'} = { type => 'func',
2681 value => $code };
2682 0 $return = 3;
2683 0 push(@ope_stack, 1); # whatever
2684 0 next INSTR;
2685  
2686 } elsif($_ eq 'S') {
2687  
2688 # S for string
2689 10 $_ = $instr->[1];
2690 10 s/ \\a /\a/gx;
2691 10 s/ \\b /\b/gx;
2692 10 s/ \\f /\f/gx;
2693 10 s/ \\n /\n/gx;
2694 10 s/ \\r /\r/gx;
2695 10 s/ \\t /\t/gx;
2696 10 s/ \\q /"/gx; # "
2697 10 s/ \\\\ /\\/gx;
2698 10 push(@ope_stack, $_);
2699 10 next INSTR;
2700  
2701 } else {
2702  
2703 0 die "internal error: illegal statement $_";
2704  
2705 }
2706  
2707 }
2708  
2709 236 ▶ if ($return == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return == 3) { } 135 101 236
2710 135 @ope_stack = ();
2711 } else {
2712 101 ▶ if(scalar @ope_stack != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ope_stack != 1) 0 101 101
2713 0 die("internal error: ope_stack = ".join(", ", @ope_stack).".\n");
2714 }
2715  
2716 101 $val = pop(@ope_stack);
2717 # debug {"Returning ($return, $val)\n"};
2718 # debug {"ope_stack at e-o-func: ".Dumper(\@ope_stack)};
2719 }
2720  
2721 236 return ($return, $val);
2722  
2723 }
2724  
2725 0 ▶sub floor_idx {
Subroutine floor_idx: not called CC=2 SCAR=17.9
2726 0 my $idx = shift;
2727 0 ▶ if ($idx =~ m/\A([0-9]+)\.?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx =~ /\A([0-9]+)\.?/) 0 0 0
2728 0 return $1;
2729 }
2730 0 return -1;
2731 }
2732  
2733 sub main
2734 67 ▶{
Subroutine main: called CC=3 SCAR=11.0
2735 67 my $status;
2736 67 while(1)
2737 {
2738 70 $line = '';
2739 eval {
2740 70 clear_flags();
2741 70 $status = yyparse();
2742 67 1;
2743 70 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { clear_flags(); $status = yyparse(); 1 } } or do { yyerror($@) } 67 3 70
2744 3 yyerror($@);
2745 };
2746  
2747 70 ▶ exit $status if ! $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 67 3 70
2748 }
2749 }
2750  
2751 67 select(STDERR);
2752 67 $| = 1;
2753 67 select(STDOUT);
2754  
2755 67 command_line();
2756 67 init_table();
2757 67 next_file();
2758 67 start_stmt();
2759 67 main();
2760  
2761 __END__
« blib/lib/PerlPowerTools/SymbolicMode.pm ↑ Summary bin/ls »