summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/bc
diff options
context:
space:
mode:
authorsteve <steve@FreeBSD.org>1996-11-04 03:55:26 +0000
committersteve <steve@FreeBSD.org>1996-11-04 03:55:26 +0000
commitef6f1644ef0f9d0b3a17f8e271db61d6a070036d (patch)
tree1b79ec214b19b142c034cafd7e968b29acd0e8d4 /gnu/usr.bin/bc
parent881f1465638d683d72a9e960e03dfd5a14436652 (diff)
downloadFreeBSD-src-ef6f1644ef0f9d0b3a17f8e271db61d6a070036d.zip
FreeBSD-src-ef6f1644ef0f9d0b3a17f8e271db61d6a070036d.tar.gz
Upgrade to version 1.03.
Diffstat (limited to 'gnu/usr.bin/bc')
-rw-r--r--gnu/usr.bin/bc/Makefile8
-rw-r--r--gnu/usr.bin/bc/bc.127
-rw-r--r--gnu/usr.bin/bc/bc.c1369
-rw-r--r--gnu/usr.bin/bc/bc.y615
-rw-r--r--gnu/usr.bin/bc/bcdefs.h2
-rw-r--r--gnu/usr.bin/bc/const.h12
-rw-r--r--gnu/usr.bin/bc/execute.c10
-rw-r--r--gnu/usr.bin/bc/global.c2
-rw-r--r--gnu/usr.bin/bc/global.h27
-rw-r--r--gnu/usr.bin/bc/libmath.b255
-rw-r--r--gnu/usr.bin/bc/load.c2
-rw-r--r--gnu/usr.bin/bc/main.c2
-rw-r--r--gnu/usr.bin/bc/math.h74
-rw-r--r--gnu/usr.bin/bc/number.c34
-rw-r--r--gnu/usr.bin/bc/number.h2
-rw-r--r--gnu/usr.bin/bc/proto.h5
-rw-r--r--gnu/usr.bin/bc/scan.c1368
-rw-r--r--gnu/usr.bin/bc/scan.l196
-rw-r--r--gnu/usr.bin/bc/storage.c10
-rw-r--r--gnu/usr.bin/bc/util.c48
-rw-r--r--gnu/usr.bin/bc/version.h2
-rw-r--r--gnu/usr.bin/bc/y.tab.h40
22 files changed, 976 insertions, 3134 deletions
diff --git a/gnu/usr.bin/bc/Makefile b/gnu/usr.bin/bc/Makefile
index fac7437..dd11698 100644
--- a/gnu/usr.bin/bc/Makefile
+++ b/gnu/usr.bin/bc/Makefile
@@ -1,6 +1,10 @@
PROG= bc
-SRCS= bc.c global.c scan.c util.c main.c number.c storage.c load.c execute.c
-MAN1= bc.1
+
+BCSRCS= execute.c global.c load.c main.c number.c storage.c util.c
+GENSRCS= bc.c scan.c
+SRCS= ${GENSRCS} ${BCSRCS}
+
CFLAGS+= -D_POSIX_SOURCE -I$(.CURDIR)
+CLEANFILES+= ${GENSRCS} y.tab.h
.include <bsd.prog.mk>
diff --git a/gnu/usr.bin/bc/bc.1 b/gnu/usr.bin/bc/bc.1
index b1f50ca..87aab4d 100644
--- a/gnu/usr.bin/bc/bc.1
+++ b/gnu/usr.bin/bc/bc.1
@@ -1,8 +1,8 @@
.\"
.\" bc.1 - the *roff document processor source for the bc manual
.\"
-.\" This file is part of bc written for MINIX.
-.\" Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+.\" This file is part of bc written initially for MINIX.
+.\" Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
@@ -25,15 +25,15 @@
.\" Western Washington University
.\" Bellingham, WA 98226-9062
.\"
-.\" $Id$
+.\" $Id: bc.1,v 1.3 1996/10/05 22:26:19 wosch Exp $
.\"
-.TH bc 1 .\" "Command Manual" v1.02 "Feb 3, 1992"
+.TH bc 1 .\" "Command Manual" v1.03 "Nov 2, 1994"
.SH NAME
bc - An arbitrary precision calculator language
.SH SYNTAX
\fBbc\fR [ \fB-lws\fR ] [ \fI file ...\fR ]
.SH VERSION
-This man page documents GNU bc version 1.02.
+This man page documents GNU bc version 1.03.
.SH DESCRIPTION
\fBbc\fR is a language that supports arbitrary precision numbers
with interactive execution of statements. There are some similarities
@@ -317,7 +317,9 @@ last value printed without having to retype the expression that
printed the number. Assigning to \fBlast\fR is legal and will
overwrite the last printed value with the assigned value. The newly
assigned value will remain until the next number is printed or another
-value is assigned to \fBlast\fR.
+value is assigned to \fBlast\fR. (Some installations may allow the
+use of a single period (.) which is not part of a number as a short
+hand notation for for \fBlast\fR.)
.IP "string"
The string is printed to the output. Strings start with a double quote
character and contain all characters until the next double quote character.
@@ -332,10 +334,9 @@ value is printed and assigned the variable \fBlast\fR. Strings
in the print statement are printed to the output and may contain
special characters. Special characters start with the backslash
character (\e). The special characters recognized by \fBbc\fR are
-"b" (bell), "f" (form feed), "n" (newline), "r" (carriage return), "t"
-(tab), and "\e" (backslash). Any other character following the
-backslash will be ignored. This still does not allow the double quote
-character to be part of any string.
+"a" (alert or bell), "b" (backspace), "f" (form feed), "n" (newline),
+"r" (carriage return), "q" (double quote), "t" (tab), and "\e" (backslash).
+Any other character following the backslash will be ignored.
.IP "{ statement_list }"
This is the compound statement. It allows multiple statements to be
grouped together for execution.
@@ -702,9 +703,9 @@ The multiply routine may yield incorrect results if a number
has more than LONG_MAX / 90 total digits. For 32 bit longs, this number is
23,860,929 digits.
.IP "code size"
-Each function and the "main" program are limited to 10240 bytes of
+Each function and the "main" program are limited to 16384 bytes of
compiled byte code each. This limit (BC_MAX_SEGS) can be easily changed
-to have more than 10 segments of 1024 bytes.
+to have more than 16 segments of 1024 bytes.
.IP "variable names"
The current limit on the number of unique names is 32767 for each of
simple variables, arrays and functions.
@@ -726,6 +727,6 @@ Philip A. Nelson
phil@cs.wwu.edu
.fi
.SH ACKNOWLEDGEMENTS
-The author would like to thank Steve Sommars (sesv@iwtsf.att.com) for
+The author would like to thank Steve Sommars (Steve.Sommars@att.com) for
his extensive help in testing the implementation. Many great suggestions
were given. This is a much better product due to his involvement.
diff --git a/gnu/usr.bin/bc/bc.c b/gnu/usr.bin/bc/bc.c
deleted file mode 100644
index b6308d0..0000000
--- a/gnu/usr.bin/bc/bc.c
+++ /dev/null
@@ -1,1369 +0,0 @@
-#ifndef lint
-static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
-#endif
-#define YYBYACC 1
-#line 2 "bc.y"
-/* bc.y: The grammar for a POSIX compatable bc processor with some
- extensions to the language. */
-
-/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License , or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- You may contact the author by:
- e-mail: phil@cs.wwu.edu
- us-mail: Philip A. Nelson
- Computer Science Department, 9062
- Western Washington University
- Bellingham, WA 98226-9062
-
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "global.h"
-#include "proto.h"
-#line 38 "bc.y"
-typedef union {
- char *s_value;
- char c_value;
- int i_value;
- arg_list *a_value;
- } YYSTYPE;
-#line 46 "y.tab.c"
-#define NEWLINE 257
-#define AND 258
-#define OR 259
-#define NOT 260
-#define STRING 261
-#define NAME 262
-#define NUMBER 263
-#define MUL_OP 264
-#define ASSIGN_OP 265
-#define REL_OP 266
-#define INCR_DECR 267
-#define Define 268
-#define Break 269
-#define Quit 270
-#define Length 271
-#define Return 272
-#define For 273
-#define If 274
-#define While 275
-#define Sqrt 276
-#define Else 277
-#define Scale 278
-#define Ibase 279
-#define Obase 280
-#define Auto 281
-#define Read 282
-#define Warranty 283
-#define Halt 284
-#define Last 285
-#define Continue 286
-#define Print 287
-#define Limits 288
-#define UNARY_MINUS 289
-#define YYERRCODE 256
-short yylhs[] = { -1,
- 0, 0, 10, 10, 10, 11, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 15, 15, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 16, 17, 18,
- 19, 13, 20, 13, 22, 23, 13, 13, 25, 13,
- 24, 24, 26, 26, 21, 27, 21, 28, 14, 5,
- 5, 6, 6, 6, 7, 7, 7, 7, 8, 8,
- 9, 9, 9, 9, 4, 4, 2, 2, 29, 1,
- 30, 1, 31, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 3, 3, 3, 3, 3, 3,
-};
-short yylen[] = { 2,
- 0, 2, 2, 1, 2, 0, 1, 3, 2, 0,
- 1, 2, 3, 2, 3, 1, 2, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 4, 0, 0, 0,
- 0, 13, 0, 7, 0, 0, 7, 3, 0, 3,
- 1, 3, 1, 1, 0, 0, 3, 0, 12, 0,
- 1, 0, 3, 3, 1, 3, 3, 5, 0, 1,
- 1, 3, 3, 5, 0, 1, 0, 1, 0, 4,
- 0, 4, 0, 4, 2, 3, 3, 3, 3, 3,
- 2, 1, 1, 3, 4, 2, 2, 4, 4, 4,
- 3, 1, 4, 1, 1, 1, 1,
-};
-short yydefred[] = { 1,
- 0, 0, 0, 21, 0, 83, 0, 0, 22, 24,
- 0, 0, 28, 0, 35, 0, 0, 94, 95, 0,
- 18, 25, 97, 23, 39, 19, 0, 0, 0, 0,
- 0, 2, 0, 16, 4, 7, 5, 17, 0, 0,
- 0, 0, 96, 86, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 81, 0, 0, 0, 11, 71,
- 73, 0, 0, 0, 0, 0, 69, 87, 3, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 91, 43, 0, 40, 0, 84,
- 0, 0, 38, 0, 0, 0, 0, 0, 0, 0,
- 0, 8, 0, 85, 0, 93, 0, 0, 0, 88,
- 27, 0, 0, 33, 0, 89, 90, 0, 13, 15,
- 0, 0, 0, 62, 0, 0, 0, 0, 0, 29,
- 0, 0, 42, 0, 56, 0, 0, 0, 0, 0,
- 64, 0, 0, 0, 46, 34, 37, 0, 48, 58,
- 30, 0, 0, 0, 0, 47, 53, 54, 0, 0,
- 0, 31, 49, 0, 32,
-};
-short yydgoto[] = { 1,
- 30, 79, 31, 113, 108, 149, 109, 73, 74, 32,
- 33, 58, 34, 35, 59, 48, 138, 155, 164, 131,
- 146, 50, 132, 88, 54, 89, 152, 154, 101, 94,
- 95,
-};
-short yysindex[] = { 0,
- -7, 58, 212, 0, -22, 0, -233, -241, 0, 0,
- -8, -5, 0, -4, 0, 2, 4, 0, 0, 9,
- 0, 0, 0, 0, 0, 0, 212, 212, 91, 725,
- -240, 0, -29, 0, 0, 0, 0, 0, 84, 245,
- 212, -57, 0, 0, 10, 212, 212, 14, 212, 16,
- 212, 212, 23, 156, 0, 549, 127, -52, 0, 0,
- 0, 212, 212, 212, 212, 212, 0, 0, 0, 91,
- -17, 725, 24, -3, 578, -205, 562, 725, 27, 212,
- 606, 212, 669, 716, 0, 0, 725, 0, 19, 0,
- 91, 127, 0, 212, 212, -36, -39, -91, -91, -36,
- 212, 0, 166, 0, 277, 0, -21, 36, 40, 0,
- 0, 725, 28, 0, 725, 0, 0, 156, 0, 0,
- 84, 540, -39, 0, -9, 725, -2, -37, -174, 0,
- 127, 48, 0, 346, 0, -167, 3, 212, -185, 127,
- 0, -188, 6, 37, 0, 0, 0, -205, 0, 0,
- 0, 127, -42, 91, 212, 0, 0, 0, -20, 54,
- 26, 0, 0, 127, 0,
-};
-short yyrindex[] = { 0,
- -16, 0, 0, 0, 409, 0, 0, 0, 0, 0,
- 0, -58, 0, 0, 0, 0, 426, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, -50, 46,
- 470, 0, 0, 0, 0, 0, 0, 0, 661, 56,
- 0, 525, 0, 0, 0, 0, 59, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, -6,
- 705, 7, 0, 60, 0, 61, 0, 63, 0, 49,
- 0, 0, 0, 0, 0, 0, 17, 0, 78, 0,
- -47, -45, 0, 0, 0, 537, 440, 620, 637, 594,
- 0, 0, 0, 0, 0, 0, -33, 0, 66, 0,
- 0, -19, 0, 0, 68, 0, 0, 0, 0, 0,
- 667, 680, 508, 0, 705, 18, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, -31, 49, -44, 0,
- 0, -40, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 69, 0, 0, 0, 0, 0,
- 13, 0, 0, 0, 0,
-};
-short yygindex[] = { 0,
- 958, 0, 104, -118, 0, 0, -35, 0, 0, 0,
- 0, -34, 22, 0, 15, 0, 0, 0, 0, 0,
- 0, 0, 0, -1, 0, 0, 0, 0, 0, 0,
- 0,
-};
-#define YYTABLESIZE 1113
-short yytable[] = { 52,
- 26, 129, 66, 64, 52, 65, 92, 55, 10, 57,
- 55, 12, 57, 14, 45, 36, 158, 40, 52, 144,
- 45, 66, 40, 38, 67, 55, 68, 57, 42, 70,
- 40, 46, 28, 41, 47, 49, 160, 27, 92, 66,
- 105, 51, 6, 52, 43, 18, 19, 61, 53, 76,
- 61, 23, 9, 80, 66, 82, 107, 66, 63, 10,
- 44, 63, 118, 85, 104, 28, 26, 111, 41, 127,
- 27, 12, 93, 103, 10, 44, 128, 12, 38, 14,
- 45, 134, 52, 129, 102, 136, 130, 137, 140, 142,
- 135, 145, 148, 143, 162, 151, 59, 28, 150, 67,
- 60, 50, 27, 68, 20, 119, 51, 65, 36, 65,
- 44, 0, 153, 120, 0, 29, 133, 0, 0, 159,
- 0, 0, 0, 0, 0, 0, 64, 0, 65, 0,
- 28, 0, 0, 0, 0, 27, 41, 0, 0, 0,
- 0, 44, 0, 0, 0, 0, 0, 0, 29, 0,
- 163, 0, 139, 0, 0, 0, 0, 0, 0, 0,
- 0, 147, 0, 0, 0, 0, 28, 0, 0, 0,
- 20, 27, 62, 156, 0, 119, 0, 66, 0, 0,
- 29, 0, 0, 0, 0, 165, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 28, 0, 0, 26, 0,
- 27, 0, 41, 0, 91, 28, 10, 0, 0, 12,
- 27, 14, 45, 29, 157, 52, 52, 0, 26, 52,
- 52, 52, 52, 55, 62, 57, 52, 69, 52, 52,
- 52, 52, 52, 52, 52, 52, 161, 52, 52, 52,
- 6, 52, 52, 52, 52, 52, 52, 52, 2, 29,
- 9, 28, 3, 4, 5, 6, 27, 10, 124, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 12,
- 17, 18, 19, 44, 20, 21, 22, 23, 24, 25,
- 26, 57, 0, 0, 28, 3, 4, 5, 6, 27,
- 0, 0, 7, 44, 9, 10, 11, 12, 13, 14,
- 15, 16, 20, 17, 18, 19, 0, 20, 21, 22,
- 23, 24, 25, 26, 37, 0, 28, 3, 4, 5,
- 6, 27, 20, 0, 7, 0, 9, 10, 11, 12,
- 13, 14, 15, 16, 41, 17, 18, 19, 0, 20,
- 21, 22, 23, 24, 25, 26, 57, 62, 0, 63,
- 3, 4, 5, 6, 41, 0, 0, 7, 0, 9,
- 10, 11, 12, 13, 14, 15, 16, 0, 17, 18,
- 19, 0, 20, 21, 22, 23, 24, 25, 26, 0,
- 0, 0, 0, 0, 0, 28, 3, 4, 5, 6,
- 27, 0, 0, 7, 0, 9, 10, 11, 12, 13,
- 14, 15, 16, 0, 17, 18, 19, 0, 20, 21,
- 22, 23, 24, 25, 26, 3, 86, 5, 6, 0,
- 0, 0, 7, 0, 0, 3, 11, 5, 6, 0,
- 0, 16, 7, 17, 18, 19, 11, 20, 141, 0,
- 23, 16, 0, 17, 18, 19, 0, 20, 0, 92,
- 23, 92, 92, 92, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 96, 92, 96, 96,
- 96, 3, 0, 5, 6, 0, 0, 0, 7, 0,
- 76, 0, 11, 76, 96, 0, 0, 16, 0, 17,
- 18, 19, 0, 20, 0, 0, 23, 0, 76, 0,
- 0, 92, 92, 0, 3, 0, 71, 6, 0, 0,
- 82, 7, 82, 82, 82, 11, 0, 0, 96, 96,
- 16, 0, 17, 18, 19, 0, 20, 0, 82, 23,
- 0, 0, 76, 92, 0, 0, 3, 0, 125, 6,
- 0, 0, 0, 7, 0, 0, 0, 11, 70, 0,
- 96, 70, 16, 0, 17, 18, 19, 0, 20, 0,
- 0, 23, 82, 82, 76, 92, 70, 92, 92, 92,
- 0, 0, 0, 0, 0, 0, 0, 79, 0, 79,
- 79, 79, 64, 92, 65, 0, 0, 0, 0, 90,
- 0, 64, 0, 65, 82, 79, 0, 0, 0, 0,
- 70, 0, 110, 0, 64, 3, 65, 5, 6, 0,
- 0, 0, 7, 0, 0, 0, 11, 92, 92, 0,
- 64, 16, 65, 17, 18, 19, 0, 20, 0, 79,
- 23, 0, 70, 66, 80, 0, 80, 80, 80, 0,
- 0, 0, 66, 0, 0, 0, 114, 0, 64, 92,
- 65, 0, 80, 0, 0, 66, 0, 0, 0, 0,
- 77, 79, 77, 77, 77, 92, 92, 92, 0, 0,
- 106, 66, 92, 92, 92, 92, 0, 78, 77, 78,
- 78, 78, 96, 96, 96, 92, 80, 0, 0, 96,
- 96, 96, 96, 0, 0, 78, 76, 76, 76, 66,
- 0, 75, 96, 0, 75, 76, 0, 72, 0, 116,
- 72, 64, 77, 65, 0, 0, 76, 0, 80, 75,
- 74, 0, 0, 74, 0, 72, 82, 82, 82, 78,
- 0, 0, 0, 82, 0, 82, 0, 0, 74, 0,
- 0, 0, 0, 0, 77, 92, 82, 92, 92, 92,
- 0, 0, 0, 75, 0, 0, 117, 0, 64, 72,
- 65, 78, 66, 0, 70, 70, 70, 64, 0, 65,
- 0, 0, 74, 70, 0, 0, 0, 0, 0, 0,
- 0, 92, 92, 92, 70, 75, 0, 0, 92, 0,
- 92, 72, 0, 79, 79, 79, 0, 60, 92, 0,
- 79, 92, 79, 62, 74, 63, 60, 61, 0, 66,
- 0, 0, 62, 79, 63, 0, 0, 0, 66, 60,
- 61, 0, 0, 0, 0, 62, 0, 63, 0, 0,
- 0, 0, 0, 0, 0, 60, 61, 0, 0, 0,
- 0, 62, 0, 63, 0, 0, 0, 0, 0, 0,
- 80, 80, 80, 0, 0, 0, 0, 80, 0, 80,
- 0, 0, 0, 60, 61, 0, 0, 0, 0, 62,
- 80, 63, 0, 0, 0, 0, 77, 77, 77, 0,
- 0, 0, 0, 0, 0, 77, 0, 0, 0, 0,
- 0, 0, 0, 78, 78, 78, 77, 0, 0, 0,
- 0, 0, 78, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 78, 0, 0, 0, 75, 75, 75,
- 0, 0, 0, 72, 72, 72, 60, 61, 0, 0,
- 0, 0, 62, 0, 63, 0, 74, 75, 74, 0,
- 0, 0, 0, 72, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 74, 0, 0, 0,
- 39, 0, 92, 92, 0, 0, 0, 0, 92, 92,
- 92, 92, 0, 60, 61, 0, 0, 0, 0, 62,
- 0, 63, 60, 61, 55, 56, 0, 0, 62, 0,
- 63, 0, 0, 0, 0, 0, 0, 72, 75, 0,
- 0, 0, 0, 77, 78, 0, 81, 0, 83, 84,
- 0, 87, 0, 0, 0, 0, 0, 0, 0, 96,
- 97, 98, 99, 100, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 112, 0, 115,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 121, 122, 0, 0, 0, 0, 0, 123, 0,
- 75, 0, 126, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 87, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 75, 0, 0, 0, 112, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 112,
-};
-short yycheck[] = { 40,
- 59, 44, 94, 43, 45, 45, 59, 41, 59, 41,
- 44, 59, 44, 59, 59, 1, 59, 40, 59, 138,
- 262, 41, 40, 2, 265, 59, 267, 59, 262, 59,
- 40, 40, 40, 91, 40, 40, 155, 45, 59, 59,
- 44, 40, 59, 40, 278, 279, 280, 41, 40, 40,
- 44, 285, 59, 40, 94, 40, 262, 94, 41, 59,
- 44, 44, 44, 41, 41, 40, 125, 41, 91, 91,
- 45, 59, 125, 91, 125, 59, 41, 125, 57, 125,
- 125, 91, 123, 44, 70, 123, 59, 262, 41, 257,
- 93, 277, 281, 91, 41, 59, 41, 40, 93, 41,
- 41, 41, 45, 41, 59, 91, 41, 59, 41, 41,
- 7, -1, 148, 92, -1, 123, 118, -1, -1, 154,
- -1, -1, -1, -1, -1, -1, 43, -1, 45, -1,
- 40, -1, -1, -1, -1, 45, 59, -1, -1, -1,
- -1, 125, -1, -1, -1, -1, -1, -1, 123, -1,
- 125, -1, 131, -1, -1, -1, -1, -1, -1, -1,
- -1, 140, -1, -1, -1, -1, 40, -1, -1, -1,
- 125, 45, 264, 152, -1, 161, -1, 94, -1, -1,
- 123, -1, -1, -1, -1, 164, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, 40, -1, -1, 257, -1,
- 45, -1, 125, -1, 257, 40, 257, -1, -1, 257,
- 45, 257, 257, 123, 257, 256, 257, -1, 277, 260,
- 261, 262, 263, 257, 264, 257, 267, 257, 269, 270,
- 271, 272, 273, 274, 275, 276, 257, 278, 279, 280,
- 257, 282, 283, 284, 285, 286, 287, 288, 256, 123,
- 257, 40, 260, 261, 262, 263, 45, 257, 93, 267,
- 268, 269, 270, 271, 272, 273, 274, 275, 276, 257,
- 278, 279, 280, 257, 282, 283, 284, 285, 286, 287,
- 288, 256, -1, -1, 40, 260, 261, 262, 263, 45,
- -1, -1, 267, 277, 269, 270, 271, 272, 273, 274,
- 275, 276, 257, 278, 279, 280, -1, 282, 283, 284,
- 285, 286, 287, 288, 257, -1, 40, 260, 261, 262,
- 263, 45, 277, -1, 267, -1, 269, 270, 271, 272,
- 273, 274, 275, 276, 257, 278, 279, 280, -1, 282,
- 283, 284, 285, 286, 287, 288, 256, 264, -1, 266,
- 260, 261, 262, 263, 277, -1, -1, 267, -1, 269,
- 270, 271, 272, 273, 274, 275, 276, -1, 278, 279,
- 280, -1, 282, 283, 284, 285, 286, 287, 288, -1,
- -1, -1, -1, -1, -1, 40, 260, 261, 262, 263,
- 45, -1, -1, 267, -1, 269, 270, 271, 272, 273,
- 274, 275, 276, -1, 278, 279, 280, -1, 282, 283,
- 284, 285, 286, 287, 288, 260, 261, 262, 263, -1,
- -1, -1, 267, -1, -1, 260, 271, 262, 263, -1,
- -1, 276, 267, 278, 279, 280, 271, 282, 93, -1,
- 285, 276, -1, 278, 279, 280, -1, 282, -1, 41,
- 285, 43, 44, 45, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 41, 59, 43, 44,
- 45, 260, -1, 262, 263, -1, -1, -1, 267, -1,
- 41, -1, 271, 44, 59, -1, -1, 276, -1, 278,
- 279, 280, -1, 282, -1, -1, 285, -1, 59, -1,
- -1, 93, 94, -1, 260, -1, 262, 263, -1, -1,
- 41, 267, 43, 44, 45, 271, -1, -1, 93, 94,
- 276, -1, 278, 279, 280, -1, 282, -1, 59, 285,
- -1, -1, 93, 125, -1, -1, 260, -1, 262, 263,
- -1, -1, -1, 267, -1, -1, -1, 271, 41, -1,
- 125, 44, 276, -1, 278, 279, 280, -1, 282, -1,
- -1, 285, 93, 94, 125, 41, 59, 43, 44, 45,
- -1, -1, -1, -1, -1, -1, -1, 41, -1, 43,
- 44, 45, 43, 59, 45, -1, -1, -1, -1, 41,
- -1, 43, -1, 45, 125, 59, -1, -1, -1, -1,
- 93, -1, 41, -1, 43, 260, 45, 262, 263, -1,
- -1, -1, 267, -1, -1, -1, 271, 93, 94, -1,
- 43, 276, 45, 278, 279, 280, -1, 282, -1, 93,
- 285, -1, 125, 94, 41, -1, 43, 44, 45, -1,
- -1, -1, 94, -1, -1, -1, 41, -1, 43, 125,
- 45, -1, 59, -1, -1, 94, -1, -1, -1, -1,
- 41, 125, 43, 44, 45, 257, 258, 259, -1, -1,
- 93, 94, 264, 265, 266, 267, -1, 41, 59, 43,
- 44, 45, 257, 258, 259, 277, 93, -1, -1, 264,
- 265, 266, 267, -1, -1, 59, 257, 258, 259, 94,
- -1, 41, 277, -1, 44, 266, -1, 41, -1, 41,
- 44, 43, 93, 45, -1, -1, 277, -1, 125, 59,
- 41, -1, -1, 44, -1, 59, 257, 258, 259, 93,
- -1, -1, -1, 264, -1, 266, -1, -1, 59, -1,
- -1, -1, -1, -1, 125, 41, 277, 43, 44, 45,
- -1, -1, -1, 93, -1, -1, 41, -1, 43, 93,
- 45, 125, 94, -1, 257, 258, 259, 43, -1, 45,
- -1, -1, 93, 266, -1, -1, -1, -1, -1, -1,
- -1, 257, 258, 259, 277, 125, -1, -1, 264, -1,
- 266, 125, -1, 257, 258, 259, -1, 258, 94, -1,
- 264, 277, 266, 264, 125, 266, 258, 259, -1, 94,
- -1, -1, 264, 277, 266, -1, -1, -1, 94, 258,
- 259, -1, -1, -1, -1, 264, -1, 266, -1, -1,
- -1, -1, -1, -1, -1, 258, 259, -1, -1, -1,
- -1, 264, -1, 266, -1, -1, -1, -1, -1, -1,
- 257, 258, 259, -1, -1, -1, -1, 264, -1, 266,
- -1, -1, -1, 258, 259, -1, -1, -1, -1, 264,
- 277, 266, -1, -1, -1, -1, 257, 258, 259, -1,
- -1, -1, -1, -1, -1, 266, -1, -1, -1, -1,
- -1, -1, -1, 257, 258, 259, 277, -1, -1, -1,
- -1, -1, 266, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, 277, -1, -1, -1, 257, 258, 259,
- -1, -1, -1, 257, 258, 259, 258, 259, -1, -1,
- -1, -1, 264, -1, 266, -1, 257, 277, 259, -1,
- -1, -1, -1, 277, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 277, -1, -1, -1,
- 3, -1, 258, 259, -1, -1, -1, -1, 264, 265,
- 266, 267, -1, 258, 259, -1, -1, -1, -1, 264,
- -1, 266, 258, 259, 27, 28, -1, -1, 264, -1,
- 266, -1, -1, -1, -1, -1, -1, 40, 41, -1,
- -1, -1, -1, 46, 47, -1, 49, -1, 51, 52,
- -1, 54, -1, -1, -1, -1, -1, -1, -1, 62,
- 63, 64, 65, 66, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, 80, -1, 82,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 94, 95, -1, -1, -1, -1, -1, 101, -1,
- 103, -1, 105, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, 118, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 134, -1, -1, -1, 138, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, 155,
-};
-#define YYFINAL 1
-#ifndef YYDEBUG
-#define YYDEBUG 0
-#endif
-#define YYMAXTOKEN 289
-#if YYDEBUG
-char *yyname[] = {
-"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,"'('","')'",0,"'+'","','","'-'",0,0,0,0,0,0,0,0,0,0,0,0,0,"';'",0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'","'^'",0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'{'",0,"'}'",0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,"NEWLINE","AND","OR","NOT","STRING","NAME","NUMBER","MUL_OP",
-"ASSIGN_OP","REL_OP","INCR_DECR","Define","Break","Quit","Length","Return",
-"For","If","While","Sqrt","Else","Scale","Ibase","Obase","Auto","Read",
-"Warranty","Halt","Last","Continue","Print","Limits","UNARY_MINUS",
-};
-char *yyrule[] = {
-"$accept : program",
-"program :",
-"program : program input_item",
-"input_item : semicolon_list NEWLINE",
-"input_item : function",
-"input_item : error NEWLINE",
-"semicolon_list :",
-"semicolon_list : statement_or_error",
-"semicolon_list : semicolon_list ';' statement_or_error",
-"semicolon_list : semicolon_list ';'",
-"statement_list :",
-"statement_list : statement_or_error",
-"statement_list : statement_list NEWLINE",
-"statement_list : statement_list NEWLINE statement_or_error",
-"statement_list : statement_list ';'",
-"statement_list : statement_list ';' statement",
-"statement_or_error : statement",
-"statement_or_error : error statement",
-"statement : Warranty",
-"statement : Limits",
-"statement : expression",
-"statement : STRING",
-"statement : Break",
-"statement : Continue",
-"statement : Quit",
-"statement : Halt",
-"statement : Return",
-"statement : Return '(' return_expression ')'",
-"$$1 :",
-"$$2 :",
-"$$3 :",
-"$$4 :",
-"statement : For $$1 '(' opt_expression ';' $$2 opt_expression ';' $$3 opt_expression ')' $$4 statement",
-"$$5 :",
-"statement : If '(' expression ')' $$5 statement opt_else",
-"$$6 :",
-"$$7 :",
-"statement : While $$6 '(' expression $$7 ')' statement",
-"statement : '{' statement_list '}'",
-"$$8 :",
-"statement : Print $$8 print_list",
-"print_list : print_element",
-"print_list : print_element ',' print_list",
-"print_element : STRING",
-"print_element : expression",
-"opt_else :",
-"$$9 :",
-"opt_else : Else $$9 statement",
-"$$10 :",
-"function : Define NAME '(' opt_parameter_list ')' '{' NEWLINE opt_auto_define_list $$10 statement_list NEWLINE '}'",
-"opt_parameter_list :",
-"opt_parameter_list : define_list",
-"opt_auto_define_list :",
-"opt_auto_define_list : Auto define_list NEWLINE",
-"opt_auto_define_list : Auto define_list ';'",
-"define_list : NAME",
-"define_list : NAME '[' ']'",
-"define_list : define_list ',' NAME",
-"define_list : define_list ',' NAME '[' ']'",
-"opt_argument_list :",
-"opt_argument_list : argument_list",
-"argument_list : expression",
-"argument_list : NAME '[' ']'",
-"argument_list : argument_list ',' expression",
-"argument_list : argument_list ',' NAME '[' ']'",
-"opt_expression :",
-"opt_expression : expression",
-"return_expression :",
-"return_expression : expression",
-"$$11 :",
-"expression : named_expression ASSIGN_OP $$11 expression",
-"$$12 :",
-"expression : expression AND $$12 expression",
-"$$13 :",
-"expression : expression OR $$13 expression",
-"expression : NOT expression",
-"expression : expression REL_OP expression",
-"expression : expression '+' expression",
-"expression : expression '-' expression",
-"expression : expression MUL_OP expression",
-"expression : expression '^' expression",
-"expression : '-' expression",
-"expression : named_expression",
-"expression : NUMBER",
-"expression : '(' expression ')'",
-"expression : NAME '(' opt_argument_list ')'",
-"expression : INCR_DECR named_expression",
-"expression : named_expression INCR_DECR",
-"expression : Length '(' expression ')'",
-"expression : Sqrt '(' expression ')'",
-"expression : Scale '(' expression ')'",
-"expression : Read '(' ')'",
-"named_expression : NAME",
-"named_expression : NAME '[' expression ']'",
-"named_expression : Ibase",
-"named_expression : Obase",
-"named_expression : Scale",
-"named_expression : Last",
-};
-#endif
-#define yyclearin (yychar=(-1))
-#define yyerrok (yyerrflag=0)
-#ifdef YYSTACKSIZE
-#ifndef YYMAXDEPTH
-#define YYMAXDEPTH YYSTACKSIZE
-#endif
-#else
-#ifdef YYMAXDEPTH
-#define YYSTACKSIZE YYMAXDEPTH
-#else
-#define YYSTACKSIZE 500
-#define YYMAXDEPTH 500
-#endif
-#endif
-int yydebug;
-int yynerrs;
-int yyerrflag;
-int yychar;
-short *yyssp;
-YYSTYPE *yyvsp;
-YYSTYPE yyval;
-YYSTYPE yylval;
-short yyss[YYSTACKSIZE];
-YYSTYPE yyvs[YYSTACKSIZE];
-#define yystacksize YYSTACKSIZE
-#define YYABORT goto yyabort
-#define YYACCEPT goto yyaccept
-#define YYERROR goto yyerrlab
-int
-yyparse()
-{
- register int yym, yyn, yystate;
-#if YYDEBUG
- register char *yys;
- extern char *getenv();
-
- if (yys = getenv("YYDEBUG"))
- {
- yyn = *yys;
- if (yyn >= '0' && yyn <= '9')
- yydebug = yyn - '0';
- }
-#endif
-
- yynerrs = 0;
- yyerrflag = 0;
- yychar = (-1);
-
- yyssp = yyss;
- yyvsp = yyvs;
- *yyssp = yystate = 0;
-
-yyloop:
- if (yyn = yydefred[yystate]) goto yyreduce;
- if (yychar < 0)
- {
- if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
- if (yydebug)
- {
- yys = 0;
- if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
- if (!yys) yys = "illegal-symbol";
- printf("yydebug: state %d, reading %d (%s)\n", yystate,
- yychar, yys);
- }
-#endif
- }
- if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
- {
-#if YYDEBUG
- if (yydebug)
- printf("yydebug: state %d, shifting to state %d\n",
- yystate, yytable[yyn]);
-#endif
- if (yyssp >= yyss + yystacksize - 1)
- {
- goto yyoverflow;
- }
- *++yyssp = yystate = yytable[yyn];
- *++yyvsp = yylval;
- yychar = (-1);
- if (yyerrflag > 0) --yyerrflag;
- goto yyloop;
- }
- if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
- {
- yyn = yytable[yyn];
- goto yyreduce;
- }
- if (yyerrflag) goto yyinrecovery;
-#ifdef lint
- goto yynewerror;
-#endif
-yynewerror:
- yyerror("syntax error");
-#ifdef lint
- goto yyerrlab;
-#endif
-yyerrlab:
- ++yynerrs;
-yyinrecovery:
- if (yyerrflag < 3)
- {
- yyerrflag = 3;
- for (;;)
- {
- if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
- {
-#if YYDEBUG
- if (yydebug)
- printf("yydebug: state %d, error recovery shifting\
- to state %d\n", *yyssp, yytable[yyn]);
-#endif
- if (yyssp >= yyss + yystacksize - 1)
- {
- goto yyoverflow;
- }
- *++yyssp = yystate = yytable[yyn];
- *++yyvsp = yylval;
- goto yyloop;
- }
- else
- {
-#if YYDEBUG
- if (yydebug)
- printf("yydebug: error recovery discarding state %d\n",
- *yyssp);
-#endif
- if (yyssp <= yyss) goto yyabort;
- --yyssp;
- --yyvsp;
- }
- }
- }
- else
- {
- if (yychar == 0) goto yyabort;
-#if YYDEBUG
- if (yydebug)
- {
- yys = 0;
- if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
- if (!yys) yys = "illegal-symbol";
- printf("yydebug: state %d, error recovery discards token %d (%s)\n",
- yystate, yychar, yys);
- }
-#endif
- yychar = (-1);
- goto yyloop;
- }
-yyreduce:
-#if YYDEBUG
- if (yydebug)
- printf("yydebug: state %d, reducing by rule %d (%s)\n",
- yystate, yyn, yyrule[yyn]);
-#endif
- yym = yylen[yyn];
- yyval = yyvsp[1-yym];
- switch (yyn)
- {
-case 1:
-#line 106 "bc.y"
-{
- yyval.i_value = 0;
- if (interactive)
- {
- printf ("%s\n", BC_VERSION);
- welcome ();
- }
- }
-break;
-case 3:
-#line 117 "bc.y"
-{ run_code (); }
-break;
-case 4:
-#line 119 "bc.y"
-{ run_code (); }
-break;
-case 5:
-#line 121 "bc.y"
-{
- yyerrok;
- init_gen ();
- }
-break;
-case 6:
-#line 127 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 10:
-#line 133 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 17:
-#line 142 "bc.y"
-{ yyval.i_value = yyvsp[0].i_value; }
-break;
-case 18:
-#line 145 "bc.y"
-{ warranty (""); }
-break;
-case 19:
-#line 147 "bc.y"
-{ limits (); }
-break;
-case 20:
-#line 149 "bc.y"
-{
- if (yyvsp[0].i_value & 2)
- warn ("comparison in expression");
- if (yyvsp[0].i_value & 1)
- generate ("W");
- else
- generate ("p");
- }
-break;
-case 21:
-#line 158 "bc.y"
-{
- yyval.i_value = 0;
- generate ("w");
- generate (yyvsp[0].s_value);
- free (yyvsp[0].s_value);
- }
-break;
-case 22:
-#line 165 "bc.y"
-{
- if (break_label == 0)
- yyerror ("Break outside a for/while");
- else
- {
- sprintf (genstr, "J%1d:", break_label);
- generate (genstr);
- }
- }
-break;
-case 23:
-#line 175 "bc.y"
-{
- warn ("Continue statement");
- if (continue_label == 0)
- yyerror ("Continue outside a for");
- else
- {
- sprintf (genstr, "J%1d:", continue_label);
- generate (genstr);
- }
- }
-break;
-case 24:
-#line 186 "bc.y"
-{ exit (0); }
-break;
-case 25:
-#line 188 "bc.y"
-{ generate ("h"); }
-break;
-case 26:
-#line 190 "bc.y"
-{ generate ("0R"); }
-break;
-case 27:
-#line 192 "bc.y"
-{ generate ("R"); }
-break;
-case 28:
-#line 194 "bc.y"
-{
- yyvsp[0].i_value = break_label;
- break_label = next_label++;
- }
-break;
-case 29:
-#line 199 "bc.y"
-{
- if (yyvsp[-1].i_value > 1)
- warn ("Comparison in first for expression");
- yyvsp[-1].i_value = next_label++;
- if (yyvsp[-1].i_value < 0)
- sprintf (genstr, "N%1d:", yyvsp[-1].i_value);
- else
- sprintf (genstr, "pN%1d:", yyvsp[-1].i_value);
- generate (genstr);
- }
-break;
-case 30:
-#line 210 "bc.y"
-{
- if (yyvsp[-1].i_value < 0) generate ("1");
- yyvsp[-1].i_value = next_label++;
- sprintf (genstr, "B%1d:J%1d:", yyvsp[-1].i_value, break_label);
- generate (genstr);
- yyval.i_value = continue_label;
- continue_label = next_label++;
- sprintf (genstr, "N%1d:", continue_label);
- generate (genstr);
- }
-break;
-case 31:
-#line 221 "bc.y"
-{
- if (yyvsp[-1].i_value > 1)
- warn ("Comparison in third for expression");
- if (yyvsp[-1].i_value < 0)
- sprintf (genstr, "J%1d:N%1d:", yyvsp[-7].i_value, yyvsp[-4].i_value);
- else
- sprintf (genstr, "pJ%1d:N%1d:", yyvsp[-7].i_value, yyvsp[-4].i_value);
- generate (genstr);
- }
-break;
-case 32:
-#line 231 "bc.y"
-{
- sprintf (genstr, "J%1d:N%1d:",
- continue_label, break_label);
- generate (genstr);
- break_label = yyvsp[-12].i_value;
- continue_label = yyvsp[-4].i_value;
- }
-break;
-case 33:
-#line 239 "bc.y"
-{
- yyvsp[-1].i_value = if_label;
- if_label = next_label++;
- sprintf (genstr, "Z%1d:", if_label);
- generate (genstr);
- }
-break;
-case 34:
-#line 246 "bc.y"
-{
- sprintf (genstr, "N%1d:", if_label);
- generate (genstr);
- if_label = yyvsp[-4].i_value;
- }
-break;
-case 35:
-#line 252 "bc.y"
-{
- yyvsp[0].i_value = next_label++;
- sprintf (genstr, "N%1d:", yyvsp[0].i_value);
- generate (genstr);
- }
-break;
-case 36:
-#line 258 "bc.y"
-{
- yyvsp[0].i_value = break_label;
- break_label = next_label++;
- sprintf (genstr, "Z%1d:", break_label);
- generate (genstr);
- }
-break;
-case 37:
-#line 265 "bc.y"
-{
- sprintf (genstr, "J%1d:N%1d:", yyvsp[-6].i_value, break_label);
- generate (genstr);
- break_label = yyvsp[-3].i_value;
- }
-break;
-case 38:
-#line 271 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 39:
-#line 273 "bc.y"
-{ warn ("print statement"); }
-break;
-case 43:
-#line 280 "bc.y"
-{
- generate ("O");
- generate (yyvsp[0].s_value);
- free (yyvsp[0].s_value);
- }
-break;
-case 44:
-#line 286 "bc.y"
-{ generate ("P"); }
-break;
-case 46:
-#line 290 "bc.y"
-{
- warn ("else clause in if statement");
- yyvsp[0].i_value = next_label++;
- sprintf (genstr, "J%d:N%1d:", yyvsp[0].i_value, if_label);
- generate (genstr);
- if_label = yyvsp[0].i_value;
- }
-break;
-case 48:
-#line 300 "bc.y"
-{
- /* Check auto list against parameter list? */
- check_params (yyvsp[-4].a_value,yyvsp[0].a_value);
- sprintf (genstr, "F%d,%s.%s[", lookup(yyvsp[-6].s_value,FUNCT),
- arg_str (yyvsp[-4].a_value,TRUE), arg_str (yyvsp[0].a_value,TRUE));
- generate (genstr);
- free_args (yyvsp[-4].a_value);
- free_args (yyvsp[0].a_value);
- yyvsp[-7].i_value = next_label;
- next_label = 0;
- }
-break;
-case 49:
-#line 312 "bc.y"
-{
- generate ("0R]");
- next_label = yyvsp[-11].i_value;
- }
-break;
-case 50:
-#line 318 "bc.y"
-{ yyval.a_value = NULL; }
-break;
-case 52:
-#line 322 "bc.y"
-{ yyval.a_value = NULL; }
-break;
-case 53:
-#line 324 "bc.y"
-{ yyval.a_value = yyvsp[-1].a_value; }
-break;
-case 54:
-#line 326 "bc.y"
-{ yyval.a_value = yyvsp[-1].a_value; }
-break;
-case 55:
-#line 329 "bc.y"
-{ yyval.a_value = nextarg (NULL, lookup (yyvsp[0].s_value,SIMPLE)); }
-break;
-case 56:
-#line 331 "bc.y"
-{ yyval.a_value = nextarg (NULL, lookup (yyvsp[-2].s_value,ARRAY)); }
-break;
-case 57:
-#line 333 "bc.y"
-{ yyval.a_value = nextarg (yyvsp[-2].a_value, lookup (yyvsp[0].s_value,SIMPLE)); }
-break;
-case 58:
-#line 335 "bc.y"
-{ yyval.a_value = nextarg (yyvsp[-4].a_value, lookup (yyvsp[-2].s_value,ARRAY)); }
-break;
-case 59:
-#line 338 "bc.y"
-{ yyval.a_value = NULL; }
-break;
-case 61:
-#line 342 "bc.y"
-{
- if (yyvsp[0].i_value > 1) warn ("comparison in argument");
- yyval.a_value = nextarg (NULL,0);
- }
-break;
-case 62:
-#line 347 "bc.y"
-{
- sprintf (genstr, "K%d:", -lookup (yyvsp[-2].s_value,ARRAY));
- generate (genstr);
- yyval.a_value = nextarg (NULL,1);
- }
-break;
-case 63:
-#line 353 "bc.y"
-{
- if (yyvsp[0].i_value > 1) warn ("comparison in argument");
- yyval.a_value = nextarg (yyvsp[-2].a_value,0);
- }
-break;
-case 64:
-#line 358 "bc.y"
-{
- sprintf (genstr, "K%d:", -lookup (yyvsp[-2].s_value,ARRAY));
- generate (genstr);
- yyval.a_value = nextarg (yyvsp[-4].a_value,1);
- }
-break;
-case 65:
-#line 365 "bc.y"
-{
- yyval.i_value = -1;
- warn ("Missing expression in for statement");
- }
-break;
-case 67:
-#line 372 "bc.y"
-{
- yyval.i_value = 0;
- generate ("0");
- }
-break;
-case 68:
-#line 377 "bc.y"
-{
- if (yyvsp[0].i_value > 1)
- warn ("comparison in return expresion");
- }
-break;
-case 69:
-#line 383 "bc.y"
-{
- if (yyvsp[0].c_value != '=')
- {
- if (yyvsp[-1].i_value < 0)
- sprintf (genstr, "DL%d:", -yyvsp[-1].i_value);
- else
- sprintf (genstr, "l%d:", yyvsp[-1].i_value);
- generate (genstr);
- }
- }
-break;
-case 70:
-#line 394 "bc.y"
-{
- if (yyvsp[0].i_value > 1) warn("comparison in assignment");
- if (yyvsp[-2].c_value != '=')
- {
- sprintf (genstr, "%c", yyvsp[-2].c_value);
- generate (genstr);
- }
- if (yyvsp[-3].i_value < 0)
- sprintf (genstr, "S%d:", -yyvsp[-3].i_value);
- else
- sprintf (genstr, "s%d:", yyvsp[-3].i_value);
- generate (genstr);
- yyval.i_value = 0;
- }
-break;
-case 71:
-#line 410 "bc.y"
-{
- warn("&& operator");
- yyvsp[0].i_value = next_label++;
- sprintf (genstr, "DZ%d:p", yyvsp[0].i_value);
- generate (genstr);
- }
-break;
-case 72:
-#line 417 "bc.y"
-{
- sprintf (genstr, "DZ%d:p1N%d:", yyvsp[-2].i_value, yyvsp[-2].i_value);
- generate (genstr);
- yyval.i_value = yyvsp[-3].i_value | yyvsp[0].i_value;
- }
-break;
-case 73:
-#line 423 "bc.y"
-{
- warn("|| operator");
- yyvsp[0].i_value = next_label++;
- sprintf (genstr, "B%d:", yyvsp[0].i_value);
- generate (genstr);
- }
-break;
-case 74:
-#line 430 "bc.y"
-{
- int tmplab;
- tmplab = next_label++;
- sprintf (genstr, "B%d:0J%d:N%d:1N%d:",
- yyvsp[-2].i_value, tmplab, yyvsp[-2].i_value, tmplab);
- generate (genstr);
- yyval.i_value = yyvsp[-3].i_value | yyvsp[0].i_value;
- }
-break;
-case 75:
-#line 439 "bc.y"
-{
- yyval.i_value = yyvsp[0].i_value;
- warn("! operator");
- generate ("!");
- }
-break;
-case 76:
-#line 445 "bc.y"
-{
- yyval.i_value = 3;
- switch (*(yyvsp[-1].s_value))
- {
- case '=':
- generate ("=");
- break;
-
- case '!':
- generate ("#");
- break;
-
- case '<':
- if (yyvsp[-1].s_value[1] == '=')
- generate ("{");
- else
- generate ("<");
- break;
-
- case '>':
- if (yyvsp[-1].s_value[1] == '=')
- generate ("}");
- else
- generate (">");
- break;
- }
- }
-break;
-case 77:
-#line 473 "bc.y"
-{
- generate ("+");
- yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
- }
-break;
-case 78:
-#line 478 "bc.y"
-{
- generate ("-");
- yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
- }
-break;
-case 79:
-#line 483 "bc.y"
-{
- genstr[0] = yyvsp[-1].c_value;
- genstr[1] = 0;
- generate (genstr);
- yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
- }
-break;
-case 80:
-#line 490 "bc.y"
-{
- generate ("^");
- yyval.i_value = yyvsp[-2].i_value | yyvsp[0].i_value;
- }
-break;
-case 81:
-#line 495 "bc.y"
-{
- generate ("n");
- yyval.i_value = yyvsp[0].i_value;
- }
-break;
-case 82:
-#line 500 "bc.y"
-{
- yyval.i_value = 1;
- if (yyvsp[0].i_value < 0)
- sprintf (genstr, "L%d:", -yyvsp[0].i_value);
- else
- sprintf (genstr, "l%d:", yyvsp[0].i_value);
- generate (genstr);
- }
-break;
-case 83:
-#line 509 "bc.y"
-{
- int len = strlen(yyvsp[0].s_value);
- yyval.i_value = 1;
- if (len == 1 && *yyvsp[0].s_value == '0')
- generate ("0");
- else if (len == 1 && *yyvsp[0].s_value == '1')
- generate ("1");
- else
- {
- generate ("K");
- generate (yyvsp[0].s_value);
- generate (":");
- }
- free (yyvsp[0].s_value);
- }
-break;
-case 84:
-#line 525 "bc.y"
-{ yyval.i_value = yyvsp[-1].i_value | 1; }
-break;
-case 85:
-#line 527 "bc.y"
-{
- yyval.i_value = 1;
- if (yyvsp[-1].a_value != NULL)
- {
- sprintf (genstr, "C%d,%s:",
- lookup (yyvsp[-3].s_value,FUNCT),
- arg_str (yyvsp[-1].a_value,FALSE));
- free_args (yyvsp[-1].a_value);
- }
- else
- {
- sprintf (genstr, "C%d:", lookup (yyvsp[-3].s_value,FUNCT));
- }
- generate (genstr);
- }
-break;
-case 86:
-#line 543 "bc.y"
-{
- yyval.i_value = 1;
- if (yyvsp[0].i_value < 0)
- {
- if (yyvsp[-1].c_value == '+')
- sprintf (genstr, "DA%d:L%d:", -yyvsp[0].i_value, -yyvsp[0].i_value);
- else
- sprintf (genstr, "DM%d:L%d:", -yyvsp[0].i_value, -yyvsp[0].i_value);
- }
- else
- {
- if (yyvsp[-1].c_value == '+')
- sprintf (genstr, "i%d:l%d:", yyvsp[0].i_value, yyvsp[0].i_value);
- else
- sprintf (genstr, "d%d:l%d:", yyvsp[0].i_value, yyvsp[0].i_value);
- }
- generate (genstr);
- }
-break;
-case 87:
-#line 562 "bc.y"
-{
- yyval.i_value = 1;
- if (yyvsp[-1].i_value < 0)
- {
- sprintf (genstr, "DL%d:x", -yyvsp[-1].i_value);
- generate (genstr);
- if (yyvsp[0].c_value == '+')
- sprintf (genstr, "A%d:", -yyvsp[-1].i_value);
- else
- sprintf (genstr, "M%d:", -yyvsp[-1].i_value);
- }
- else
- {
- sprintf (genstr, "l%d:", yyvsp[-1].i_value);
- generate (genstr);
- if (yyvsp[0].c_value == '+')
- sprintf (genstr, "i%d:", yyvsp[-1].i_value);
- else
- sprintf (genstr, "d%d:", yyvsp[-1].i_value);
- }
- generate (genstr);
- }
-break;
-case 88:
-#line 585 "bc.y"
-{ generate ("cL"); yyval.i_value = 1;}
-break;
-case 89:
-#line 587 "bc.y"
-{ generate ("cR"); yyval.i_value = 1;}
-break;
-case 90:
-#line 589 "bc.y"
-{ generate ("cS"); yyval.i_value = 1;}
-break;
-case 91:
-#line 591 "bc.y"
-{
- warn ("read function");
- generate ("cI"); yyval.i_value = 1;
- }
-break;
-case 92:
-#line 597 "bc.y"
-{ yyval.i_value = lookup(yyvsp[0].s_value,SIMPLE); }
-break;
-case 93:
-#line 599 "bc.y"
-{
- if (yyvsp[-1].i_value > 1) warn("comparison in subscript");
- yyval.i_value = lookup(yyvsp[-3].s_value,ARRAY);
- }
-break;
-case 94:
-#line 604 "bc.y"
-{ yyval.i_value = 0; }
-break;
-case 95:
-#line 606 "bc.y"
-{ yyval.i_value = 1; }
-break;
-case 96:
-#line 608 "bc.y"
-{ yyval.i_value = 2; }
-break;
-case 97:
-#line 610 "bc.y"
-{ yyval.i_value = 3; }
-break;
-#line 1314 "y.tab.c"
- }
- yyssp -= yym;
- yystate = *yyssp;
- yyvsp -= yym;
- yym = yylhs[yyn];
- if (yystate == 0 && yym == 0)
- {
-#if YYDEBUG
- if (yydebug)
- printf("yydebug: after reduction, shifting from state 0 to\
- state %d\n", YYFINAL);
-#endif
- yystate = YYFINAL;
- *++yyssp = YYFINAL;
- *++yyvsp = yyval;
- if (yychar < 0)
- {
- if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
- if (yydebug)
- {
- yys = 0;
- if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
- if (!yys) yys = "illegal-symbol";
- printf("yydebug: state %d, reading %d (%s)\n",
- YYFINAL, yychar, yys);
- }
-#endif
- }
- if (yychar == 0) goto yyaccept;
- goto yyloop;
- }
- if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
- yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
- yystate = yytable[yyn];
- else
- yystate = yydgoto[yym];
-#if YYDEBUG
- if (yydebug)
- printf("yydebug: after reduction, shifting from state %d \
-to state %d\n", *yyssp, yystate);
-#endif
- if (yyssp >= yyss + yystacksize - 1)
- {
- goto yyoverflow;
- }
- *++yyssp = yystate;
- *++yyvsp = yyval;
- goto yyloop;
-yyoverflow:
- yyerror("yacc stack overflow");
-yyabort:
- return (1);
-yyaccept:
- return (0);
-}
diff --git a/gnu/usr.bin/bc/bc.y b/gnu/usr.bin/bc/bc.y
new file mode 100644
index 0000000..2c888c3
--- /dev/null
+++ b/gnu/usr.bin/bc/bc.y
@@ -0,0 +1,615 @@
+%{
+/* bc.y: The grammar for a POSIX compatable bc processor with some
+ extensions to the language. */
+
+/* This file is part of bc written for MINIX.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License , or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You may contact the author by:
+ e-mail: phil@cs.wwu.edu
+ us-mail: Philip A. Nelson
+ Computer Science Department, 9062
+ Western Washington University
+ Bellingham, WA 98226-9062
+
+*************************************************************************/
+
+#include "bcdefs.h"
+#include "global.h"
+#include "proto.h"
+%}
+
+%start program
+
+%union {
+ char *s_value;
+ char c_value;
+ int i_value;
+ arg_list *a_value;
+ }
+
+/* Extensions over POSIX bc.
+ a) NAME was LETTER. This grammer allows longer names.
+ Single letter names will still work.
+ b) Relational_expression allowed only one comparison.
+ This grammar has added boolean expressions with
+ && (and) || (or) and ! (not) and allowed all of them in
+ full expressions.
+ c) Added an else to the if.
+ d) Call by variable array parameters
+ e) read() procedure that reads a number under program control from stdin.
+ f) halt statement that halts the the program under program control. It
+ is an executed statement.
+ g) continue statement for for loops.
+ h) optional expressions in the for loop.
+ i) print statement to print multiple numbers per line.
+ j) warranty statement to print an extended warranty notice.
+ j) limits statement to print the processor's limits.
+*/
+
+%token <i_value> NEWLINE AND OR NOT
+%token <s_value> STRING NAME NUMBER
+/* '-', '+' are tokens themselves */
+%token <c_value> MUL_OP
+/* '*', '/', '%' */
+%token <c_value> ASSIGN_OP
+/* '=', '+=', '-=', '*=', '/=', '%=', '^=' */
+%token <s_value> REL_OP
+/* '==', '<=', '>=', '!=', '<', '>' */
+%token <c_value> INCR_DECR
+/* '++', '--' */
+%token <i_value> Define Break Quit Length
+/* 'define', 'break', 'quit', 'length' */
+%token <i_value> Return For If While Sqrt Else
+/* 'return', 'for', 'if', 'while', 'sqrt', 'else' */
+%token <i_value> Scale Ibase Obase Auto Read
+/* 'scale', 'ibase', 'obase', 'auto', 'read' */
+%token <i_value> Warranty, Halt, Last, Continue, Print, Limits
+/* 'warranty', 'halt', 'last', 'continue', 'print', 'limits' */
+
+/* Types of all other things. */
+%type <i_value> expression return_expression named_expression opt_expression
+%type <c_value> '+' '-'
+%type <a_value> opt_parameter_list opt_auto_define_list define_list
+%type <a_value> opt_argument_list argument_list
+%type <i_value> program input_item semicolon_list statement_list
+%type <i_value> statement function statement_or_error
+
+/* precedence */
+%left OR
+%left AND
+%nonassoc NOT
+%left REL_OP
+%right ASSIGN_OP
+%left '+' '-'
+%left MUL_OP
+%right '^'
+%nonassoc UNARY_MINUS
+%nonassoc INCR_DECR
+
+%%
+program : /* empty */
+ {
+ $$ = 0;
+ if (interactive)
+ {
+ printf ("%s\n", BC_VERSION);
+ welcome ();
+ }
+ }
+ | program input_item
+ ;
+input_item : semicolon_list NEWLINE
+ { run_code (); }
+ | function
+ { run_code (); }
+ | error NEWLINE
+ {
+ yyerrok;
+ init_gen ();
+ }
+ ;
+semicolon_list : /* empty */
+ { $$ = 0; }
+ | statement_or_error
+ | semicolon_list ';' statement_or_error
+ | semicolon_list ';'
+ ;
+statement_list : /* empty */
+ { $$ = 0; }
+ | statement_or_error
+ | statement_list NEWLINE
+ | statement_list NEWLINE statement_or_error
+ | statement_list ';'
+ | statement_list ';' statement
+ ;
+statement_or_error : statement
+ | error statement
+ { $$ = $2; }
+ ;
+statement : Warranty
+ { warranty (""); }
+ | Limits
+ { limits (); }
+ | expression
+ {
+ if ($1 & 2)
+ warn ("comparison in expression");
+ if ($1 & 1)
+ generate ("W");
+ else
+ generate ("p");
+ }
+ | STRING
+ {
+ $$ = 0;
+ generate ("w");
+ generate ($1);
+ free ($1);
+ }
+ | Break
+ {
+ if (break_label == 0)
+ yyerror ("Break outside a for/while");
+ else
+ {
+ sprintf (genstr, "J%1d:", break_label);
+ generate (genstr);
+ }
+ }
+ | Continue
+ {
+ warn ("Continue statement");
+ if (continue_label == 0)
+ yyerror ("Continue outside a for");
+ else
+ {
+ sprintf (genstr, "J%1d:", continue_label);
+ generate (genstr);
+ }
+ }
+ | Quit
+ { exit (0); }
+ | Halt
+ { generate ("h"); }
+ | Return
+ { generate ("0R"); }
+ | Return '(' return_expression ')'
+ { generate ("R"); }
+ | For
+ {
+ $1 = break_label;
+ break_label = next_label++;
+ }
+ '(' opt_expression ';'
+ {
+ if ($4 > 1)
+ warn ("Comparison in first for expression");
+ $4 = next_label++;
+ if ($4 < 0)
+ sprintf (genstr, "N%1d:", $4);
+ else
+ sprintf (genstr, "pN%1d:", $4);
+ generate (genstr);
+ }
+ opt_expression ';'
+ {
+ if ($7 < 0) generate ("1");
+ $7 = next_label++;
+ sprintf (genstr, "B%1d:J%1d:", $7, break_label);
+ generate (genstr);
+ $<i_value>$ = continue_label;
+ continue_label = next_label++;
+ sprintf (genstr, "N%1d:", continue_label);
+ generate (genstr);
+ }
+ opt_expression ')'
+ {
+ if ($10 > 1)
+ warn ("Comparison in third for expression");
+ if ($10 < 0)
+ sprintf (genstr, "J%1d:N%1d:", $4, $7);
+ else
+ sprintf (genstr, "pJ%1d:N%1d:", $4, $7);
+ generate (genstr);
+ }
+ statement
+ {
+ sprintf (genstr, "J%1d:N%1d:",
+ continue_label, break_label);
+ generate (genstr);
+ break_label = $1;
+ continue_label = $<i_value>9;
+ }
+ | If '(' expression ')'
+ {
+ $3 = if_label;
+ if_label = next_label++;
+ sprintf (genstr, "Z%1d:", if_label);
+ generate (genstr);
+ }
+ statement opt_else
+ {
+ sprintf (genstr, "N%1d:", if_label);
+ generate (genstr);
+ if_label = $3;
+ }
+ | While
+ {
+ $1 = next_label++;
+ sprintf (genstr, "N%1d:", $1);
+ generate (genstr);
+ }
+ '(' expression
+ {
+ $4 = break_label;
+ break_label = next_label++;
+ sprintf (genstr, "Z%1d:", break_label);
+ generate (genstr);
+ }
+ ')' statement
+ {
+ sprintf (genstr, "J%1d:N%1d:", $1, break_label);
+ generate (genstr);
+ break_label = $4;
+ }
+ | '{' statement_list '}'
+ { $$ = 0; }
+ | Print
+ { warn ("print statement"); }
+ print_list
+ ;
+print_list : print_element
+ | print_element ',' print_list
+ ;
+print_element : STRING
+ {
+ generate ("O");
+ generate ($1);
+ free ($1);
+ }
+ | expression
+ { generate ("P"); }
+ ;
+opt_else : /* nothing */
+ | Else
+ {
+ warn ("else clause in if statement");
+ $1 = next_label++;
+ sprintf (genstr, "J%d:N%1d:", $1, if_label);
+ generate (genstr);
+ if_label = $1;
+ }
+ statement
+function : Define NAME '(' opt_parameter_list ')' '{'
+ NEWLINE opt_auto_define_list
+ {
+ /* Check auto list against parameter list? */
+ check_params ($4,$8);
+ sprintf (genstr, "F%d,%s.%s[",
+ lookup($2,FUNCTDEF),
+ arg_str ($4), arg_str ($8));
+ generate (genstr);
+ free_args ($4);
+ free_args ($8);
+ $1 = next_label;
+ next_label = 1;
+ }
+ statement_list /* NEWLINE */ '}'
+ {
+ generate ("0R]");
+ next_label = $1;
+ }
+ ;
+opt_parameter_list : /* empty */
+ { $$ = NULL; }
+ | define_list
+ ;
+opt_auto_define_list : /* empty */
+ { $$ = NULL; }
+ | Auto define_list NEWLINE
+ { $$ = $2; }
+ | Auto define_list ';'
+ { $$ = $2; }
+ ;
+define_list : NAME
+ { $$ = nextarg (NULL, lookup ($1,SIMPLE)); }
+ | NAME '[' ']'
+ { $$ = nextarg (NULL, lookup ($1,ARRAY)); }
+ | define_list ',' NAME
+ { $$ = nextarg ($1, lookup ($3,SIMPLE)); }
+ | define_list ',' NAME '[' ']'
+ { $$ = nextarg ($1, lookup ($3,ARRAY)); }
+ ;
+opt_argument_list : /* empty */
+ { $$ = NULL; }
+ | argument_list
+ ;
+argument_list : expression
+ {
+ if ($1 > 1) warn ("comparison in argument");
+ $$ = nextarg (NULL,0);
+ }
+ | NAME '[' ']'
+ {
+ sprintf (genstr, "K%d:", -lookup ($1,ARRAY));
+ generate (genstr);
+ $$ = nextarg (NULL,1);
+ }
+ | argument_list ',' expression
+ {
+ if ($3 > 1) warn ("comparison in argument");
+ $$ = nextarg ($1,0);
+ }
+ | argument_list ',' NAME '[' ']'
+ {
+ sprintf (genstr, "K%d:", -lookup ($3,ARRAY));
+ generate (genstr);
+ $$ = nextarg ($1,1);
+ }
+ ;
+opt_expression : /* empty */
+ {
+ $$ = -1;
+ warn ("Missing expression in for statement");
+ }
+ | expression
+ ;
+return_expression : /* empty */
+ {
+ $$ = 0;
+ generate ("0");
+ }
+ | expression
+ {
+ if ($1 > 1)
+ warn ("comparison in return expresion");
+ }
+ ;
+expression : named_expression ASSIGN_OP
+ {
+ if ($2 != '=')
+ {
+ if ($1 < 0)
+ sprintf (genstr, "DL%d:", -$1);
+ else
+ sprintf (genstr, "l%d:", $1);
+ generate (genstr);
+ }
+ }
+ expression
+ {
+ if ($4 > 1) warn("comparison in assignment");
+ if ($2 != '=')
+ {
+ sprintf (genstr, "%c", $2);
+ generate (genstr);
+ }
+ if ($1 < 0)
+ sprintf (genstr, "S%d:", -$1);
+ else
+ sprintf (genstr, "s%d:", $1);
+ generate (genstr);
+ $$ = 0;
+ }
+ ;
+ | expression AND
+ {
+ warn("&& operator");
+ $2 = next_label++;
+ sprintf (genstr, "DZ%d:p", $2);
+ generate (genstr);
+ }
+ expression
+ {
+ sprintf (genstr, "DZ%d:p1N%d:", $2, $2);
+ generate (genstr);
+ $$ = $1 | $4;
+ }
+ | expression OR
+ {
+ warn("|| operator");
+ $2 = next_label++;
+ sprintf (genstr, "B%d:", $2);
+ generate (genstr);
+ }
+ expression
+ {
+ int tmplab;
+ tmplab = next_label++;
+ sprintf (genstr, "B%d:0J%d:N%d:1N%d:",
+ $2, tmplab, $2, tmplab);
+ generate (genstr);
+ $$ = $1 | $4;
+ }
+ | NOT expression
+ {
+ $$ = $2;
+ warn("! operator");
+ generate ("!");
+ }
+ | expression REL_OP expression
+ {
+ $$ = 3;
+ switch (*($2))
+ {
+ case '=':
+ generate ("=");
+ break;
+
+ case '!':
+ generate ("#");
+ break;
+
+ case '<':
+ if ($2[1] == '=')
+ generate ("{");
+ else
+ generate ("<");
+ break;
+
+ case '>':
+ if ($2[1] == '=')
+ generate ("}");
+ else
+ generate (">");
+ break;
+ }
+ }
+ | expression '+' expression
+ {
+ generate ("+");
+ $$ = $1 | $3;
+ }
+ | expression '-' expression
+ {
+ generate ("-");
+ $$ = $1 | $3;
+ }
+ | expression MUL_OP expression
+ {
+ genstr[0] = $2;
+ genstr[1] = 0;
+ generate (genstr);
+ $$ = $1 | $3;
+ }
+ | expression '^' expression
+ {
+ generate ("^");
+ $$ = $1 | $3;
+ }
+ | '-' expression %prec UNARY_MINUS
+ {
+ generate ("n");
+ $$ = $2;
+ }
+ | named_expression
+ {
+ $$ = 1;
+ if ($1 < 0)
+ sprintf (genstr, "L%d:", -$1);
+ else
+ sprintf (genstr, "l%d:", $1);
+ generate (genstr);
+ }
+ | NUMBER
+ {
+ int len = strlen($1);
+ $$ = 1;
+ if (len == 1 && *$1 == '0')
+ generate ("0");
+ else if (len == 1 && *$1 == '1')
+ generate ("1");
+ else
+ {
+ generate ("K");
+ generate ($1);
+ generate (":");
+ }
+ free ($1);
+ }
+ | '(' expression ')'
+ { $$ = $2 | 1; }
+ | NAME '(' opt_argument_list ')'
+ {
+ $$ = 1;
+ if ($3 != NULL)
+ {
+ sprintf (genstr, "C%d,%s:",
+ lookup ($1,FUNCT),
+ call_str ($3));
+ free_args ($3);
+ }
+ else
+ {
+ sprintf (genstr, "C%d:", lookup ($1,FUNCT));
+ }
+ generate (genstr);
+ }
+ | INCR_DECR named_expression
+ {
+ $$ = 1;
+ if ($2 < 0)
+ {
+ if ($1 == '+')
+ sprintf (genstr, "DA%d:L%d:", -$2, -$2);
+ else
+ sprintf (genstr, "DM%d:L%d:", -$2, -$2);
+ }
+ else
+ {
+ if ($1 == '+')
+ sprintf (genstr, "i%d:l%d:", $2, $2);
+ else
+ sprintf (genstr, "d%d:l%d:", $2, $2);
+ }
+ generate (genstr);
+ }
+ | named_expression INCR_DECR
+ {
+ $$ = 1;
+ if ($1 < 0)
+ {
+ sprintf (genstr, "DL%d:x", -$1);
+ generate (genstr);
+ if ($2 == '+')
+ sprintf (genstr, "A%d:", -$1);
+ else
+ sprintf (genstr, "M%d:", -$1);
+ }
+ else
+ {
+ sprintf (genstr, "l%d:", $1);
+ generate (genstr);
+ if ($2 == '+')
+ sprintf (genstr, "i%d:", $1);
+ else
+ sprintf (genstr, "d%d:", $1);
+ }
+ generate (genstr);
+ }
+ | Length '(' expression ')'
+ { generate ("cL"); $$ = 1;}
+ | Sqrt '(' expression ')'
+ { generate ("cR"); $$ = 1;}
+ | Scale '(' expression ')'
+ { generate ("cS"); $$ = 1;}
+ | Read '(' ')'
+ {
+ warn ("read function");
+ generate ("cI"); $$ = 1;
+ }
+ ;
+named_expression : NAME
+ { $$ = lookup($1,SIMPLE); }
+ | NAME '[' expression ']'
+ {
+ if ($3 > 1) warn("comparison in subscript");
+ $$ = lookup($1,ARRAY);
+ }
+ | Ibase
+ { $$ = 0; }
+ | Obase
+ { $$ = 1; }
+ | Scale
+ { $$ = 2; }
+ | Last
+ { $$ = 3;
+ warn ("Last variable");
+ }
+ ;
+%%
diff --git a/gnu/usr.bin/bc/bcdefs.h b/gnu/usr.bin/bc/bcdefs.h
index 0f2c5e1..455530d 100644
--- a/gnu/usr.bin/bc/bcdefs.h
+++ b/gnu/usr.bin/bc/bcdefs.h
@@ -1,7 +1,7 @@
/* bcdefs.h: The single file to include all constants and type definitions. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gnu/usr.bin/bc/const.h b/gnu/usr.bin/bc/const.h
index a4ab2ac..1b55adc 100644
--- a/gnu/usr.bin/bc/const.h
+++ b/gnu/usr.bin/bc/const.h
@@ -1,7 +1,7 @@
/* const.h: Constants for bc. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -71,9 +71,13 @@
#define FALSE 0
#define TRUE 1
-#define SIMPLE 0
-#define ARRAY 1
-#define FUNCT 2
+
+/* for use with lookup (). */
+#define SIMPLE 0
+#define ARRAY 1
+#define FUNCT 2
+#define FUNCTDEF 3
+
#define EXTERN extern
#ifdef __STDC__
#define CONST const
diff --git a/gnu/usr.bin/bc/execute.c b/gnu/usr.bin/bc/execute.c
index a2f0e00..1a89506 100644
--- a/gnu/usr.bin/bc/execute.c
+++ b/gnu/usr.bin/bc/execute.c
@@ -1,7 +1,7 @@
/* execute.c - run a bc program. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -213,11 +213,13 @@ execute ()
if (ch == '"') break;
switch (ch)
{
+ case 'a': out_char (007); break;
+ case 'b': out_char ('\b'); break;
+ case 'f': out_char ('\f'); break;
case 'n': out_char ('\n'); break;
- case 't': out_char ('\t'); break;
+ case 'q': out_char ('"'); break;
case 'r': out_char ('\r'); break;
- case 'b': out_char (007); break;
- case 'f': out_char ('\f'); break;
+ case 't': out_char ('\t'); break;
case '\\': out_char ('\\'); break;
default: break;
}
diff --git a/gnu/usr.bin/bc/global.c b/gnu/usr.bin/bc/global.c
index b00a989..fc44ff6 100644
--- a/gnu/usr.bin/bc/global.c
+++ b/gnu/usr.bin/bc/global.c
@@ -1,7 +1,7 @@
/* global.c: This defines the global variables. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gnu/usr.bin/bc/global.h b/gnu/usr.bin/bc/global.h
index 550afb1..2b339a8 100644
--- a/gnu/usr.bin/bc/global.h
+++ b/gnu/usr.bin/bc/global.h
@@ -1,7 +1,7 @@
/* global.h: The global variables for bc. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,24 +27,41 @@
*************************************************************************/
-/* For the current "break level" and if statements. */
+/* The current break level's label. */
EXTERN int break_label;
+
+/* The current if statement's else label or label after else. */
EXTERN int if_label;
+
+/* The current for statement label for continuing the loop. */
EXTERN int continue_label;
-/* Label numbers. */
+/* Next available label number. */
EXTERN int next_label;
-/* Used for "code" generation. */
+/* Byte code character storage. Used in many places for generation of code. */
EXTERN char genstr[80];
+
+/* Count of characters printed to the output in compile_only mode. */
EXTERN int out_count;
+
+/* Have we generated any code since the last initialization of the code
+ generator. */
EXTERN char did_gen;
-/* Interactive and other flags. */
+/* Is this run an interactive execution. (Is stdin a terminal?) */
EXTERN char interactive;
+
+/* Just generate the byte code. -c flag. */
EXTERN char compile_only;
+
+/* Load the standard math functions. -l flag. */
EXTERN char use_math;
+
+/* Give a warning on use of any non-standard feature (non-POSIX). -w flag. */
EXTERN char warn_not_std;
+
+/* Accept POSIX bc only! -s flag. */
EXTERN char std_only;
/* global variables for the bc machine. All will be dynamic in size.*/
diff --git a/gnu/usr.bin/bc/libmath.b b/gnu/usr.bin/bc/libmath.b
deleted file mode 100644
index 30d9532..0000000
--- a/gnu/usr.bin/bc/libmath.b
+++ /dev/null
@@ -1,255 +0,0 @@
-/* libmath.b for bc for minix. */
-
-/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License , or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- You may contact the author by:
- e-mail: phil@cs.wwu.edu
- us-mail: Philip A. Nelson
- Computer Science Department, 9062
- Western Washington University
- Bellingham, WA 98226-9062
-
-*************************************************************************/
-
-
-scale = 20
-
-/* Uses the fact that e^x = (e^(x/2))^2
- When x is small enough, we use the series:
- e^x = 1 + x + x^2/2! + x^3/3! + ...
-*/
-
-define e(x) {
- auto a, d, e, f, i, m, v, z
-
- /* Check the sign of x. */
- if (x<0) {
- m = 1
- x = -x
- }
-
- /* Precondition x. */
- z = scale;
- scale = 4 + z + .44*x;
- while (x > 1) {
- f += 1;
- x /= 2;
- }
-
- /* Initialize the variables. */
- v = 1+x
- a = x
- d = 1
-
- for (i=2; 1; i++) {
- e = (a *= x) / (d *= i)
- if (e == 0) {
- if (f>0) while (f--) v = v*v;
- scale = z
- if (m) return (1/v);
- return (v/1);
- }
- v += e
- }
-}
-
-/* Natural log. Uses the fact that ln(x^2) = 2*ln(x)
- The series used is:
- ln(x) = 2(a+a^3/3+a^5/5+...) where a=(x-1)/(x+1)
-*/
-
-define l(x) {
- auto e, f, i, m, n, v, z
-
- /* return something for the special case. */
- if (x <= 0) return (1 - 10^scale)
-
- /* Precondition x to make .5 < x < 2.0. */
- z = scale;
- scale += 4;
- f = 2;
- i=0
- while (x >= 2) { /* for large numbers */
- f *= 2;
- x = sqrt(x);
- }
- while (x <= .5) { /* for small numbers */
- f *= 2;
- x = sqrt(x);
- }
-
- /* Set up the loop. */
- v = n = (x-1)/(x+1)
- m = n*n
-
- /* Sum the series. */
- for (i=3; 1; i+=2) {
- e = (n *= m) / i
- if (e == 0) {
- v = f*v
- scale = z
- return (v/1)
- }
- v += e
- }
-}
-
-/* Sin(x) uses the standard series:
- sin(x) = x - x^3/3! + x^5/5! - x^7/7! ... */
-
-define s(x) {
- auto e, i, m, n, s, v, z
-
- /* precondition x. */
- z = scale
- scale = 1.1*z + 1;
- v = a(1)
- if (x < 0) {
- m = 1;
- x = -x;
- }
- scale = 0
- n = (x / v + 2 )/4
- x = x - 4*n*v
- if (n%2) x = -x
-
- /* Do the loop. */
- scale = z + 2;
- v = e = x
- s = -x*x
- for (i=3; 1; i+=2) {
- e *= s/(i*(i-1))
- if (e == 0) {
- scale = z
- if (m) return (-v/1);
- return (v/1);
- }
- v += e
- }
-}
-
-/* Cosine : cos(x) = sin(x+pi/2) */
-define c(x) {
- auto v;
- scale += 1;
- v = s(x+a(1)*2);
- scale -= 1;
- return (v/1);
-}
-
-/* Arctan: Using the formula:
- atan(x) = atan(c) + atan((x-c)/(1+xc)) for a small c (.2 here)
- For under .2, use the series:
- atan(x) = x - x^3/3 + x^5/5 - x^7/7 + ... */
-
-define a(x) {
- auto a, e, f, i, m, n, s, v, z
-
- /* Special case and for fast answers */
- if (x==1) {
- if (scale <= 25) return (.7853981633974483096156608/1)
- if (scale <= 40) return (.7853981633974483096156608458198757210492/1)
- if (scale <= 60) \
- return (.785398163397448309615660845819875721049292349843776455243736/1)
- }
- if (x==.2) {
- if (scale <= 25) return (.1973955598498807583700497/1)
- if (scale <= 40) return (.1973955598498807583700497651947902934475/1)
- if (scale <= 60) \
- return (.197395559849880758370049765194790293447585103787852101517688/1)
- }
-
- /* Negative x? */
- if (x<0) {
- m = 1;
- x = -x;
- }
-
- /* Save the scale. */
- z = scale;
-
- /* Note: a and f are known to be zero due to being auto vars. */
- /* Calculate atan of a known number. */
- if (x > .2) {
- scale = z+4;
- a = a(.2);
- }
-
- /* Precondition x. */
- scale = z+2;
- while (x > .2) {
- f += 1;
- x = (x-.2) / (1+x*.2);
- }
-
- /* Initialize the series. */
- v = n = x;
- s = -x*x;
-
- /* Calculate the series. */
- for (i=3; 1; i+=2) {
- e = (n *= s) / i;
- if (e == 0) {
- scale = z;
- if (m) return ((f*a+v)/-1);
- return ((f*a+v)/1);
- }
- v += e
- }
-}
-
-
-/* Bessel function of integer order. Uses the following:
- j(-n,x) = (-1)^n*j(n,x)
- j(n,x) = x^n/(2^n*n!) * (1 - x^2/(2^2*1!*(n+1)) + x^4/(2^4*2!*(n+1)*(n+2))
- - x^6/(2^6*3!*(n+1)*(n+2)*(n+3)) .... )
-*/
-define j(n,x) {
- auto a, d, e, f, i, m, s, v, z
-
- /* Make n an integer and check for negative n. */
- z = scale;
- scale = 0;
- n = n/1;
- if (n<0) {
- n = -n;
- if (n%2 == 1) m = 1;
- }
-
- /* Compute the factor of x^n/(2^n*n!) */
- f = 1;
- for (i=2; i<=n; i++) f = f*i;
- scale = 1.5*z;
- f = x^n / 2^n / f;
-
- /* Initialize the loop .*/
- v = e = 1;
- s = -x*x/4
- scale = 1.5*z
-
- /* The Loop.... */
- for (i=1; 1; i++) {
- e = e * s / i / (n+i);
- if (e == 0) {
- scale = z
- if (m) return (-f*v/1);
- return (f*v/1);
- }
- v += e;
- }
-}
diff --git a/gnu/usr.bin/bc/load.c b/gnu/usr.bin/bc/load.c
index 144ae0e..96b248a 100644
--- a/gnu/usr.bin/bc/load.c
+++ b/gnu/usr.bin/bc/load.c
@@ -1,7 +1,7 @@
/* load.c: This code "loads" code into the code segments. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gnu/usr.bin/bc/main.c b/gnu/usr.bin/bc/main.c
index ed8643a..57bcd8c 100644
--- a/gnu/usr.bin/bc/main.c
+++ b/gnu/usr.bin/bc/main.c
@@ -1,7 +1,7 @@
/* main.c: The main program for bc. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gnu/usr.bin/bc/math.h b/gnu/usr.bin/bc/math.h
index a1fc146..fb5b03b 100644
--- a/gnu/usr.bin/bc/math.h
+++ b/gnu/usr.bin/bc/math.h
@@ -1,40 +1,40 @@
"@iK20:s2:p@r\
-@iF1,4.5,6,7,8,9,10,11,12[l4:0<Z0:1s10:pl4:ns4:pN0:l2:s12:pK4\
-:l12:+K.44:l4:*+s2:pN1:l4:1>Z2:l8:1+s8:pl4:K2:/s4:pJ1:N2:1l4:\
-+s11:pl4:s5:p1s6:pK2:s9:pN4:1B5:J3:N6:l9:i9:pJ4:N5:l5:l4:*s5:\
-l6:l9:*s6:/s7:pl7:0=Z7:l8:0>Z8:N9:l8:d8:Z10:l11:l11:*s11:pJ9:N10:\
-N8:l12:s2:pl10:Z11:1l11:/RN11:l11:1/RN7:l11:l7:+s11:pJ6:N3:0R]\
+@iF1,4.5,6,7,8,9,10,11,12,13[l4:0<Z1:1s10:pl4:ns4:pN1:l2:s13:\
+pK6:l13:+K.44:l4:*+s11:pl4:cS1+s2:pN2:l4:1>Z3:l8:1+s8:pl4:K2:\
+/s4:pl2:1+s2:pJ2:N3:l11:s2:p1l4:+s12:pl4:s5:p1s6:pK2:s9:pN5:1\
+B6:J4:N7:l9:i9:pJ5:N6:l5:l4:*s5:l6:l9:*s6:/s7:pl7:0=Z8:l8:0>Z9:\
+N10:l8:d8:Z11:l12:l12:*s12:pJ10:N11:N9:l13:s2:pl10:Z12:1l12:/\
+RN12:l12:1/RN8:l12:l7:+s12:pJ7:N4:0R]@r\
+@iF2,4.7,8,9,10,11,12,13[l4:0{Z1:1K10:l2:^-RN1:l2:s13:pK6:l2:\
++s2:pK2:s8:p0s9:pN2:l4:K2:}Z3:l8:K2:*s8:pl4:cRs4:pJ2:N3:N4:l4:\
+K.5:{Z5:l8:K2:*s8:pl4:cRs4:pJ4:N5:l4:1-l4:1+/s11:s12:pl11:l11:\
+*s10:pK3:s9:pN7:1B8:J6:N9:l9:K2:+s9:pJ7:N8:l11:l10:*s11:l9:/s7:\
+pl7:0=Z10:l8:l12:*s12:pl13:s2:pl12:1/RN10:l12:l7:+s12:pJ9:N6:\
+0R]@r\
+@iF3,4.7,9,10,11,14,12,13[l2:s13:pK1.1:l13:*K2:+s2:p1C4,0:s12:\
+pl4:0<Z1:1s10:pl4:ns4:pN1:0s2:pl4:l12:/K2:+K4:/s11:pl4:K4:l11:\
+*l12:*-s4:pl11:K2:%Z2:l4:ns4:pN2:l13:K2:+s2:pl4:s7:s12:pl4:nl4:\
+*s14:pK3:s9:pN4:1B5:J3:N6:l9:K2:+s9:pJ4:N5:l7:l14:l9:l9:1-*/*\
+s7:pl7:0=Z7:l13:s2:pl10:Z8:l12:n1/RN8:l12:1/RN7:l12:l7:+s12:p\
+J6:N3:0R]@r\
+@iF5,4.12[l2:1+s2:pl4:1C4,0:K2:*+C3,0:s12:pl2:1-s2:pl12:1/R0R]\
@r\
-@iF2,4.7,8,9,10,13,11,12[l4:0{Z0:1K10:l2:^-RN0:l2:s12:pl2:K4:\
-+s2:pK2:s8:p0s9:pN1:l4:K2:}Z2:l8:K2:*s8:pl4:cRs4:pJ1:N2:N3:l4:\
-K.5:{Z4:l8:K2:*s8:pl4:cRs4:pJ3:N4:l4:1-l4:1+/s13:s11:pl13:l13:\
-*s10:pK3:s9:pN6:1B7:J5:N8:l9:K2:+s9:pJ6:N7:l13:l10:*s13:l9:/s7:\
-pl7:0=Z9:l8:l11:*s11:pl12:s2:pl11:1/RN9:l11:l7:+s11:pJ8:N5:0R]\
-@r\
-@iF3,4.7,9,10,13,14,11,12[l2:s12:pK1.1:l12:*1+s2:p1C4,0:s11:p\
-l4:0<Z0:1s10:pl4:ns4:pN0:0s2:pl4:l11:/K2:+K4:/s13:pl4:K4:l13:\
-*l11:*-s4:pl13:K2:%Z1:l4:ns4:pN1:l12:K2:+s2:pl4:s7:s11:pl4:nl4:\
-*s14:pK3:s9:pN3:1B4:J2:N5:l9:K2:+s9:pJ3:N4:l7:l14:l9:l9:1-*/*\
-s7:pl7:0=Z6:l12:s2:pl10:Z7:l11:n1/RN7:l11:1/RN6:l11:l7:+s11:p\
-J5:N2:0R]@r\
-@iF5,4.11[l2:1+s2:pl4:1C4,0:K2:*+C3,0:s11:pl2:1-s2:pl11:1/R0R]\
-@r\
-@iF4,4.5,7,8,9,10,13,14,11,12[l4:1=Z0:l2:K25:{Z1:K.7853981633974483096156608\
-:1/RN1:l2:K40:{Z2:K.7853981633974483096156608458198757210492:\
-1/RN2:l2:K60:{Z3:K.785398163397448309615660845819875721049292349843776455243736\
-:1/RN3:N0:l4:K.2:=Z4:l2:K25:{Z5:K.1973955598498807583700497:1\
-/RN5:l2:K40:{Z6:K.1973955598498807583700497651947902934475:1/\
-RN6:l2:K60:{Z7:K.197395559849880758370049765194790293447585103787852101517688\
-:1/RN7:N4:l4:0<Z8:1s10:pl4:ns4:pN8:l2:s12:pl4:K.2:>Z9:l12:K4:\
-+s2:pK.2:C4,0:s5:pN9:l12:K2:+s2:pN10:l4:K.2:>Z11:l8:1+s8:pl4:\
-K.2:-1l4:K.2:*+/s4:pJ10:N11:l4:s13:s11:pl4:nl4:*s14:pK3:s9:pN13:\
-1B14:J12:N15:l9:K2:+s9:pJ13:N14:l13:l14:*s13:l9:/s7:pl7:0=Z16:\
-l12:s2:pl10:Z17:l8:l5:*l11:+1n/RN17:l8:l5:*l11:+1/RN16:l11:l7:\
-+s11:pJ15:N12:0R]@r\
-@iF6,13,4.5,6,7,8,9,10,14,11,12[l2:s12:p0s2:pl13:1/s13:pl13:0\
-<Z0:l13:ns13:pl13:K2:%1=Z1:1s10:pN1:N0:1s8:pK2:s9:pN3:l9:l13:\
-{B4:J2:N5:l9:i9:pJ3:N4:l8:l9:*s8:pJ5:N2:K1.5:l12:*s2:pl4:l13:\
-^K2:l13:^/l8:/s8:p1s7:s11:pl4:nl4:*K4:/s14:pK1.5:l12:*s2:p1s9:\
-pN7:1B8:J6:N9:l9:i9:pJ7:N8:l7:l14:*l9:/l13:l9:+/s7:pl7:0=Z10:\
-l12:s2:pl10:Z11:l8:nl11:*1/RN11:l8:l11:*1/RN10:l11:l7:+s11:pJ9:N6:\
+@iF4,4.5,7,8,9,10,11,14,12,13[1s10:pl4:0<Z1:1ns10:pl4:ns4:pN1:\
+l4:1=Z2:l2:K25:{Z3:K.7853981633974483096156608:l10:/RN3:l2:K40\
+:{Z4:K.7853981633974483096156608458198757210492:l10:/RN4:l2:K\
+60:{Z5:K.785398163397448309615660845819875721049292349843776455243736\
+:l10:/RN5:N2:l4:K.2:=Z6:l2:K25:{Z7:K.1973955598498807583700497\
+:l10:/RN7:l2:K40:{Z8:K.1973955598498807583700497651947902934475\
+:l10:/RN8:l2:K60:{Z9:K.197395559849880758370049765194790293447585103787852101517688\
+:l10:/RN9:N6:l2:s13:pl4:K.2:>Z10:l13:K5:+s2:pK.2:C4,0:s5:pN10:\
+l13:K3:+s2:pN11:l4:K.2:>Z12:l8:1+s8:pl4:K.2:-1l4:K.2:*+/s4:pJ11:N12:\
+l4:s11:s12:pl4:nl4:*s14:pK3:s9:pN14:1B15:J13:N16:l9:K2:+s9:pJ14:N15:\
+l11:l14:*s11:l9:/s7:pl7:0=Z17:l13:s2:pl8:l5:*l12:+l10:/RN17:l12:\
+l7:+s12:pJ16:N13:0R]@r\
+@iF6,11,4.5,6,7,8,9,10,14,12,13[l2:s13:p0s2:pl11:1/s11:pl11:0\
+<Z1:l11:ns11:pl11:K2:%1=Z2:1s10:pN2:N1:1s8:pK2:s9:pN4:l9:l11:\
+{B5:J3:N6:l9:i9:pJ4:N5:l8:l9:*s8:pJ6:N3:K1.5:l13:*s2:pl4:l11:\
+^K2:l11:^/l8:/s8:p1s7:s12:pl4:nl4:*K4:/s14:pK1.5:l13:*s2:p1s9:\
+pN8:1B9:J7:N10:l9:i9:pJ8:N9:l7:l14:*l9:/l11:l9:+/s7:pl7:0=Z11:\
+l13:s2:pl10:Z12:l8:nl12:*1/RN12:l8:l12:*1/RN11:l12:l7:+s12:pJ10:N7:\
0R]@r"
diff --git a/gnu/usr.bin/bc/number.c b/gnu/usr.bin/bc/number.c
index 336ad11..5f3aa39 100644
--- a/gnu/usr.bin/bc/number.c
+++ b/gnu/usr.bin/bc/number.c
@@ -1,7 +1,7 @@
/* number.c: Implements arbitrary precision numbers. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -995,15 +995,23 @@ bc_raise (num1, num2, result, scale)
neg = FALSE;
rscale = MIN (num1->n_scale*exponent, MAX(scale, num1->n_scale));
}
- temp = copy_num (_one_);
+
+ /* Set initial value of temp. */
power = copy_num (num1);
+ while ((exponent & 1) == 0)
+ {
+ bc_multiply (power, power, &power, rscale);
+ exponent = exponent >> 1;
+ }
+ temp = copy_num (power);
+ exponent = exponent >> 1;
/* Do the calculation. */
- while (exponent != 0)
+ while (exponent > 0)
{
- if (exponent & 1 != 0)
- bc_multiply (temp, power, &temp, rscale);
bc_multiply (power, power, &power, rscale);
+ if ((exponent & 1) == 1)
+ bc_multiply (temp, power, &temp, rscale);
exponent = exponent >> 1;
}
@@ -1057,7 +1065,6 @@ bc_sqrt (num, scale)
/* Initialize the variables. */
rscale = MAX (scale, (*num)->n_scale);
- cscale = rscale + 2;
init_num (&guess);
init_num (&guess1);
point5 = new_num (1,1);
@@ -1073,14 +1080,15 @@ bc_sqrt (num, scale)
/* The number is greater than 1. Guess should start at 10^(exp/2). */
int2num (&guess,10);
int2num (&guess1,(*num)->n_len);
- bc_multiply (guess1, point5, &guess1, rscale);
+ bc_multiply (guess1, point5, &guess1, 0);
guess1->n_scale = 0;
- bc_raise (guess, guess1, &guess, rscale);
+ bc_raise (guess, guess1, &guess, 0);
free_num (&guess1);
}
/* Find the square root using Newton's algorithm. */
done = FALSE;
+ cscale = 2;
while (!done)
{
free_num (&guess1);
@@ -1089,7 +1097,11 @@ bc_sqrt (num, scale)
bc_add (guess,guess1,&guess);
bc_multiply (guess,point5,&guess,cscale);
cmp_res = _do_compare (guess,guess1,FALSE,TRUE);
- if (cmp_res == 0) done = TRUE;
+ if (cmp_res == 0)
+ if (cscale < rscale+1)
+ cscale = MIN (cscale*3, rscale+1);
+ else
+ done = TRUE;
}
/* Assign the number and clean up. */
@@ -1198,6 +1210,9 @@ out_num (num, o_base, out_char)
init_num (&cur_dig);
init_num (&base);
bc_sub (num, int_part, &frac_part);
+ /* Make the INT_PART and FRAC_PART positive. */
+ int_part->n_sign = PLUS;
+ frac_part->n_sign = PLUS;
int2num (&base, o_base);
init_num (&max_o_digit);
int2num (&max_o_digit, o_base-1);
@@ -1273,7 +1288,6 @@ p_n (num)
bc_num num;
{
out_num (num, 10, out_char);
- return 0;
}
diff --git a/gnu/usr.bin/bc/number.h b/gnu/usr.bin/bc/number.h
index 79a340f..325612e 100644
--- a/gnu/usr.bin/bc/number.h
+++ b/gnu/usr.bin/bc/number.h
@@ -1,7 +1,7 @@
/* number.h: Arbitrary precision numbers header file. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gnu/usr.bin/bc/proto.h b/gnu/usr.bin/bc/proto.h
index f2aa490..275a759 100644
--- a/gnu/usr.bin/bc/proto.h
+++ b/gnu/usr.bin/bc/proto.h
@@ -1,7 +1,7 @@
/* proto.h: Prototype function definitions for "external" functions. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -70,7 +70,8 @@ _PROTOTYPE(void assign, (int c_code));
/* From util.c */
_PROTOTYPE(char *strcopyof, (char *str));
_PROTOTYPE(arg_list *nextarg, (arg_list *args, int val));
-_PROTOTYPE(char *arg_str, (arg_list *args, int));
+_PROTOTYPE(char *arg_str, (arg_list *args));
+_PROTOTYPE(char *call_str, (arg_list *args));
_PROTOTYPE(void free_args, (arg_list *args));
_PROTOTYPE(void check_params, (arg_list *params, arg_list *autos));
_PROTOTYPE(void init_gen, (void));
diff --git a/gnu/usr.bin/bc/scan.c b/gnu/usr.bin/bc/scan.c
deleted file mode 100644
index 6bff451..0000000
--- a/gnu/usr.bin/bc/scan.c
+++ /dev/null
@@ -1,1368 +0,0 @@
-/* A lexical scanner generated by flex */
-
-/* scanner skeleton version:
- * $Header: /home/ncvs/src/gnu/usr.bin/bc/scan.c,v 1.1.1.1 1993/06/19 00:26:18 paul Exp $
- */
-
-#define FLEX_SCANNER
-
-#include <stdio.h>
-
-
-/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
-#ifdef c_plusplus
-#ifndef __cplusplus
-#define __cplusplus
-#endif
-#endif
-
-
-#ifdef __cplusplus
-
-#include <stdlib.h>
-#include <osfcn.h>
-
-/* use prototypes in function declarations */
-#define YY_USE_PROTOS
-
-/* the "const" storage-class-modifier is valid */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-#ifdef __STDC__
-
-#ifdef __GNUC__
-#include <stddef.h>
-void *malloc( size_t );
-void free( void* );
-#else
-#include <stdlib.h>
-#endif /* __GNUC__ */
-
-#define YY_USE_PROTOS
-#define YY_USE_CONST
-
-#endif /* __STDC__ */
-#endif /* ! __cplusplus */
-
-
-#ifdef __TURBOC__
-#define YY_USE_CONST
-#endif
-
-
-#ifndef YY_USE_CONST
-#define const
-#endif
-
-
-#ifdef YY_USE_PROTOS
-#define YY_PROTO(proto) proto
-#else
-#define YY_PROTO(proto) ()
-/* we can't get here if it's an ANSI C compiler, or a C++ compiler,
- * so it's got to be a K&R compiler, and therefore there's no standard
- * place from which to include these definitions
- */
-/* char *malloc();
-int free(); */
-int read();
-#endif
-
-
-/* amount of stuff to slurp up with each read */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* returned upon end-of-file */
-#define YY_END_TOK 0
-
-/* copy whatever the last rule matched to the standard output */
-
-/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
-/* this used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite()
- */
-#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
-
-/* gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#define YY_INPUT(buf,result,max_size) \
- if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
- YY_FATAL_ERROR( "read() in flex scanner failed" );
-#define YY_NULL 0
-
-/* no semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#define yyterminate() return ( YY_NULL )
-
-/* report a fatal error */
-
-/* The funky do-while is used to turn this macro definition into
- * a single C statement (which needs a semi-colon terminator).
- * This avoids problems with code like:
- *
- * if ( something_happens )
- * YY_FATAL_ERROR( "oops, the something happened" );
- * else
- * everything_okay();
- *
- * Prior to using the do-while the compiler would get upset at the
- * "else" because it interpreted the "if" statement as being all
- * done when it reached the ';' after the YY_FATAL_ERROR() call.
- */
-
-#define YY_FATAL_ERROR(msg) \
- do \
- { \
- (void) fputs( msg, stderr ); \
- (void) putc( '\n', stderr ); \
- exit( 1 ); \
- } \
- while ( 0 )
-
-/* default yywrap function - always treat EOF as an EOF */
-#define yywrap() 1
-
-/* enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN
- */
-#define BEGIN yy_start = 1 + 2 *
-
-/* action number for EOF rule of a given start state */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* special action meaning "start processing a new file" */
-#define YY_NEW_FILE \
- do \
- { \
- yy_init_buffer( yy_current_buffer, yyin ); \
- yy_load_buffer_state(); \
- } \
- while ( 0 )
-
-/* default declaration of generated scanner - a define so the user can
- * easily add parameters
- */
-#define YY_DECL int yylex YY_PROTO(( void ))
-
-/* code executed at the end of each rule */
-#define YY_BREAK break;
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-#ifndef YY_BUF_SIZE
-#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
-#endif
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
-#define YY_CHAR unsigned char
-# line 1 "scan.l"
-#define INITIAL 0
-# line 2 "scan.l"
-/* scan.l: the (f)lex description file for the scanner. */
-
-/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License , or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- You may contact the author by:
- e-mail: phil@cs.wwu.edu
- us-mail: Philip A. Nelson
- Computer Science Department, 9062
- Western Washington University
- Bellingham, WA 98226-9062
-
-*************************************************************************/
-
-#include "bcdefs.h"
-#include "y.tab.h"
-#include "global.h"
-#include "proto.h"
-
-/* Using flex, we can ask for a smaller input buffer. With lex, this
- does nothing! */
-
-#ifdef SMALL_BUF
-#undef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 512
-#endif
-
-/* We want to define our own yywrap. */
-#undef yywrap
-_PROTOTYPE(int yywrap, (void));
-
-/* MINIX returns from read with < 0 if SIGINT is encountered.
- In flex, we can redefine YY_INPUT to the following. In lex, this
- does nothing! */
-#include <errno.h>
-#undef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
- while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
- if (errno != EINTR) \
- YY_FATAL_ERROR( "read() in flex scanner failed" );
-
-# line 60 "scan.l"
-
-/* done after the current pattern has been matched and before the
- * corresponding action - sets up yytext
- */
-#define YY_DO_BEFORE_ACTION \
- yytext = yy_bp; \
- yyleng = yy_cp - yy_bp; \
- yy_hold_char = *yy_cp; \
- *yy_cp = '\0'; \
- yy_c_buf_p = yy_cp;
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
-/* return all but the first 'n' matched characters back to the input stream */
-#define yyless(n) \
- do \
- { \
- /* undo effects of setting up yytext */ \
- *yy_cp = yy_hold_char; \
- yy_c_buf_p = yy_cp = yy_bp + n; \
- YY_DO_BEFORE_ACTION; /* set up yytext again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, yytext )
-
-
-struct yy_buffer_state
- {
- FILE *yy_input_file;
-
- YY_CHAR *yy_ch_buf; /* input buffer */
- YY_CHAR *yy_buf_pos; /* current position in input buffer */
-
- /* size of input buffer in bytes, not including room for EOB characters*/
- int yy_buf_size;
-
- /* number of characters read into yy_ch_buf, not including EOB characters */
- int yy_n_chars;
-
- int yy_eof_status; /* whether we've seen an EOF on this buffer */
-#define EOF_NOT_SEEN 0
- /* "pending" happens when the EOF has been seen but there's still
- * some text process
- */
-#define EOF_PENDING 1
-#define EOF_DONE 2
- };
-
-static YY_BUFFER_STATE yy_current_buffer;
-
-/* we provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state"
- */
-#define YY_CURRENT_BUFFER yy_current_buffer
-
-
-/* yy_hold_char holds the character lost when yytext is formed */
-static YY_CHAR yy_hold_char;
-
-static int yy_n_chars; /* number of characters read into yy_ch_buf */
-
-
-
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-#ifndef YY_USER_INIT
-#define YY_USER_INIT
-#endif
-
-extern YY_CHAR *yytext;
-extern int yyleng;
-extern FILE *yyin, *yyout;
-
-YY_CHAR *yytext;
-int yyleng;
-
-FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
-
-#define YY_END_OF_BUFFER 40
-typedef int yy_state_type;
-static const short int yy_accept[144] =
- { 0,
- 0, 0, 40, 38, 33, 31, 25, 38, 26, 38,
- 22, 26, 22, 22, 38, 26, 37, 29, 27, 29,
- 38, 22, 35, 35, 35, 35, 35, 35, 35, 35,
- 35, 35, 35, 35, 35, 35, 35, 35, 38, 33,
- 29, 0, 36, 27, 23, 30, 37, 0, 34, 37,
- 37, 0, 28, 32, 35, 35, 35, 35, 35, 35,
- 35, 35, 35, 7, 35, 35, 35, 35, 35, 35,
- 35, 35, 35, 35, 35, 24, 37, 0, 0, 37,
- 0, 35, 35, 35, 35, 35, 6, 35, 35, 35,
- 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
-
- 35, 13, 35, 35, 35, 14, 16, 35, 17, 35,
- 35, 35, 35, 3, 15, 35, 35, 9, 35, 35,
- 2, 35, 35, 11, 35, 35, 12, 20, 35, 10,
- 35, 8, 35, 1, 4, 21, 5, 35, 35, 35,
- 19, 18, 0
- } ;
-
-static const YY_CHAR yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 4, 5, 1, 1, 6, 7, 1, 8,
- 9, 10, 11, 12, 13, 14, 15, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 1, 17, 18,
- 19, 20, 1, 1, 21, 21, 21, 21, 21, 21,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 22, 23, 24, 25, 26, 1, 27, 28, 29, 30,
-
- 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 36, 48, 36,
- 49, 36, 50, 51, 52, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static const YY_CHAR yy_meta[53] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
- 1, 1
- } ;
-
-static const short int yy_base[146] =
- { 0,
- 0, 0, 193, 194, 190, 194, 172, 185, 170, 181,
- 194, 168, 42, 41, 41, 46, 52, 167, 61, 166,
- 181, 164, 135, 137, 139, 148, 140, 136, 0, 149,
- 27, 50, 147, 130, 126, 141, 40, 36, 120, 168,
- 194, 164, 194, 194, 194, 194, 66, 165, 194, 72,
- 76, 164, 194, 194, 0, 120, 134, 124, 131, 117,
- 117, 122, 132, 0, 113, 117, 117, 128, 119, 118,
- 52, 125, 107, 106, 114, 194, 80, 145, 84, 88,
- 144, 105, 118, 98, 108, 111, 0, 95, 95, 93,
- 105, 102, 91, 95, 88, 103, 85, 93, 84, 85,
-
- 90, 0, 90, 91, 85, 0, 0, 93, 0, 77,
- 76, 90, 74, 0, 0, 75, 87, 0, 90, 85,
- 0, 75, 83, 0, 76, 63, 0, 0, 66, 0,
- 62, 0, 47, 0, 0, 0, 0, 45, 53, 29,
- 0, 0, 194, 111, 56
- } ;
-
-static const short int yy_def[146] =
- { 0,
- 143, 1, 143, 143, 143, 143, 143, 144, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 145, 145, 145, 143, 143,
- 143, 144, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 143, 143, 143, 143, 143,
- 143, 145, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
-
- 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
- 145, 145, 0, 143, 143
- } ;
-
-static const short int yy_nxt[247] =
- { 0,
- 4, 5, 6, 7, 8, 9, 10, 11, 11, 12,
- 13, 11, 14, 15, 16, 17, 11, 18, 19, 20,
- 17, 11, 21, 11, 22, 4, 23, 24, 25, 26,
- 27, 28, 29, 30, 31, 29, 29, 32, 29, 29,
- 33, 34, 35, 36, 37, 29, 29, 38, 29, 11,
- 39, 11, 46, 46, 63, 49, 47, 55, 64, 44,
- 44, 47, 74, 48, 44, 50, 53, 51, 72, 75,
- 53, 53, 51, 53, 52, 53, 65, 142, 96, 41,
- 66, 77, 73, 141, 67, 53, 77, 80, 78, 50,
- 140, 51, 80, 139, 81, 77, 51, 97, 52, 47,
-
- 77, 138, 78, 80, 47, 137, 48, 136, 80, 135,
- 81, 42, 42, 134, 133, 132, 131, 130, 129, 128,
- 127, 126, 125, 124, 123, 122, 121, 120, 119, 118,
- 117, 116, 115, 114, 113, 112, 111, 110, 109, 108,
- 107, 106, 105, 104, 103, 102, 80, 77, 101, 100,
- 99, 98, 95, 94, 93, 92, 91, 90, 89, 88,
- 87, 86, 85, 84, 83, 82, 51, 79, 43, 40,
- 76, 71, 70, 69, 68, 62, 61, 60, 59, 58,
- 57, 56, 44, 54, 41, 41, 44, 45, 44, 43,
- 41, 40, 143, 3, 143, 143, 143, 143, 143, 143,
-
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143
- } ;
-
-static const short int yy_chk[247] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 13, 14, 31, 16, 15, 145, 31, 14,
- 13, 15, 38, 15, 16, 17, 19, 17, 37, 38,
- 19, 19, 17, 19, 17, 19, 32, 140, 71, 19,
- 32, 47, 37, 139, 32, 19, 47, 50, 47, 51,
- 138, 51, 50, 133, 50, 77, 51, 71, 51, 79,
-
- 77, 131, 77, 80, 79, 129, 79, 126, 80, 125,
- 80, 144, 144, 123, 122, 120, 119, 117, 116, 113,
- 112, 111, 110, 108, 105, 104, 103, 101, 100, 99,
- 98, 97, 96, 95, 94, 93, 92, 91, 90, 89,
- 88, 86, 85, 84, 83, 82, 81, 78, 75, 74,
- 73, 72, 70, 69, 68, 67, 66, 65, 63, 62,
- 61, 60, 59, 58, 57, 56, 52, 48, 42, 40,
- 39, 36, 35, 34, 33, 30, 28, 27, 26, 25,
- 24, 23, 22, 21, 20, 18, 12, 10, 9, 8,
- 7, 5, 3, 143, 143, 143, 143, 143, 143, 143,
-
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
- 143, 143, 143, 143, 143, 143
- } ;
-
-static yy_state_type yy_last_accepting_state;
-static YY_CHAR *yy_last_accepting_cpos;
-
-/* the intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-
-/* these variables are all declared out here so that section 3 code can
- * manipulate them
- */
-/* points to current character in buffer */
-static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
-static int yy_init = 1; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* flag which is used to allow yywrap()'s to do buffer switches
- * instead of setting up a fresh yyin. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-
-static yy_state_type yy_get_previous_state YY_PROTO(( void ));
-static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
-static int yy_get_next_buffer YY_PROTO(( void ));
-static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
-void yyrestart YY_PROTO(( FILE *input_file ));
-void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
-void yy_load_buffer_state YY_PROTO(( void ));
-YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
-void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
-void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
-
-#define yy_new_buffer yy_create_buffer
-
-#ifdef __cplusplus
-static int yyinput YY_PROTO(( void ));
-#else
-static int input YY_PROTO(( void ));
-#endif
-
-YY_DECL
- {
- register yy_state_type yy_current_state;
- register YY_CHAR *yy_cp, *yy_bp;
- register int yy_act;
-
-
-
- if ( yy_init )
- {
- YY_USER_INIT;
-
- if ( ! yy_start )
- yy_start = 1; /* first start state */
-
- if ( ! yyin )
- yyin = stdin;
-
- if ( ! yyout )
- yyout = stdout;
-
- if ( yy_current_buffer )
- yy_init_buffer( yy_current_buffer, yyin );
- else
- yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
-
- yy_load_buffer_state();
-
- yy_init = 0;
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
- yy_cp = yy_c_buf_p;
-
- /* support of yytext */
- *yy_cp = yy_hold_char;
-
- /* yy_bp points to the position in yy_ch_buf of the start of the
- * current run.
- */
- yy_bp = yy_cp;
-
- yy_current_state = yy_start;
-yy_match:
- do
- {
- register YY_CHAR yy_c = yy_ec[*yy_cp];
- if ( yy_accept[yy_current_state] )
- {
- yy_last_accepting_state = yy_current_state;
- yy_last_accepting_cpos = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = yy_def[yy_current_state];
- if ( yy_current_state >= 144 )
- yy_c = yy_meta[yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
- ++yy_cp;
- }
- while ( yy_base[yy_current_state] != 194 );
-
-yy_find_action:
- yy_act = yy_accept[yy_current_state];
-
- YY_DO_BEFORE_ACTION;
- YY_USER_ACTION;
-
-do_action: /* this label is used only to access EOF actions */
-
-
- switch ( yy_act )
- {
- case 0: /* must backtrack */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = yy_hold_char;
- yy_cp = yy_last_accepting_cpos;
- yy_current_state = yy_last_accepting_state;
- goto yy_find_action;
-
-case 1:
-# line 61 "scan.l"
-return(Define);
- YY_BREAK
-case 2:
-# line 62 "scan.l"
-return(Break);
- YY_BREAK
-case 3:
-# line 63 "scan.l"
-return(Quit);
- YY_BREAK
-case 4:
-# line 64 "scan.l"
-return(Length);
- YY_BREAK
-case 5:
-# line 65 "scan.l"
-return(Return);
- YY_BREAK
-case 6:
-# line 66 "scan.l"
-return(For);
- YY_BREAK
-case 7:
-# line 67 "scan.l"
-return(If);
- YY_BREAK
-case 8:
-# line 68 "scan.l"
-return(While);
- YY_BREAK
-case 9:
-# line 69 "scan.l"
-return(Sqrt);
- YY_BREAK
-case 10:
-# line 70 "scan.l"
-return(Scale);
- YY_BREAK
-case 11:
-# line 71 "scan.l"
-return(Ibase);
- YY_BREAK
-case 12:
-# line 72 "scan.l"
-return(Obase);
- YY_BREAK
-case 13:
-# line 73 "scan.l"
-return(Auto);
- YY_BREAK
-case 14:
-# line 74 "scan.l"
-return(Else);
- YY_BREAK
-case 15:
-# line 75 "scan.l"
-return(Read);
- YY_BREAK
-case 16:
-# line 76 "scan.l"
-return(Halt);
- YY_BREAK
-case 17:
-# line 77 "scan.l"
-return(Last);
- YY_BREAK
-case 18:
-# line 78 "scan.l"
-return(Warranty);
- YY_BREAK
-case 19:
-# line 79 "scan.l"
-return(Continue);
- YY_BREAK
-case 20:
-# line 80 "scan.l"
-return(Print);
- YY_BREAK
-case 21:
-# line 81 "scan.l"
-return(Limits);
- YY_BREAK
-case 22:
-# line 82 "scan.l"
-{ yylval.c_value = yytext[0];
- return((int)yytext[0]); }
- YY_BREAK
-case 23:
-# line 84 "scan.l"
-{ return(AND); }
- YY_BREAK
-case 24:
-# line 85 "scan.l"
-{ return(OR); }
- YY_BREAK
-case 25:
-# line 86 "scan.l"
-{ return(NOT); }
- YY_BREAK
-case 26:
-# line 87 "scan.l"
-{ yylval.c_value = yytext[0]; return(MUL_OP); }
- YY_BREAK
-case 27:
-# line 88 "scan.l"
-{ yylval.c_value = yytext[0]; return(ASSIGN_OP); }
- YY_BREAK
-case 28:
-# line 89 "scan.l"
-{
-#ifdef OLD_EQ_OP
- char warn_save;
- warn_save = warn_not_std;
- warn_not_std = TRUE;
- warn ("Old fashioned =<op>");
- warn_not_std = warn_save;
- yylval.c_value = yytext[1];
-#else
- yylval.c_value = '=';
- yyless (1);
-#endif
- return(ASSIGN_OP);
- }
- YY_BREAK
-case 29:
-# line 103 "scan.l"
-{ yylval.s_value = strcopyof(yytext); return(REL_OP); }
- YY_BREAK
-case 30:
-# line 104 "scan.l"
-{ yylval.c_value = yytext[0]; return(INCR_DECR); }
- YY_BREAK
-case 31:
-# line 105 "scan.l"
-{ line_no++; return(NEWLINE); }
- YY_BREAK
-case 32:
-# line 106 "scan.l"
-{ line_no++; /* ignore a "quoted" newline */ }
- YY_BREAK
-case 33:
-# line 107 "scan.l"
-{ /* ignore spaces and tabs */ }
- YY_BREAK
-case 34:
-# line 108 "scan.l"
-{
- int c;
-
- for (;;)
- {
- while ( ((c=input()) != '*') && (c != EOF))
- /* eat it */
- if (c == '\n') line_no++;
- if (c == '*')
- {
- while ( (c=input()) == '*') /* eat it*/;
- if (c == '/') break; /* at end of comment */
- if (c == '\n') line_no++;
- }
- if (c == EOF)
- {
- fprintf (stderr,"EOF encountered in a comment.\n");
- break;
- }
- }
- }
- YY_BREAK
-case 35:
-# line 129 "scan.l"
-{ yylval.s_value = strcopyof(yytext); return(NAME); }
- YY_BREAK
-case 36:
-# line 130 "scan.l"
-{
- unsigned char *look;
- int count = 0;
- yylval.s_value = strcopyof(yytext);
- for (look = yytext; *look != 0; look++)
- {
- if (*look == '\n') line_no++;
- if (*look == '"') count++;
- }
- if (count != 2) yyerror ("NUL character in string.");
- return(STRING);
- }
- YY_BREAK
-case 37:
-# line 142 "scan.l"
-{
- unsigned char *src, *dst;
- int len;
- /* remove a trailing decimal point. */
- len = strlen(yytext);
- if (yytext[len-1] == '.')
- yytext[len-1] = 0;
- /* remove leading zeros. */
- src = yytext;
- dst = yytext;
- while (*src == '0') src++;
- if (*src == 0) src--;
- /* Copy strings removing the newlines. */
- while (*src != 0)
- {
- if (*src == '\\')
- {
- src++; src++;
- line_no++;
- }
- else
- *dst++ = *src++;
- }
- *dst = 0;
- yylval.s_value = strcopyof(yytext);
- return(NUMBER);
- }
- YY_BREAK
-case 38:
-# line 169 "scan.l"
-{
- if (yytext[0] < ' ')
- yyerror ("illegal character: ^%c",yytext[0] + '@');
- else
- if (yytext[0] > '~')
- yyerror ("illegal character: \\%3d", (int) yytext[0]);
- else
- yyerror ("illegal character: %s",yytext);
- }
- YY_BREAK
-case 39:
-# line 178 "scan.l"
-ECHO;
- YY_BREAK
-case YY_STATE_EOF(INITIAL):
- yyterminate();
-
- case YY_END_OF_BUFFER:
- {
- /* amount of text matched not including the EOB char */
- int yy_amount_of_matched_text = yy_cp - yytext - 1;
-
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = yy_hold_char;
-
- /* note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the end-
- * of-buffer state). Contrast this with the test in yyinput().
- */
- if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
- /* this was really a NUL */
- {
- yy_state_type yy_next_state;
-
- yy_c_buf_p = yytext + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state();
-
- /* okay, we're now positioned to make the
- * NUL transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we
- * don't want to build jamming into it because
- * then it will run more slowly)
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = yytext + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* consume the NUL */
- yy_cp = ++yy_c_buf_p;
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer() )
- {
- case EOB_ACT_END_OF_FILE:
- {
- yy_did_buffer_switch_on_eof = 0;
-
- if ( yywrap() )
- {
- /* note: because we've taken care in
- * yy_get_next_buffer() to have set up yytext,
- * we can now set up yy_c_buf_p so that if some
- * total hoser (like flex itself) wants
- * to call the scanner after we return the
- * YY_NULL, it'll still work - another YY_NULL
- * will get returned.
- */
- yy_c_buf_p = yytext + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF((yy_start - 1) / 2);
- goto do_action;
- }
-
- else
- {
- if ( ! yy_did_buffer_switch_on_eof )
- YY_NEW_FILE;
- }
- }
- break;
-
- case EOB_ACT_CONTINUE_SCAN:
- yy_c_buf_p = yytext + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state();
-
- yy_cp = yy_c_buf_p;
- yy_bp = yytext + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- yy_c_buf_p =
- &yy_current_buffer->yy_ch_buf[yy_n_chars];
-
- yy_current_state = yy_get_previous_state();
-
- yy_cp = yy_c_buf_p;
- yy_bp = yytext + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
-#ifdef FLEX_DEBUG
- printf( "action # %d\n", yy_act );
-#endif
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- }
- }
- }
-
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * synopsis
- * int yy_get_next_buffer();
- *
- * returns a code representing an action
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-
-static int yy_get_next_buffer()
-
- {
- register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
- register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
- register int number_to_move, i;
- int ret_val;
-
- if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- /* try to read more data */
-
- /* first move last chars to start of buffer */
- number_to_move = yy_c_buf_p - yytext;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- yy_n_chars = 0;
-
- else
- {
- int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- else if ( num_to_read <= 0 )
- YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
-
- /* read in more data */
- YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
- yy_n_chars, num_to_read );
- }
-
- if ( yy_n_chars == 0 )
- {
- if ( number_to_move == 1 )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- yy_current_buffer->yy_eof_status = EOF_DONE;
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- yy_current_buffer->yy_eof_status = EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- yy_n_chars += number_to_move;
- yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
- yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
-
- /* yytext begins at the second character in yy_ch_buf; the first
- * character is the one which preceded it before reading in the latest
- * buffer; it needs to be kept around in case it's a newline, so
- * yy_get_previous_state() will have with '^' rules active
- */
-
- yytext = &yy_current_buffer->yy_ch_buf[1];
-
- return ( ret_val );
- }
-
-
-/* yy_get_previous_state - get the state just before the EOB char was reached
- *
- * synopsis
- * yy_state_type yy_get_previous_state();
- */
-
-static yy_state_type yy_get_previous_state()
-
- {
- register yy_state_type yy_current_state;
- register YY_CHAR *yy_cp;
-
- yy_current_state = yy_start;
-
- for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
- {
- register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1);
- if ( yy_accept[yy_current_state] )
- {
- yy_last_accepting_state = yy_current_state;
- yy_last_accepting_cpos = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = yy_def[yy_current_state];
- if ( yy_current_state >= 144 )
- yy_c = yy_meta[yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
- }
-
- return ( yy_current_state );
- }
-
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
-
-#ifdef YY_USE_PROTOS
-static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
-#else
-static yy_state_type yy_try_NUL_trans( yy_current_state )
-register yy_state_type yy_current_state;
-#endif
-
- {
- register int yy_is_jam;
- register YY_CHAR *yy_cp = yy_c_buf_p;
-
- register YY_CHAR yy_c = 1;
- if ( yy_accept[yy_current_state] )
- {
- yy_last_accepting_state = yy_current_state;
- yy_last_accepting_cpos = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = yy_def[yy_current_state];
- if ( yy_current_state >= 144 )
- yy_c = yy_meta[yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
- yy_is_jam = (yy_current_state == 143);
-
- return ( yy_is_jam ? 0 : yy_current_state );
- }
-
-
-#ifdef YY_USE_PROTOS
-static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
-#else
-static void yyunput( c, yy_bp )
-YY_CHAR c;
-register YY_CHAR *yy_bp;
-#endif
-
- {
- register YY_CHAR *yy_cp = yy_c_buf_p;
-
- /* undo effects of setting up yytext */
- *yy_cp = yy_hold_char;
-
- if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
- { /* need to shift things up to make room */
- register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
- register YY_CHAR *dest =
- &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
- register YY_CHAR *source =
- &yy_current_buffer->yy_ch_buf[number_to_move];
-
- while ( source > yy_current_buffer->yy_ch_buf )
- *--dest = *--source;
-
- yy_cp += dest - source;
- yy_bp += dest - source;
- yy_n_chars = yy_current_buffer->yy_buf_size;
-
- if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
- YY_FATAL_ERROR( "flex scanner push-back overflow" );
- }
-
- if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
- yy_cp[-2] = '\n';
-
- *--yy_cp = c;
-
- /* note: the formal parameter *must* be called "yy_bp" for this
- * macro to now work correctly
- */
- YY_DO_BEFORE_ACTION; /* set up yytext again */
- }
-
-
-#ifdef __cplusplus
-static int yyinput()
-#else
-static int input()
-#endif
-
- {
- int c;
- YY_CHAR *yy_cp = yy_c_buf_p;
-
- *yy_cp = yy_hold_char;
-
- if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
- /* this was really a NUL */
- *yy_c_buf_p = '\0';
-
- else
- { /* need more input */
- yytext = yy_c_buf_p;
- ++yy_c_buf_p;
-
- switch ( yy_get_next_buffer() )
- {
- case EOB_ACT_END_OF_FILE:
- {
- if ( yywrap() )
- {
- yy_c_buf_p = yytext + YY_MORE_ADJ;
- return ( EOF );
- }
-
- YY_NEW_FILE;
-
-#ifdef __cplusplus
- return ( yyinput() );
-#else
- return ( input() );
-#endif
- }
- break;
-
- case EOB_ACT_CONTINUE_SCAN:
- yy_c_buf_p = yytext + YY_MORE_ADJ;
- break;
-
- case EOB_ACT_LAST_MATCH:
-#ifdef __cplusplus
- YY_FATAL_ERROR( "unexpected last match in yyinput()" );
-#else
- YY_FATAL_ERROR( "unexpected last match in input()" );
-#endif
- }
- }
- }
-
- c = *yy_c_buf_p;
- yy_hold_char = *++yy_c_buf_p;
-
- return ( c );
- }
-
-
-#ifdef YY_USE_PROTOS
-void yyrestart( FILE *input_file )
-#else
-void yyrestart( input_file )
-FILE *input_file;
-#endif
-
- {
- yy_init_buffer( yy_current_buffer, input_file );
- yy_load_buffer_state();
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
-#else
-void yy_switch_to_buffer( new_buffer )
-YY_BUFFER_STATE new_buffer;
-#endif
-
- {
- if ( yy_current_buffer == new_buffer )
- return;
-
- if ( yy_current_buffer )
- {
- /* flush out information for old buffer */
- *yy_c_buf_p = yy_hold_char;
- yy_current_buffer->yy_buf_pos = yy_c_buf_p;
- yy_current_buffer->yy_n_chars = yy_n_chars;
- }
-
- yy_current_buffer = new_buffer;
- yy_load_buffer_state();
-
- /* we don't actually know whether we did this switch during
- * EOF (yywrap()) processing, but the only time this flag
- * is looked at is after yywrap() is called, so it's safe
- * to go ahead and always set it.
- */
- yy_did_buffer_switch_on_eof = 1;
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_load_buffer_state( void )
-#else
-void yy_load_buffer_state()
-#endif
-
- {
- yy_n_chars = yy_current_buffer->yy_n_chars;
- yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
- yyin = yy_current_buffer->yy_input_file;
- yy_hold_char = *yy_c_buf_p;
- }
-
-
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
-#else
-YY_BUFFER_STATE yy_create_buffer( file, size )
-FILE *file;
-int size;
-#endif
-
- {
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
-
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
- yy_init_buffer( b, file );
-
- return ( b );
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_delete_buffer( YY_BUFFER_STATE b )
-#else
-void yy_delete_buffer( b )
-YY_BUFFER_STATE b;
-#endif
-
- {
- if ( b == yy_current_buffer )
- yy_current_buffer = (YY_BUFFER_STATE) 0;
-
- free( (char *) b->yy_ch_buf );
- free( (char *) b );
- }
-
-
-#ifdef YY_USE_PROTOS
-void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
-#else
-void yy_init_buffer( b, file )
-YY_BUFFER_STATE b;
-FILE *file;
-#endif
-
- {
- b->yy_input_file = file;
-
- /* we put in the '\n' and start reading from [1] so that an
- * initial match-at-newline will be true.
- */
-
- b->yy_ch_buf[0] = '\n';
- b->yy_n_chars = 1;
-
- /* we always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[1];
-
- b->yy_eof_status = EOF_NOT_SEEN;
- }
-# line 178 "scan.l"
-
-
-
-
-/* This is the way to get multiple files input into lex. */
-
-int
-yywrap()
-{
- if (!open_new_file ()) return (1); /* EOF on standard in. */
- return (0); /* We have more input. */
-}
diff --git a/gnu/usr.bin/bc/scan.l b/gnu/usr.bin/bc/scan.l
new file mode 100644
index 0000000..8189364
--- /dev/null
+++ b/gnu/usr.bin/bc/scan.l
@@ -0,0 +1,196 @@
+%{
+/* scan.l: the (f)lex description file for the scanner. */
+
+/* This file is part of bc written for MINIX.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License , or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You may contact the author by:
+ e-mail: phil@cs.wwu.edu
+ us-mail: Philip A. Nelson
+ Computer Science Department, 9062
+ Western Washington University
+ Bellingham, WA 98226-9062
+
+*************************************************************************/
+
+#include "bcdefs.h"
+#include "y.tab.h"
+#include "global.h"
+#include "proto.h"
+
+/* Using flex, we can ask for a smaller input buffer. With lex, this
+ does nothing! */
+
+#ifdef SMALL_BUF
+#undef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 512
+#endif
+
+/* We want to define our own yywrap. */
+#undef yywrap
+_PROTOTYPE(int yywrap, (void));
+
+/* MINIX returns from read with < 0 if SIGINT is encountered.
+ In flex, we can redefine YY_INPUT to the following. In lex, this
+ does nothing! */
+#include <errno.h>
+#undef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
+ if (errno != EINTR) \
+ YY_FATAL_ERROR( "read() in flex scanner failed" );
+
+%}
+DIGIT [0-9A-F]
+LETTER [a-z]
+%%
+define return(Define);
+break return(Break);
+quit return(Quit);
+length return(Length);
+return return(Return);
+for return(For);
+if return(If);
+while return(While);
+sqrt return(Sqrt);
+scale return(Scale);
+ibase return(Ibase);
+obase return(Obase);
+auto return(Auto);
+else return(Else);
+read return(Read);
+halt return(Halt);
+last return(Last);
+warranty return(Warranty);
+continue return(Continue);
+print return(Print);
+limits return(Limits);
+"." {
+#ifdef DOT_IS_LAST
+ return(Last);
+#else
+ yyerror ("illegal character: %s",yytext);
+#endif
+ }
+"+"|"-"|";"|"("|")"|"{"|"}"|"["|"]"|","|"^" { yylval.c_value = yytext[0];
+ return((int)yytext[0]); }
+&& { return(AND); }
+\|\| { return(OR); }
+"!" { return(NOT); }
+"*"|"/"|"%" { yylval.c_value = yytext[0]; return(MUL_OP); }
+"="|\+=|-=|\*=|\/=|%=|\^= { yylval.c_value = yytext[0]; return(ASSIGN_OP); }
+=\+|=-|=\*|=\/|=%|=\^ {
+#ifdef OLD_EQ_OP
+ char warn_save;
+ warn_save = warn_not_std;
+ warn_not_std = TRUE;
+ warn ("Old fashioned =<op>");
+ warn_not_std = warn_save;
+ yylval.c_value = yytext[1];
+#else
+ yylval.c_value = '=';
+ yyless (1);
+#endif
+ return(ASSIGN_OP);
+ }
+==|\<=|\>=|\!=|"<"|">" { yylval.s_value = strcopyof(yytext); return(REL_OP); }
+\+\+|-- { yylval.c_value = yytext[0]; return(INCR_DECR); }
+"\n" { line_no++; return(NEWLINE); }
+\\\n { line_no++; /* ignore a "quoted" newline */ }
+[ \t]+ { /* ignore spaces and tabs */ }
+"/*" {
+ int c;
+
+ for (;;)
+ {
+ while ( ((c=input()) != '*') && (c != EOF))
+ /* eat it */
+ if (c == '\n') line_no++;
+ if (c == '*')
+ {
+ while ( (c=input()) == '*') /* eat it*/;
+ if (c == '/') break; /* at end of comment */
+ if (c == '\n') line_no++;
+ }
+ if (c == EOF)
+ {
+ fprintf (stderr,"EOF encountered in a comment.\n");
+ break;
+ }
+ }
+ }
+[a-z][a-z0-9_]* { yylval.s_value = strcopyof(yytext); return(NAME); }
+\"[^\"]*\" {
+ unsigned char *look;
+ int count = 0;
+ yylval.s_value = strcopyof(yytext);
+ for (look = yytext; *look != 0; look++)
+ {
+ if (*look == '\n') line_no++;
+ if (*look == '"') count++;
+ }
+ if (count != 2) yyerror ("NUL character in string.");
+ return(STRING);
+ }
+{DIGIT}({DIGIT}|\\\n)*("."({DIGIT}|\\\n)*)?|"."(\\\n)*{DIGIT}({DIGIT}|\\\n)* {
+ unsigned char *src, *dst;
+ int len;
+ /* remove a trailing decimal point. */
+ len = strlen(yytext);
+ if (yytext[len-1] == '.')
+ yytext[len-1] = 0;
+ /* remove leading zeros. */
+ src = yytext;
+ dst = yytext;
+ while (*src == '0') src++;
+ if (*src == 0) src--;
+ /* Copy strings removing the newlines. */
+ while (*src != 0)
+ {
+ if (*src == '\\')
+ {
+ src++; src++;
+ line_no++;
+ }
+ else
+ *dst++ = *src++;
+ }
+ *dst = 0;
+ yylval.s_value = strcopyof(yytext);
+ return(NUMBER);
+ }
+. {
+ if (yytext[0] < ' ')
+ yyerror ("illegal character: ^%c",yytext[0] + '@');
+ else
+ if (yytext[0] > '~')
+ yyerror ("illegal character: \\%3d", (int) yytext[0]);
+ else
+ yyerror ("illegal character: %s",yytext);
+ }
+%%
+
+
+
+/* This is the way to get multiple files input into lex. */
+
+int
+yywrap()
+{
+ if (!open_new_file ()) return (1); /* EOF on standard in. */
+ return (0); /* We have more input. */
+}
diff --git a/gnu/usr.bin/bc/storage.c b/gnu/usr.bin/bc/storage.c
index 18ddb93..5e65568 100644
--- a/gnu/usr.bin/bc/storage.c
+++ b/gnu/usr.bin/bc/storage.c
@@ -1,7 +1,7 @@
/* storage.c: Code and data storage manipulations. This includes labels. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -895,7 +895,6 @@ process_params (pc, func)
{
char ch;
arg_list *params;
- char warned = FALSE;
int ix, ix1;
bc_var *v_temp;
bc_var_array *a_src, *a_dest;
@@ -954,11 +953,8 @@ process_params (pc, func)
}
else
{
- if (!warned)
- {
- rt_error ("Parameter number mismatch");
- warned = TRUE;
- }
+ rt_error ("Parameter number mismatch");
+ return;
}
params = params->next;
}
diff --git a/gnu/usr.bin/bc/util.c b/gnu/usr.bin/bc/util.c
index 5a01803..8957908 100644
--- a/gnu/usr.bin/bc/util.c
+++ b/gnu/usr.bin/bc/util.c
@@ -1,7 +1,7 @@
/* util.c: Utility routines for bc. */
/* This file is part of bc written for MINIX.
- Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -56,7 +56,7 @@ strcopyof (str)
arg_list *
nextarg (args, val)
arg_list *args;
- char val;
+ int val;
{ arg_list *temp;
temp = (arg_list *) bc_malloc (sizeof (arg_list));
@@ -77,23 +77,22 @@ static char *arglist1 = NULL, *arglist2 = NULL;
/* make_arg_str does the actual construction of the argument string.
ARGS is the pointer to the list and LEN is the maximum number of
- characters needed. 1 char is the minimum needed. COMMAS tells
- if each number should be seperated by commas.*/
+ characters needed. 1 char is the minimum needed.
+ */
-_PROTOTYPE (static char *make_arg_str, (arg_list *args, int len, int commas));
+_PROTOTYPE (static char *make_arg_str, (arg_list *args, int len));
static char *
-make_arg_str (args, len, commas)
+make_arg_str (args, len)
arg_list *args;
int len;
- int commas;
{
char *temp;
char sval[20];
/* Recursive call. */
if (args != NULL)
- temp = make_arg_str (args->next, len+11, commas);
+ temp = make_arg_str (args->next, len+11);
else
{
temp = (char *) bc_malloc (len);
@@ -102,7 +101,7 @@ make_arg_str (args, len, commas)
}
/* Add the current number to the end of the string. */
- if (len != 1 && commas)
+ if (len != 1)
sprintf (sval, "%d,", args->av_name);
else
sprintf (sval, "%d", args->av_name);
@@ -111,17 +110,38 @@ make_arg_str (args, len, commas)
}
char *
-arg_str (args, commas)
+arg_str (args)
arg_list *args;
- int commas;
{
if (arglist2 != NULL)
free (arglist2);
arglist2 = arglist1;
- arglist1 = make_arg_str (args, 1, commas);
+ arglist1 = make_arg_str (args, 1);
return (arglist1);
}
+char *
+call_str (args)
+ arg_list *args;
+{
+ arg_list *temp;
+ int arg_count;
+ int ix;
+
+ if (arglist2 != NULL)
+ free (arglist2);
+ arglist2 = arglist1;
+
+ /* Count the number of args and add the 0's and 1's. */
+ for (temp = args, arg_count = 0; temp != NULL; temp = temp->next)
+ arg_count++;
+ arglist1 = (char *) bc_malloc(arg_count+1);
+ for (temp = args, ix=0; temp != NULL; temp = temp->next)
+ arglist1[ix++] = ( temp->av_name ? '1' : '0');
+ arglist1[ix] = 0;
+
+ return (arglist1);
+}
/* free_args frees an argument list ARGS. */
@@ -522,9 +542,13 @@ lookup (name, namekind)
exit (1);
case FUNCT:
+ case FUNCTDEF:
if (id->f_name != 0)
{
free(name);
+ /* Check to see if we are redefining a math lib function. */
+ if (use_math && namekind == FUNCTDEF && id->f_name <= 6)
+ id->f_name = next_func++;
return (id->f_name);
}
id->f_name = next_func++;
diff --git a/gnu/usr.bin/bc/version.h b/gnu/usr.bin/bc/version.h
index 6b3f909..6bf3ba3 100644
--- a/gnu/usr.bin/bc/version.h
+++ b/gnu/usr.bin/bc/version.h
@@ -1,3 +1,3 @@
#define BC_VERSION \
- "bc 1.02 (Mar 3, 92) Copyright (C) 1991, 1992 Free Software Foundation, Inc."
+"bc 1.03 (Nov 2, 1994)\nCopyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc."
diff --git a/gnu/usr.bin/bc/y.tab.h b/gnu/usr.bin/bc/y.tab.h
deleted file mode 100644
index 9e65a2f..0000000
--- a/gnu/usr.bin/bc/y.tab.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#define NEWLINE 257
-#define AND 258
-#define OR 259
-#define NOT 260
-#define STRING 261
-#define NAME 262
-#define NUMBER 263
-#define MUL_OP 264
-#define ASSIGN_OP 265
-#define REL_OP 266
-#define INCR_DECR 267
-#define Define 268
-#define Break 269
-#define Quit 270
-#define Length 271
-#define Return 272
-#define For 273
-#define If 274
-#define While 275
-#define Sqrt 276
-#define Else 277
-#define Scale 278
-#define Ibase 279
-#define Obase 280
-#define Auto 281
-#define Read 282
-#define Warranty 283
-#define Halt 284
-#define Last 285
-#define Continue 286
-#define Print 287
-#define Limits 288
-#define UNARY_MINUS 289
-typedef union {
- char *s_value;
- char c_value;
- int i_value;
- arg_list *a_value;
- } YYSTYPE;
-extern YYSTYPE yylval;
OpenPOWER on IntegriCloud