#include <sys/cdefs.h>
#ifndef lint
#if 0
static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
#else
__IDSTRING(yyrcsid, "$NetBSD: skeleton.c,v 1.14 1997/10/20 03:41:16 lukem Exp $");
#endif
#endif
#include <stdlib.h>
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define YYLEX yylex()
#define YYEMPTY -1
#define yyclearin (yychar=(YYEMPTY))
#define yyerrok (yyerrflag=0)
#define YYRECOVERING (yyerrflag!=0)
#define YYPREFIX "yy"
#line 2 "bc.y"
/* from 4.4BSD /usr/src/usr.bin/bc/bc.y */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This module is believed to contain source code proprietary to AT&T.
* Use and redistribution is subject to the Berkeley Software License
* Agreement and your Software Agreement with AT&T (Western Electric).
*
* from bc.y 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Redistributions of source code and documentation must retain the
* above copyright notice, this list of conditions and the following
* disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed or owned by Caldera
* International, Inc.
* Neither the name of Caldera International, Inc. nor the names of
* other contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
* INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4
#define USED __attribute__ ((used))
#elif defined __GNUC__
#define USED __attribute__ ((unused))
#else
#define USED
#endif
static const char sccsid[] USED = "@(#)bc.sl 1.24 (gritter) 7/3/05";
#include <unistd.h>
#include <signal.h>
#include <limits.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
typedef intptr_t YYSTYPE;
#define YYSTYPE YYSTYPE
static int cpeek(int c, int yes, int no);
static int getch(void);
static intptr_t bundle(int a, ...);
static void routput(intptr_t *p);
static void output(intptr_t *p);
static void conout(intptr_t p, intptr_t s);
static void pp(intptr_t);
static void tp(intptr_t);
static void yyinit(int argc, char *argv[]);
static intptr_t *getout(void);
static intptr_t *getf(intptr_t);
static intptr_t *geta(intptr_t);
static void yyerror(const char *);
static void cantopen(const char *);
extern int yylex(void);
#if defined (__GLIBC__) && defined (_IO_getc_unlocked)
#undef getc
#define getc(f) _IO_getc_unlocked(f)
#endif
#line 98 "bc.y"
#define THIS_BC_STRING_MAX 1000
static FILE *in;
static char cary[LINE_MAX + 1], *cp = { cary };
static char string[THIS_BC_STRING_MAX + 3], *str = {string};
static int crs = '0';
static int rcrs = '0'; /* reset crs */
static int bindx = 0;
static int lev = 0;
static int ln;
static char *ss;
static int bstack[10] = { 0 };
static char *numb[15] = {
" 0", " 1", " 2", " 3", " 4", " 5",
" 6", " 7", " 8", " 9", " 10", " 11",
" 12", " 13", " 14" };
static intptr_t *pre, *post;
#line 119 "y.tab.c"
#define UMINUS 257
#define LETTER 258
#define DIGIT 259
#define SQRT 260
#define LENGTH 261
#define _IF 262
#define FFF 263
#define EQ 264
#define _WHILE 265
#define _FOR 266
#define NE 267
#define LE 268
#define GE 269
#define INCR 270
#define DECR 271
#define _RETURN 272
#define _BREAK 273
#define _DEFINE 274
#define BASE 275
#define OBASE 276
#define SCALE 277
#define EQPL 278
#define EQMI 279
#define EQMUL 280
#define EQDIV 281
#define EQREM 282
#define EQEXP 283
#define _AUTO 284
#define DOT 285
#define QSTR 286
#define YYERRCODE 256
short yylhs[] = { -1,
0, 0, 0, 5, 5, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 9,
9, 9, 9, 9, 9, 13, 11, 6, 6, 2,
2, 12, 12, 12, 12, 12, 12, 12, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 14, 14, 16, 16, 15, 17, 17,
17, 10, 3, 4, 4, 4, 7, 7, 18, 18,
};
short yylen[] = { 2,
0, 3, 8, 1, 4, 1, 0, 1, 3, 6,
3, 6, 1, 4, 3, 1, 3, 3, 3, 3,
3, 3, 3, 1, 1, 7, 7, 8, 4, 1,
1, 1, 1, 1, 1, 4, 0, 1, 3, 1,
1, 3, 3, 3, 3, 3, 3, 1, 3, 3,
2, 3, 3, 3, 3, 4, 2, 2, 2, 2,
5, 5, 5, 5, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 4, 3, 1, 2,
3, 2, 1, 1, 3, 3, 6, 6, 4, 4,
3, 1, 4, 2, 3, 3, 3, 3, 3, 3,
1, 1, 1, 1, 3, 1, 3, 1, 1, 1,
2, 0, 3, 0, 1, 3, 1, 3, 1, 3,
};
short yydefred[] = { 1,
0, 25, 0, 0, 110, 0, 0, 112, 24, 112,
0, 0, 0, 0, 13, 0, 0, 0, 0, 0,
8, 0, 0, 0, 92, 109, 0, 0, 0, 112,
0, 0, 0, 0, 0, 0, 0, 51, 0, 57,
60, 30, 31, 32, 33, 34, 35, 0, 0, 0,
0, 0, 37, 0, 0, 0, 70, 74, 66, 0,
72, 76, 68, 0, 0, 0, 69, 71, 0, 0,
73, 75, 0, 0, 65, 67, 0, 0, 80, 38,
0, 0, 0, 41, 40, 2, 0, 0, 115, 0,
0, 0, 0, 0, 0, 0, 0, 111, 0, 0,
0, 0, 0, 0, 0, 0, 0, 94, 0, 0,
0, 78, 0, 0, 104, 0, 0, 0, 0, 0,
0, 0, 0, 15, 0, 113, 0, 0, 0, 0,
0, 0, 0, 23, 0, 91, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 81, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77, 0, 93, 89, 0, 0, 36, 0, 0, 14,
90, 39, 0, 120, 0, 116, 0, 0, 0, 0,
0, 0, 0, 0, 0, 61, 63, 0, 107, 105,
0, 0, 62, 64, 4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 37, 0,
0, 0, 0, 0, 26, 27, 0, 117, 3, 37,
0, 5, 28, 118,
};
short yydgoto[] = { 1,
80, 135, 28, 88, 196, 81, 217, 29, 101, 53,
119, 148, 30, 114, 31, 115, 32, 89,
};
short yysindex[] = { 0,
594, 0, 860, 669, 0, -23, -17, 0, 0, 0,
5, 56, 59, 7, 0, -236, 956, 970, 936, -93,
0, 750, 860, -233, 0, 0, -3, -207, 953, 0,
-217, -179, 771, 976, 1003, 942, -177, 0, 860, 0,
0, 0, 0, 0, 0, 0, 0, 860, 498, 860,
860, 860, 0, 42, 860, 27, 0, 0, 0, 39,
0, 0, 0, 798, 71, 860, 0, 0, 860, 860,
0, 0, 860, 860, 0, 0, 860, 860, 0, 0,
-6, 987, 78, 0, 0, 0, 72, 66, 0, 860,
860, 860, 860, 860, 860, 860, -93, 0, 860, 860,
860, 860, 860, 860, 860, 860, 860, 0, 953, -27,
914, 0, 953, 162, 0, 953, 1097, 1134, 138, 860,
1068, 860, 860, 0, 1314, 0, 953, 953, 953, 953,
953, 1381, 953, 0, 750, 0, 860, 89, 87, -207,
-18, -18, 124, 124, 124, 124, 1001, 160, 0, 953,
1398, 953, 953, 953, 953, 953, 953, 953, 1009, 832,
0, 893, 0, 0, 860, 187, 0, 1419, 1436, 0,
0, 0, 953, 0, -3, 0, 860, 860, 860, 860,
860, 860, 860, 1023, 860, 0, 0, 860, 0, 0,
188, 750, 0, 0, 0, 708, 953, 953, 953, 953,
953, 953, 1443, 860, 860, 953, 953, 750, 0, -207,
-5, 750, 953, 953, 0, 0, 167, 0, 0, 0,
-207, 0, 0, 0,
};
short yyrindex[] = { 0,
18, 0, 0, 235, 0, 0, 0, 0, 0, 0,
0, 0, 0, -2, 0, 0, 804, 1035, 1288, -1,
0, 1, 0, 0, 0, 0, 0, 168, 3, 0,
28, -10, 54, 90, 99, 128, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 154, 0, 0, 0, 190,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1344, 0, 0, 0, 45, 0, 0, 0,
0, 0, 0, 0, 0, 0, 283, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 4, 0,
442, 0, 195, 0, 0, 20, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 92, 95, 98, 115,
145, 0, 146, 0, 1, 0, 0, 0, 0, 0,
245, 482, 369, 405, 431, 460, -20, 0, 0, 331,
0, 518, 524, 530, 553, 560, 617, 642, 1374, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 166, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 341, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 1, 44, 53, 121, 126,
127, 148, 0, 0, 0, 184, 228, 1, 0, 0,
0, 1, 652, 677, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
};
short yygindex[] = { 0,
73, -15, 0, 0, 0, 34, 0, 1272, 646, -4,
-103, -117, 0, 0, -19, 79, 0, 41,
};
#define YYTABLESIZE 1537
short yytable[] = { 108,
79, 26, 166, 85, 85, 54, 85, 16, 83, 94,
7, 86, 6, 9, 92, 90, 51, 91, 94, 93,
48, 65, 52, 92, 83, 96, 108, 7, 93, 11,
108, 108, 108, 108, 108, 83, 108, 79, 48, 83,
83, 83, 83, 83, 55, 83, 64, 191, 108, 108,
87, 108, 84, 84, 119, 84, 16, 83, 83, 7,
83, 6, 9, 84, 79, 159, 95, 97, 79, 79,
79, 79, 79, 27, 79, 95, 7, 149, 11, 98,
108, 120, 108, 108, 42, 119, 79, 79, 119, 79,
84, 83, 83, 45, 84, 84, 84, 84, 84, 102,
84, 19, 42, 119, 20, 216, 139, 21, 103, 140,
126, 45, 84, 84, 108, 84, 223, 122, 134, 219,
79, 79, 16, 83, 22, 7, 102, 6, 9, 123,
102, 102, 102, 102, 102, 103, 102, 101, 137, 103,
103, 103, 103, 103, 11, 103, 84, 84, 102, 102,
19, 102, 79, 20, 17, 18, 21, 103, 103, 195,
103, 47, 138, 58, 101, 5, 46, 43, 101, 101,
101, 101, 101, 22, 101, 29, 85, 165, 84, 47,
176, 174, 102, 102, 46, 43, 101, 101, 44, 101,
58, 103, 103, 10, 58, 58, 58, 58, 58, 59,
58, 222, 161, 17, 18, 162, 44, 172, 114, 175,
221, 114, 58, 58, 102, 58, 19, 95, 183, 20,
101, 101, 21, 103, 29, 84, 59, 192, 208, 211,
59, 59, 59, 59, 59, 106, 59, 12, 106, 22,
190, 0, 10, 0, 84, 0, 58, 58, 59, 59,
218, 59, 101, 108, 49, 0, 108, 108, 108, 0,
0, 224, 83, 0, 209, 83, 83, 83, 0, 17,
18, 84, 0, 0, 108, 0, 84, 84, 58, 84,
215, 84, 59, 59, 220, 49, 12, 49, 49, 49,
29, 79, 82, 84, 79, 79, 79, 0, 0, 0,
0, 0, 0, 49, 49, 0, 49, 0, 10, 0,
0, 0, 0, 56, 59, 0, 60, 84, 0, 82,
84, 84, 84, 82, 82, 82, 82, 82, 84, 82,
57, 58, 59, 61, 62, 63, 0, 49, 0, 0,
85, 82, 82, 0, 82, 0, 0, 0, 0, 0,
56, 0, 12, 102, 0, 0, 102, 102, 102, 84,
0, 0, 103, 0, 0, 103, 103, 103, 0, 49,
0, 85, 0, 0, 85, 82, 82, 56, 52, 0,
0, 56, 56, 56, 56, 56, 0, 56, 0, 85,
85, 101, 85, 0, 101, 101, 101, 0, 0, 56,
56, 0, 56, 0, 0, 52, 0, 82, 0, 52,
52, 52, 52, 52, 53, 52, 0, 58, 0, 0,
58, 58, 58, 85, 0, 0, 0, 52, 52, 0,
52, 0, 0, 56, 56, 0, 0, 0, 0, 0,
54, 53, 0, 0, 0, 53, 53, 53, 53, 53,
0, 53, 0, 59, 0, 85, 59, 59, 59, 0,
0, 52, 0, 53, 53, 56, 53, 54, 0, 55,
0, 54, 54, 54, 54, 54, 0, 54, 84, 0,
0, 0, 84, 84, 84, 84, 84, 0, 84, 54,
54, 50, 54, 52, 0, 0, 55, 53, 0, 0,
55, 55, 55, 55, 55, 0, 55, 0, 49, 0,
0, 49, 49, 49, 0, 0, 0, 0, 55, 55,
0, 55, 50, 54, 50, 50, 50, 86, 0, 53,
0, 0, 0, 97, 0, 84, 0, 23, 112, 98,
50, 50, 3, 50, 0, 0, 82, 0, 0, 82,
82, 82, 55, 0, 0, 54, 0, 0, 86, 0,
25, 86, 99, 0, 97, 0, 0, 97, 0, 100,
98, 0, 0, 98, 50, 0, 86, 86, 0, 86,
0, 0, 97, 97, 55, 97, 0, 0, 98, 98,
0, 98, 26, 99, 85, 0, 99, 85, 85, 85,
100, 0, 0, 100, 56, 0, 50, 56, 56, 56,
86, 99, 99, 0, 99, 0, 97, 0, 100, 100,
0, 100, 98, 37, 0, 0, 95, 0, 0, 0,
0, 0, 52, 23, 0, 52, 52, 52, 3, 0,
0, 0, 86, 0, 0, 99, 0, 0, 97, 50,
0, 96, 100, 0, 98, 0, 25, 95, 0, 0,
95, 87, 69, 73, 78, 0, 0, 0, 53, 0,
0, 53, 53, 53, 0, 95, 95, 99, 95, 103,
105, 107, 96, 0, 100, 96, 88, 0, 26, 0,
0, 0, 87, 0, 54, 87, 0, 54, 54, 54,
96, 96, 0, 96, 0, 0, 0, 0, 49, 95,
87, 87, 0, 87, 0, 0, 22, 88, 0, 24,
88, 0, 0, 55, 0, 0, 55, 55, 55, 39,
0, 0, 0, 0, 96, 88, 88, 0, 88, 0,
0, 95, 0, 0, 87, 50, 0, 23, 50, 50,
50, 0, 3, 0, 0, 111, 5, 6, 7, 48,
0, 0, 0, 0, 0, 0, 96, 12, 13, 88,
25, 0, 34, 35, 36, 0, 87, 0, 0, 0,
0, 86, 20, 0, 86, 86, 86, 97, 0, 23,
97, 97, 97, 98, 3, 0, 98, 98, 98, 0,
0, 88, 26, 0, 188, 0, 0, 0, 0, 0,
49, 0, 25, 102, 0, 0, 99, 0, 0, 99,
99, 99, 0, 100, 0, 0, 100, 100, 100, 205,
22, 99, 0, 24, 0, 0, 0, 23, 124, 0,
102, 0, 3, 0, 26, 102, 102, 0, 102, 2,
102, 4, 5, 6, 7, 8, 9, 0, 10, 11,
25, 100, 102, 12, 13, 14, 15, 16, 17, 18,
19, 23, 22, 0, 0, 24, 3, 0, 20, 21,
95, 0, 0, 95, 95, 95, 0, 0, 0, 0,
0, 0, 26, 0, 25, 0, 0, 102, 0, 23,
0, 0, 0, 0, 3, 96, 0, 0, 96, 96,
96, 0, 0, 0, 0, 87, 0, 0, 87, 87,
87, 0, 25, 37, 189, 0, 26, 0, 102, 0,
0, 0, 23, 0, 0, 0, 0, 3, 40, 41,
88, 0, 0, 88, 88, 88, 42, 43, 44, 45,
46, 47, 0, 49, 26, 25, 0, 37, 0, 0,
0, 0, 0, 2, 0, 4, 5, 6, 7, 8,
9, 0, 10, 11, 99, 77, 0, 12, 13, 14,
15, 77, 17, 18, 19, 37, 0, 26, 0, 94,
0, 210, 20, 21, 92, 90, 74, 91, 0, 93,
0, 0, 106, 0, 160, 2, 0, 4, 5, 6,
7, 8, 9, 0, 10, 11, 66, 0, 37, 12,
13, 14, 15, 94, 17, 18, 19, 136, 92, 90,
70, 91, 0, 93, 20, 21, 102, 94, 0, 0,
40, 41, 92, 90, 103, 91, 95, 93, 42, 43,
44, 45, 46, 47, 0, 33, 5, 6, 7, 0,
181, 0, 182, 104, 0, 0, 0, 12, 13, 185,
0, 103, 34, 35, 36, 0, 103, 103, 0, 103,
95, 103, 20, 204, 0, 0, 0, 0, 0, 33,
5, 6, 7, 103, 95, 0, 0, 0, 0, 0,
0, 12, 13, 0, 94, 0, 34, 35, 36, 92,
90, 0, 91, 0, 93, 0, 20, 33, 5, 6,
7, 0, 0, 0, 0, 0, 167, 0, 103, 12,
13, 0, 0, 94, 34, 35, 36, 163, 92, 90,
0, 91, 0, 93, 20, 0, 0, 0, 0, 0,
111, 5, 6, 7, 0, 0, 0, 0, 0, 103,
0, 95, 12, 13, 0, 0, 0, 34, 35, 36,
94, 0, 0, 0, 164, 92, 90, 20, 91, 0,
93, 0, 0, 40, 41, 0, 0, 0, 0, 0,
95, 42, 43, 44, 45, 46, 47, 0, 0, 0,
0, 0, 0, 0, 0, 75, 76, 0, 0, 0,
0, 75, 76, 42, 43, 44, 45, 46, 47, 42,
43, 44, 45, 46, 47, 67, 68, 95, 0, 0,
0, 0, 0, 42, 43, 44, 45, 46, 47, 71,
72, 0, 0, 0, 0, 67, 68, 42, 43, 44,
45, 46, 47, 42, 43, 44, 45, 46, 47, 0,
0, 0, 0, 0, 177, 0, 0, 178, 179, 180,
0, 0, 71, 72, 38, 0, 0, 0, 186, 187,
42, 43, 44, 45, 46, 47, 42, 43, 44, 45,
46, 47, 186, 187, 82, 0, 0, 101, 0, 0,
42, 43, 44, 45, 46, 47, 0, 0, 0, 0,
109, 0, 0, 0, 0, 0, 0, 0, 0, 110,
113, 116, 117, 118, 101, 0, 121, 0, 0, 101,
101, 0, 101, 0, 101, 125, 0, 127, 0, 0,
128, 129, 0, 0, 130, 131, 101, 0, 132, 133,
94, 0, 0, 94, 170, 92, 90, 0, 91, 0,
93, 141, 142, 143, 144, 145, 146, 147, 0, 0,
150, 151, 152, 153, 154, 155, 156, 157, 158, 0,
94, 101, 0, 56, 0, 94, 94, 0, 94, 0,
94, 147, 0, 168, 169, 0, 0, 0, 0, 0,
0, 0, 94, 0, 0, 0, 0, 95, 173, 0,
56, 0, 101, 0, 0, 56, 56, 94, 56, 0,
56, 171, 92, 90, 0, 91, 0, 93, 0, 0,
0, 151, 56, 113, 94, 0, 147, 94, 0, 92,
90, 0, 91, 0, 93, 0, 0, 0, 197, 198,
199, 200, 201, 202, 203, 94, 206, 0, 0, 207,
92, 90, 0, 91, 0, 93, 0, 56, 94, 0,
0, 0, 94, 0, 95, 213, 214, 92, 90, 94,
91, 0, 93, 212, 92, 90, 0, 91, 0, 93,
184, 95, 0, 0, 0, 0, 0, 0, 56, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 193, 95, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 194, 95,
0, 0, 0, 0, 0, 0, 95,
};
short yycheck[] = { 10,
20, 95, 120, 10, 10, 10, 10, 10, 10, 37,
10, 27, 10, 10, 42, 43, 40, 45, 37, 47,
41, 258, 40, 42, 258, 30, 37, 10, 47, 10,
41, 42, 43, 44, 45, 37, 47, 10, 59, 41,
42, 43, 44, 45, 40, 47, 40, 165, 59, 60,
258, 62, 59, 59, 10, 59, 59, 59, 60, 59,
62, 59, 59, 10, 37, 93, 94, 285, 41, 42,
43, 44, 45, 1, 47, 94, 59, 97, 59, 259,
258, 40, 93, 94, 41, 41, 59, 60, 44, 62,
37, 93, 94, 41, 41, 42, 43, 44, 45, 10,
47, 10, 59, 59, 10, 209, 41, 10, 10, 44,
40, 59, 59, 60, 125, 62, 220, 91, 125, 125,
93, 94, 125, 125, 10, 125, 37, 125, 125, 91,
41, 42, 43, 44, 45, 37, 47, 10, 61, 41,
42, 43, 44, 45, 125, 47, 93, 94, 59, 60,
59, 62, 125, 59, 10, 10, 59, 59, 60, 175,
62, 41, 91, 10, 37, 259, 41, 41, 41, 42,
43, 44, 45, 59, 47, 10, 10, 40, 125, 59,
140, 93, 93, 94, 59, 59, 59, 60, 41, 62,
37, 93, 94, 10, 41, 42, 43, 44, 45, 10,
47, 217, 41, 59, 59, 44, 59, 135, 41, 123,
44, 44, 59, 60, 125, 62, 125, 94, 59, 125,
93, 94, 125, 125, 59, 59, 37, 41, 41, 196,
41, 42, 43, 44, 45, 41, 47, 10, 44, 125,
162, -1, 59, -1, 10, -1, 93, 94, 59, 60,
210, 62, 125, 264, 10, -1, 267, 268, 269, -1,
-1, 221, 264, -1, 192, 267, 268, 269, -1, 125,
125, 37, -1, -1, 285, -1, 42, 43, 125, 45,
208, 47, 93, 94, 212, 41, 59, 43, 44, 45,
125, 264, 10, 59, 267, 268, 269, -1, -1, -1,
-1, -1, -1, 59, 60, -1, 62, -1, 125, -1,
-1, -1, -1, 258, 125, -1, 258, 264, -1, 37,
267, 268, 269, 41, 42, 43, 44, 45, 94, 47,
275, 276, 277, 275, 276, 277, -1, 93, -1, -1,
10, 59, 60, -1, 62, -1, -1, -1, -1, -1,
10, -1, 125, 264, -1, -1, 267, 268, 269, 125,
-1, -1, 264, -1, -1, 267, 268, 269, -1, 125,
-1, 41, -1, -1, 44, 93, 94, 37, 10, -1,
-1, 41, 42, 43, 44, 45, -1, 47, -1, 59,
60, 264, 62, -1, 267, 268, 269, -1, -1, 59,
60, -1, 62, -1, -1, 37, -1, 125, -1, 41,
42, 43, 44, 45, 10, 47, -1, 264, -1, -1,
267, 268, 269, 93, -1, -1, -1, 59, 60, -1,
62, -1, -1, 93, 94, -1, -1, -1, -1, -1,
10, 37, -1, -1, -1, 41, 42, 43, 44, 45,
-1, 47, -1, 264, -1, 125, 267, 268, 269, -1,
-1, 93, -1, 59, 60, 125, 62, 37, -1, 10,
-1, 41, 42, 43, 44, 45, -1, 47, 37, -1,
-1, -1, 41, 42, 43, 44, 45, -1, 47, 59,
60, 10, 62, 125, -1, -1, 37, 93, -1, -1,
41, 42, 43, 44, 45, -1, 47, -1, 264, -1,
-1, 267, 268, 269, -1, -1, -1, -1, 59, 60,
-1, 62, 41, 93, 43, 44, 45, 10, -1, 125,
-1, -1, -1, 10, -1, 94, -1, 40, 41, 10,
59, 60, 45, 62, -1, -1, 264, -1, -1, 267,
268, 269, 93, -1, -1, 125, -1, -1, 41, -1,
63, 44, 10, -1, 41, -1, -1, 44, -1, 10,
41, -1, -1, 44, 93, -1, 59, 60, -1, 62,
-1, -1, 59, 60, 125, 62, -1, -1, 59, 60,
-1, 62, 95, 41, 264, -1, 44, 267, 268, 269,
41, -1, -1, 44, 264, -1, 125, 267, 268, 269,
93, 59, 60, -1, 62, -1, 93, -1, 59, 60,
-1, 62, 93, 126, -1, -1, 10, -1, -1, -1,
-1, -1, 264, 40, -1, 267, 268, 269, 45, -1,
-1, -1, 125, -1, -1, 93, -1, -1, 125, 4,
-1, 10, 93, -1, 125, -1, 63, 41, -1, -1,
44, 10, 17, 18, 19, -1, -1, -1, 264, -1,
-1, 267, 268, 269, -1, 59, 60, 125, 62, 34,
35, 36, 41, -1, 125, 44, 10, -1, 95, -1,
-1, -1, 41, -1, 264, 44, -1, 267, 268, 269,
59, 60, -1, 62, -1, -1, -1, -1, 40, 93,
59, 60, -1, 62, -1, -1, 123, 41, -1, 126,
44, -1, -1, 264, -1, -1, 267, 268, 269, 61,
-1, -1, -1, -1, 93, 59, 60, -1, 62, -1,
-1, 125, -1, -1, 93, 264, -1, 40, 267, 268,
269, -1, 45, -1, -1, 258, 259, 260, 261, 91,
-1, -1, -1, -1, -1, -1, 125, 270, 271, 93,
63, -1, 275, 276, 277, -1, 125, -1, -1, -1,
-1, 264, 285, -1, 267, 268, 269, 264, -1, 40,
267, 268, 269, 264, 45, -1, 267, 268, 269, -1,
-1, 125, 95, -1, 159, -1, -1, -1, -1, -1,
40, -1, 63, 10, -1, -1, 264, -1, -1, 267,
268, 269, -1, 264, -1, -1, 267, 268, 269, 184,
123, 61, -1, 126, -1, -1, -1, 40, 41, -1,
37, -1, 45, -1, 95, 42, 43, -1, 45, 256,
47, 258, 259, 260, 261, 262, 263, -1, 265, 266,
63, 91, 59, 270, 271, 272, 273, 274, 275, 276,
277, 40, 123, -1, -1, 126, 45, -1, 285, 286,
264, -1, -1, 267, 268, 269, -1, -1, -1, -1,
-1, -1, 95, -1, 63, -1, -1, 94, -1, 40,
-1, -1, -1, -1, 45, 264, -1, -1, 267, 268,
269, -1, -1, -1, -1, 264, -1, -1, 267, 268,
269, -1, 63, 126, 93, -1, 95, -1, 125, -1,
-1, -1, 40, -1, -1, -1, -1, 45, 270, 271,
264, -1, -1, 267, 268, 269, 278, 279, 280, 281,
282, 283, -1, 40, 95, 63, -1, 126, -1, -1,
-1, -1, -1, 256, -1, 258, 259, 260, 261, 262,
263, -1, 265, 266, 61, 40, -1, 270, 271, 272,
273, 40, 275, 276, 277, 126, -1, 95, -1, 37,
-1, 284, 285, 286, 42, 43, 61, 45, -1, 47,
-1, -1, 61, -1, 91, 256, -1, 258, 259, 260,
261, 262, 263, -1, 265, 266, 61, -1, 126, 270,
271, 272, 273, 37, 275, 276, 277, 41, 42, 43,
61, 45, -1, 47, 285, 286, 61, 37, -1, -1,
270, 271, 42, 43, 10, 45, 94, 47, 278, 279,
280, 281, 282, 283, -1, 258, 259, 260, 261, -1,
60, -1, 62, 61, -1, -1, -1, 270, 271, 61,
-1, 37, 275, 276, 277, -1, 42, 43, -1, 45,
94, 47, 285, 61, -1, -1, -1, -1, -1, 258,
259, 260, 261, 59, 94, -1, -1, -1, -1, -1,
-1, 270, 271, -1, 37, -1, 275, 276, 277, 42,
43, -1, 45, -1, 47, -1, 285, 258, 259, 260,
261, -1, -1, -1, -1, -1, 59, -1, 94, 270,
271, -1, -1, 37, 275, 276, 277, 41, 42, 43,
-1, 45, -1, 47, 285, -1, -1, -1, -1, -1,
258, 259, 260, 261, -1, -1, -1, -1, -1, 125,
-1, 94, 270, 271, -1, -1, -1, 275, 276, 277,
37, -1, -1, -1, 41, 42, 43, 285, 45, -1,
47, -1, -1, 270, 271, -1, -1, -1, -1, -1,
94, 278, 279, 280, 281, 282, 283, -1, -1, -1,
-1, -1, -1, -1, -1, 270, 271, -1, -1, -1,
-1, 270, 271, 278, 279, 280, 281, 282, 283, 278,
279, 280, 281, 282, 283, 270, 271, 94, -1, -1,
-1, -1, -1, 278, 279, 280, 281, 282, 283, 270,
271, -1, -1, -1, -1, 270, 271, 278, 279, 280,
281, 282, 283, 278, 279, 280, 281, 282, 283, -1,
-1, -1, -1, -1, 264, -1, -1, 267, 268, 269,
-1, -1, 270, 271, 3, -1, -1, -1, 270, 271,
278, 279, 280, 281, 282, 283, 278, 279, 280, 281,
282, 283, 270, 271, 23, -1, -1, 10, -1, -1,
278, 279, 280, 281, 282, 283, -1, -1, -1, -1,
39, -1, -1, -1, -1, -1, -1, -1, -1, 48,
49, 50, 51, 52, 37, -1, 55, -1, -1, 42,
43, -1, 45, -1, 47, 64, -1, 66, -1, -1,
69, 70, -1, -1, 73, 74, 59, -1, 77, 78,
37, -1, -1, 10, 41, 42, 43, -1, 45, -1,
47, 90, 91, 92, 93, 94, 95, 96, -1, -1,
99, 100, 101, 102, 103, 104, 105, 106, 107, -1,
37, 94, -1, 10, -1, 42, 43, -1, 45, -1,
47, 120, -1, 122, 123, -1, -1, -1, -1, -1,
-1, -1, 59, -1, -1, -1, -1, 94, 137, -1,
37, -1, 125, -1, -1, 42, 43, 37, 45, -1,
47, 41, 42, 43, -1, 45, -1, 47, -1, -1,
-1, 160, 59, 162, 37, -1, 165, 94, -1, 42,
43, -1, 45, -1, 47, -1, -1, -1, 177, 178,
179, 180, 181, 182, 183, 37, 185, -1, -1, 188,
42, 43, -1, 45, -1, 47, -1, 94, 125, -1,
-1, -1, 37, -1, 94, 204, 205, 42, 43, 37,
45, -1, 47, 41, 42, 43, -1, 45, -1, 47,
93, 94, -1, -1, -1, -1, -1, -1, 125, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 93, 94, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 93, 94,
-1, -1, -1, -1, -1, -1, 94,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 286
#if YYDEBUG
char *yyname[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"UMINUS","LETTER","DIGIT",
"SQRT","LENGTH","_IF","FFF","EQ","_WHILE","_FOR","NE","LE","GE","INCR","DECR",
"_RETURN","_BREAK","_DEFINE","BASE","OBASE","SCALE","EQPL","EQMI","EQMUL",
"EQDIV","EQREM","EQEXP","_AUTO","DOT","QSTR",
};
char *yyrule[] = {
"$accept : start",
"start :",
"start : start stat tail",
"start : start def dargs ')' '{' dlist slist '}'",
"dlist : tail",
"dlist : dlist _AUTO dlets tail",
"stat : e",
"stat :",
"stat : QSTR",
"stat : LETTER '=' e",
"stat : LETTER '[' e ']' '=' e",
"stat : LETTER EQOP e",
"stat : LETTER '[' e ']' EQOP e",
"stat : _BREAK",
"stat : _RETURN '(' e ')'",
"stat : _RETURN '(' ')'",
"stat : _RETURN",
"stat : SCALE '=' e",
"stat : SCALE EQOP e",
"stat : BASE '=' e",
"stat : BASE EQOP e",
"stat : OBASE '=' e",
"stat : OBASE EQOP e",
"stat : '{' slist '}'",
"stat : FFF",
"stat : error",
"stat : _IF CRS BLEV '(' re ')' stat",
"stat : _WHILE CRS '(' re ')' stat BLEV",
"stat : fprefix CRS re ';' e ')' stat BLEV",
"stat : '~' LETTER '=' e",
"EQOP : EQPL",
"EQOP : EQMI",
"EQOP : EQMUL",
"EQOP : EQDIV",
"EQOP : EQREM",
"EQOP : EQEXP",
"fprefix : _FOR '(' e ';'",
"BLEV :",
"slist : stat",
"slist : slist tail stat",
"tail : '\\n'",
"tail : ';'",
"re : e EQ e",
"re : e '<' e",
"re : e '>' e",
"re : e NE e",
"re : e GE e",
"re : e LE e",
"re : e",
"e : e '+' e",
"e : e '-' e",
"e : '-' e",
"e : e '*' e",
"e : e '/' e",
"e : e '%' e",
"e : e '^' e",
"e : LETTER '[' e ']'",
"e : LETTER INCR",
"e : INCR LETTER",
"e : DECR LETTER",
"e : LETTER DECR",
"e : LETTER '[' e ']' INCR",
"e : INCR LETTER '[' e ']'",
"e : LETTER '[' e ']' DECR",
"e : DECR LETTER '[' e ']'",
"e : SCALE INCR",
"e : INCR SCALE",
"e : SCALE DECR",
"e : DECR SCALE",
"e : BASE INCR",
"e : INCR BASE",
"e : BASE DECR",
"e : DECR BASE",
"e : OBASE INCR",
"e : INCR OBASE",
"e : OBASE DECR",
"e : DECR OBASE",
"e : LETTER '(' cargs ')'",
"e : LETTER '(' ')'",
"e : cons",
"e : DOT cons",
"e : cons DOT cons",
"e : cons DOT",
"e : DOT",
"e : LETTER",
"e : LETTER '=' e",
"e : LETTER EQOP e",
"e : LETTER '[' e ']' '=' e",
"e : LETTER '[' e ']' EQOP e",
"e : LENGTH '(' e ')'",
"e : SCALE '(' e ')'",
"e : '(' e ')'",
"e : '?'",
"e : SQRT '(' e ')'",
"e : '~' LETTER",
"e : SCALE '=' e",
"e : SCALE EQOP e",
"e : BASE '=' e",
"e : BASE EQOP e",
"e : OBASE '=' e",
"e : OBASE EQOP e",
"e : SCALE",
"e : BASE",
"e : OBASE",
"cargs : eora",
"cargs : cargs ',' eora",
"eora : e",
"eora : LETTER '[' ']'",
"cons : constant",
"constant : '_'",
"constant : DIGIT",
"constant : constant DIGIT",
"CRS :",
"def : _DEFINE LETTER '('",
"dargs :",
"dargs : lora",
"dargs : dargs ',' lora",
"dlets : lora",
"dlets : dlets ',' lora",
"lora : LETTER",
"lora : LETTER '[' ']'",
};
#endif
#ifndef YYSTYPE
typedef int YYSTYPE;
#endif
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 10000
#define YYMAXDEPTH 10000
#endif
#endif
#define YYINITSTACKSIZE 200
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short *yyss;
short *yysslim;
YYSTYPE *yyvs;
int yystacksize;
#line 408 "bc.y"
# define error 256
static int peekc = -1;
static int sargc;
static int ifile;
static char **sargv;
static char funtab[52] = {
01,0,02,0,03,0,04,0,05,0,06,0,07,0,010,0,011,0,012,0,013,0,014,0,015,0,016,0,017,0,
020,0,021,0,022,0,023,0,024,0,025,0,026,0,027,0,030,0,031,0,032,0 };
static char atab[52] = {
0241,0,0242,0,0243,0,0244,0,0245,0,0246,0,0247,0,0250,0,0251,0,0252,0,0253,0,
0254,0,0255,0,0256,0,0257,0,0260,0,0261,0,0262,0,0263,0,0264,0,0265,0,0266,0,
0267,0,0270,0,0271,0,0272,0};
static char *letr[26] = {
"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z" } ;
/*static char *dot = { "." };*/
int
yylex(void){
int c, ch;
restart:
c = getch();
peekc = -1;
while( c == ' ' || c == '\t' ) c = getch();
if(c == '\\'){
getch();
goto restart;
}
if( c<= 'z' && c >= 'a' ) {
/* look ahead to look for reserved words */
peekc = getch();
if( peekc >= 'a' && peekc <= 'z' ){ /* must be reserved word */
if( c=='i' && peekc=='f' ){ c=_IF; goto skip; }
if( c=='w' && peekc=='h' ){ c=_WHILE; goto skip; }
if( c=='f' && peekc=='o' ){ c=_FOR; goto skip; }
if( c=='s' && peekc=='q' ){ c=SQRT; goto skip; }
if( c=='r' && peekc=='e' ){ c=_RETURN; goto skip; }
if( c=='b' && peekc=='r' ){ c=_BREAK; goto skip; }
if( c=='d' && peekc=='e' ){ c=_DEFINE; goto skip; }
if( c=='s' && peekc=='c' ){ c= SCALE; goto skip; }
if( c=='b' && peekc=='a' ){ c=BASE; goto skip; }
if( c=='i' && peekc == 'b'){ c=BASE; goto skip; }
if( c=='o' && peekc=='b' ){ c=OBASE; goto skip; }
if( c=='d' && peekc=='i' ){ c=FFF; goto skip; }
if( c=='a' && peekc=='u' ){ c=_AUTO; goto skip; }
if( c == 'l' && peekc=='e'){ c=LENGTH; goto skip; }
if( c == 'q' && peekc == 'u'){getout();}
/* could not be found */
return( error );
skip: /* skip over rest of word */
peekc = -1;
while( (ch = getch()) >= 'a' && ch <= 'z' );
peekc = ch;
return( c );
}
/* usual case; just one single letter */
yylval = (intptr_t)letr[c-'a'];
return( LETTER );
}
if( c>= '0' && c <= '9' || c>= 'A' && c<= 'F' ){
yylval = c;
return( DIGIT );
}
switch( c ){
case '.': return( DOT );
case '=':
switch( peekc = getch() ){
case '=': c=EQ; goto gotit;
case '+': c=EQPL; goto gotit;
case '-': c=EQMI; goto gotit;
case '*': c=EQMUL; goto gotit;
case '/': c=EQDIV; goto gotit;
case '%': c=EQREM; goto gotit;
case '^': c=EQEXP; goto gotit;
default: return( '=' );
gotit: peekc = -1; return(c);
}
case '+': return( cpeek( '+', INCR, cpeek( '=', EQPL, '+') ) );
case '-': return( cpeek( '-', DECR, cpeek( '=', EQMI, '-') ) ) ;
case '<': return( cpeek( '=', LE, '<' ) );
case '>': return( cpeek( '=', GE, '>' ) );
case '!': return( cpeek( '=', NE, '!' ) );
case '/':
if((peekc = getch()) == '*'){
peekc = -1;
while((getch() != '*') || ((peekc = getch()) != '/'));
peekc = -1;
goto restart;
}
else if (peekc == '=') {
c=EQDIV;
goto gotit;
}
else return(c);
case '*':
return( cpeek( '=', EQMUL, '*' ) );
case '%':
return( cpeek( '=', EQREM, '%' ) );
case '^':
return( cpeek( '=', EQEXP, '^' ) );
case '"':
yylval = (intptr_t)str;
while((c=getch()) != '"'){*str++ = c;
if(str >= &string[sizeof string - 1]){yyerror("string space exceeded");
getout();
}
}
*str++ = '\0';
return(QSTR);
default: return( c );
}
}
static int
cpeek(int c, int yes, int no){
if( (peekc=getch()) != c ) return( no );
else {
peekc = -1;
return( yes );
}
}
static int
getch(void){
int ch;
loop:
ch = (peekc < 0) ? getc(in) : peekc;
peekc = -1;
if(ch != EOF)return(ch);
if(++ifile > sargc){
if(ifile >= sargc+2)getout();
in = stdin;
ln = 0;
goto loop;
}
fclose(in);
if((in = fopen(sargv[ifile],"r")) != NULL){
ln = 0;
ss = sargv[ifile];
goto loop;
}
cantopen(sargv[ifile]);
return EOF;
}
# define b_sp_max 3000
static intptr_t b_space [ b_sp_max ];
static intptr_t * b_sp_nxt = { b_space };
static int bdebug = 0;
static intptr_t
bundle(int a, ...){
intptr_t i, *q;
va_list ap;
i = a;
q = b_sp_nxt;
if( bdebug ) printf("bundle %ld elements at %lo\n",(long)i, (long)q );
va_start(ap, a);
while(i-- > 0){
if( b_sp_nxt >= & b_space[b_sp_max] ) yyerror( "bundling space exceeded" );
* b_sp_nxt++ = va_arg(ap, intptr_t);
}
va_end(ap);
* b_sp_nxt++ = 0;
yyval = (intptr_t)q;
return( (intptr_t)q );
}
static void
routput(intptr_t *p) {
if( bdebug ) printf("routput(%lo)\n", (long)p );
if( p >= &b_space[0] && p < &b_space[b_sp_max]){
/* part of a bundle */
while( *p != 0 ) routput( (intptr_t *)*p++ );
}
else printf( (char *)p ); /* character string */
}
static void
output(intptr_t *p) {
routput( p );
b_sp_nxt = & b_space[0];
printf( "\n" );
fflush(stdout);
cp = cary;
crs = rcrs;
}
static void
conout(intptr_t p, intptr_t s) {
printf("[");
routput( (intptr_t *)p );
printf("]s%s\n", (char *)s );
fflush(stdout);
lev--;
}
static void
yyerror(const char *s) {
if(ifile > sargc)ss="teletype";
fprintf(stderr, "%s on line %d, %s\n",
s ,ss?ln+1:0,ss?ss:"command line");
cp = cary;
crs = rcrs;
bindx = 0;
lev = 0;
b_sp_nxt = &b_space[0];
}
static void
cantopen(const char *fn)
{
char spc[280];
char *oss = ss;
ss = 0;
snprintf(spc, sizeof spc, "can't open input file %s", fn);
yyerror(spc);
ss = oss;
}
static void
pp(intptr_t s) {
/* puts the relevant stuff on pre and post for the letter s */
bundle(3, "S", s, pre );
pre = (intptr_t *)yyval;
bundle(4, post, "L", s, "s." );
post = (intptr_t *)yyval;
}
static void
tp(intptr_t s) { /* same as pp, but for temps */
bundle(3, "0S", s, pre );
pre = (intptr_t *)yyval;
bundle(4, post, "L", s, "s." );
post = (intptr_t *)yyval;
}
static void
yyinit(int argc,char **argv) {
signal(SIGINT, SIG_IGN);
sargv=argv;
sargc= -- argc;
if(sargc == 0)in=stdin;
else if((in = fopen(sargv[1],"r")) == NULL) {
cantopen(sargv[1]);
exit(0);
}
ifile = 1;
ln = 0;
ss = sargv[1];
}
static intptr_t *
getout(void){
printf("q");
fflush(stdout);
exit(0);
/*NOTREACHED*/
return(NULL);
}
static intptr_t *
getf(intptr_t p) {
return(intptr_t *)(&funtab[2*(*((char *)p) -0141)]);
}
static intptr_t *
geta(intptr_t p) {
return(intptr_t *)(&atab[2*(*((char *)p) - 0141)]);
}
int
main(int argc, char **argv)
{
extern int yyparse(void);
const char optstring[] = "cdl";
int p[2];
int i;
int cflag = 0, lflag = 0;
#ifdef __GLIBC__
putenv("POSIXLY_CORRECT=1");
#endif
while ((i = getopt(argc, argv, optstring)) != EOF) {
switch (i) {
case 'd':
case 'c':
cflag = 1;
break;
case 'l':
lflag = 1;
break;
default:
exit(2);
}
}
argv += optind - 1, argc -= optind - 1;
if (cflag) {
yyinit(argc, argv);
yyparse();
exit(0);
}
if (lflag) {
*argv-- = LIBB;
argc++;
}
pipe(p);
if (fork()==0) {
close(1);
dup(p[1]);
close(p[0]);
close(p[1]);
yyinit(argc, argv);
yyparse();
exit(0);
}
close(0);
dup(p[0]);
close(p[0]);
close(p[1]);
execl(DC, "dc", "-", NULL);
execl("/usr/5bin/dc", "dc", "-", NULL);
execl("/usr/local/bin/dc", "dc", "-", NULL);
execl("/usr/contrib/bin/dc", "dc", "-", NULL);
execl("/usr/bin/dc", "dc", "-", NULL);
return(1);
}
#line 1082 "y.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
int yyparse __P((void));
static int yygrowstack __P((void));
static int yygrowstack()
{
int newsize, i;
short *newss;
YYSTYPE *newvs;
if ((newsize = yystacksize) == 0)
newsize = YYINITSTACKSIZE;
else if (newsize >= YYMAXDEPTH)
return -1;
else if ((newsize *= 2) > YYMAXDEPTH)
newsize = YYMAXDEPTH;
i = yyssp - yyss;
if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)
return -1;
yyss = newss;
yyssp = newss + i;
if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)
return -1;
yyvs = newvs;
yyvsp = newvs + i;
yystacksize = newsize;
yysslim = yyss + newsize - 1;
return 0;
}
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
int yym, yyn, yystate;
#if YYDEBUG
char *yys;
if ((yys = getenv("YYDEBUG")) != NULL)
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
if (yyss == NULL && yygrowstack()) goto yyoverflow;
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if ((yyn = yydefred[yystate]) != 0) 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("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, shifting to state %d\n",
YYPREFIX, yystate, yytable[yyn]);
#endif
if (yyssp >= yysslim && yygrowstack())
{
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;
goto yynewerror;
yynewerror:
yyerror("syntax error");
goto yyerrlab;
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("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
if (yyssp >= yysslim && yygrowstack())
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: error recovery discarding state %d\n",
YYPREFIX, *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("%sdebug: state %d, error recovery discards token %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 2:
#line 118 "bc.y"
{ output( (intptr_t *)yyvsp[-1] );}
break;
case 3:
#line 120 "bc.y"
{ bundle( 6,pre, yyvsp[-1], post ,"0",numb[lev],"Q");
conout( yyval, yyvsp[-6] );
rcrs = crs;
output( (intptr_t *)"" );
lev = bindx = 0;
}
break;
case 6:
#line 133 "bc.y"
{ bundle(2, yyvsp[0], "ps." ); }
break;
case 7:
#line 135 "bc.y"
{ bundle(1, "" ); }
break;
case 8:
#line 137 "bc.y"
{ bundle(3,"[",yyvsp[0],"]P");}
break;
case 9:
#line 139 "bc.y"
{ bundle(3, yyvsp[0], "s", yyvsp[-2] ); }
break;
case 10:
#line 141 "bc.y"
{ bundle(4, yyvsp[0], yyvsp[-3], ":", geta(yyvsp[-5])); }
break;
case 11:
#line 143 "bc.y"
{ bundle(6, "l", yyvsp[-2], yyvsp[0], yyvsp[-1], "s", yyvsp[-2] ); }
break;
case 12:
#line 145 "bc.y"
{ bundle(8,yyvsp[-3], ";", geta(yyvsp[-5]), yyvsp[0], yyvsp[-1], yyvsp[-3], ":", geta(yyvsp[-5]));}
break;
case 13:
#line 147 "bc.y"
{ bundle(2, numb[lev-bstack[bindx-1]], "Q" ); }
break;
case 14:
#line 149 "bc.y"
{ bundle(4, yyvsp[-1], post, numb[lev], "Q" ); }
break;
case 15:
#line 151 "bc.y"
{ bundle(4, "0", post, numb[lev], "Q" ); }
break;
case 16:
#line 153 "bc.y"
{ bundle(4,"0",post,numb[lev],"Q"); }
break;
case 17:
#line 155 "bc.y"
{ bundle(2, yyvsp[0], "k"); }
break;
case 18:
#line 157 "bc.y"
{ bundle(4,"K",yyvsp[0],yyvsp[-1],"k"); }
break;
case 19:
#line 159 "bc.y"
{ bundle(2,yyvsp[0], "i"); }
break;
case 20:
#line 161 "bc.y"
{ bundle(4,"I",yyvsp[0],yyvsp[-1],"i"); }
break;
case 21:
#line 163 "bc.y"
{ bundle(2,yyvsp[0],"o"); }
break;
case 22:
#line 165 "bc.y"
{ bundle(4,"O",yyvsp[0],yyvsp[-1],"o"); }
break;
case 23:
#line 167 "bc.y"
{ yyval = yyvsp[-1]; }
break;
case 24:
#line 169 "bc.y"
{ bundle(1,"fY"); }
break;
case 25:
#line 171 "bc.y"
{ bundle(1,"c"); }
break;
case 26:
#line 173 "bc.y"
{ conout( yyvsp[0], yyvsp[-5] );
bundle(3, yyvsp[-2], yyvsp[-5], " " );
}
break;
case 27:
#line 177 "bc.y"
{ bundle(3, yyvsp[-1], yyvsp[-3], yyvsp[-5] );
conout( yyval, yyvsp[-5] );
bundle(3, yyvsp[-3], yyvsp[-5], " " );
}
break;
case 28:
#line 182 "bc.y"
{ bundle(5, yyvsp[-1], yyvsp[-3], "s.", yyvsp[-5], yyvsp[-6] );
conout( yyval, yyvsp[-6] );
bundle(5, yyvsp[-7], "s.", yyvsp[-5], yyvsp[-6], " " );
}
break;
case 29:
#line 187 "bc.y"
{ bundle(3,yyvsp[0],"S",yyvsp[-2]); }
break;
case 30:
#line 191 "bc.y"
{ yyval = (intptr_t)"+"; }
break;
case 31:
#line 193 "bc.y"
{ yyval = (intptr_t)"-"; }
break;
case 32:
#line 195 "bc.y"
{ yyval = (intptr_t)"*"; }
break;
case 33:
#line 197 "bc.y"
{ yyval = (intptr_t)"/"; }
break;
case 34:
#line 199 "bc.y"
{ yyval = (intptr_t)"%%"; }
break;
case 35:
#line 201 "bc.y"
{ yyval = (intptr_t)"^"; }
break;
case 36:
#line 205 "bc.y"
{ yyval = yyvsp[-1]; }
break;
case 37:
#line 209 "bc.y"
{ --bindx; }
break;
case 39:
#line 214 "bc.y"
{ bundle(2, yyvsp[-2], yyvsp[0] ); }
break;
case 40:
#line 218 "bc.y"
{ln++;}
break;
case 42:
#line 223 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "=" ); }
break;
case 43:
#line 225 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], ">" ); }
break;
case 44:
#line 227 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "<" ); }
break;
case 45:
#line 229 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "!=" ); }
break;
case 46:
#line 231 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "!>" ); }
break;
case 47:
#line 233 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "!<" ); }
break;
case 48:
#line 235 "bc.y"
{ bundle(2, yyvsp[0], " 0!=" ); }
break;
case 49:
#line 239 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "+" ); }
break;
case 50:
#line 241 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "-" ); }
break;
case 51:
#line 243 "bc.y"
{ bundle(3, " 0", yyvsp[0], "-" ); }
break;
case 52:
#line 245 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "*" ); }
break;
case 53:
#line 247 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "/" ); }
break;
case 54:
#line 249 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "%%" ); }
break;
case 55:
#line 251 "bc.y"
{ bundle(3, yyvsp[-2], yyvsp[0], "^" ); }
break;
case 56:
#line 253 "bc.y"
{ bundle(3,yyvsp[-1], ";", geta(yyvsp[-3])); }
break;
case 57:
#line 255 "bc.y"
{ bundle(4, "l", yyvsp[-1], "d1+s", yyvsp[-1] ); }
break;
case 58:
#line 257 "bc.y"
{ bundle(4, "l", yyvsp[0], "1+ds", yyvsp[0] ); }
break;
case 59:
#line 259 "bc.y"
{ bundle(4, "l", yyvsp[0], "1-ds", yyvsp[0] ); }
break;
case 60:
#line 261 "bc.y"
{ bundle(4, "l", yyvsp[-1], "d1-s", yyvsp[-1] ); }
break;
case 61:
#line 263 "bc.y"
{ bundle(7,yyvsp[-2],";",geta(yyvsp[-4]),"d1+",yyvsp[-2],":",geta(yyvsp[-4])); }
break;
case 62:
#line 265 "bc.y"
{ bundle(7,yyvsp[-1],";",geta(yyvsp[-3]),"1+d",yyvsp[-1],":",geta(yyvsp[-3])); }
break;
case 63:
#line 267 "bc.y"
{ bundle(7,yyvsp[-2],";",geta(yyvsp[-4]),"d1-",yyvsp[-2],":",geta(yyvsp[-4])); }
break;
case 64:
#line 269 "bc.y"
{ bundle(7,yyvsp[-1],";",geta(yyvsp[-3]),"1-d",yyvsp[-1],":",geta(yyvsp[-3])); }
break;
case 65:
#line 271 "bc.y"
{ bundle(1,"Kd1+k"); }
break;
case 66:
#line 273 "bc.y"
{ bundle(1,"K1+dk"); }
break;
case 67:
#line 275 "bc.y"
{ bundle(1,"Kd1-k"); }
break;
case 68:
#line 277 "bc.y"
{ bundle(1,"K1-dk"); }
break;
case 69:
#line 279 "bc.y"
{ bundle(1,"Id1+i"); }
break;
case 70:
#line 281 "bc.y"
{ bundle(1,"I1+di"); }
break;
case 71:
#line 283 "bc.y"
{ bundle(1,"Id1-i"); }
break;
case 72:
#line 285 "bc.y"
{ bundle(1,"I1-di"); }
break;
case 73:
#line 287 "bc.y"
{ bundle(1,"Od1+o"); }
break;
case 74:
#line 289 "bc.y"
{ bundle(1,"O1+do"); }
break;
case 75:
#line 291 "bc.y"
{ bundle(1,"Od1-o"); }
break;
case 76:
#line 293 "bc.y"
{ bundle(1,"O1-do"); }
break;
case 77:
#line 295 "bc.y"
{ bundle(4, yyvsp[-1], "l", getf(yyvsp[-3]), "x" ); }
break;
case 78:
#line 297 "bc.y"
{ bundle(3, "l", getf(yyvsp[-2]), "x" ); }
break;
case 79:
#line 299 "bc.y"
{ bundle(2, " ", yyvsp[0] ); }
break;
case 80:
#line 301 "bc.y"
{ bundle(2, " .", yyvsp[0] ); }
break;
case 81:
#line 303 "bc.y"
{ bundle(4, " ", yyvsp[-2], ".", yyvsp[0] ); }
break;
case 82:
#line 305 "bc.y"
{ bundle(3, " ", yyvsp[-1], "." ); }
break;
case 83:
#line 307 "bc.y"
{ yyval = (intptr_t)"l."; }
break;
case 84:
#line 309 "bc.y"
{ bundle(2, "l", yyvsp[0] ); }
break;
case 85:
#line 311 "bc.y"
{ bundle(3, yyvsp[0], "ds", yyvsp[-2] ); }
break;
case 86:
#line 313 "bc.y"
{ bundle(6, "l", yyvsp[-2], yyvsp[0], yyvsp[-1], "ds", yyvsp[-2] ); }
break;
case 87:
#line 315 "bc.y"
{ bundle(5,yyvsp[0],"d",yyvsp[-3],":",geta(yyvsp[-5])); }
break;
case 88:
#line 317 "bc.y"
{ bundle(9,yyvsp[-3],";",geta(yyvsp[-5]),yyvsp[0],yyvsp[-1],"d",yyvsp[-3],":",geta(yyvsp[-5])); }
break;
case 89:
#line 319 "bc.y"
{ bundle(2,yyvsp[-1],"Z"); }
break;
case 90:
#line 321 "bc.y"
{ bundle(2,yyvsp[-1],"X"); }
break;
case 91:
#line 323 "bc.y"
{ yyval = yyvsp[-1]; }
break;
case 92:
#line 325 "bc.y"
{ bundle(1, "?" ); }
break;
case 93:
#line 327 "bc.y"
{ bundle(2, yyvsp[-1], "v" ); }
break;
case 94:
#line 329 "bc.y"
{ bundle(2,"L",yyvsp[0]); }
break;
case 95:
#line 331 "bc.y"
{ bundle(2,yyvsp[0],"dk"); }
break;
case 96:
#line 333 "bc.y"
{ bundle(4,"K",yyvsp[0],yyvsp[-1],"dk"); }
break;
case 97:
#line 335 "bc.y"
{ bundle(2,yyvsp[0],"di"); }
break;
case 98:
#line 337 "bc.y"
{ bundle(4,"I",yyvsp[0],yyvsp[-1],"di"); }
break;
case 99:
#line 339 "bc.y"
{ bundle(2,yyvsp[0],"do"); }
break;
case 100:
#line 341 "bc.y"
{ bundle(4,"O",yyvsp[0],yyvsp[-1],"do"); }
break;
case 101:
#line 343 "bc.y"
{ bundle(1,"K"); }
break;
case 102:
#line 345 "bc.y"
{ bundle(1,"I"); }
break;
case 103:
#line 347 "bc.y"
{ bundle(1,"O"); }
break;
case 105:
#line 352 "bc.y"
{ bundle(2, yyvsp[-2], yyvsp[0] ); }
break;
case 107:
#line 356 "bc.y"
{bundle(2,"l",geta(yyvsp[-2])); }
break;
case 108:
#line 360 "bc.y"
{ *cp++ = '\0'; }
break;
case 109:
#line 364 "bc.y"
{ yyval = (intptr_t)cp; *cp++ = '_'; }
break;
case 110:
#line 366 "bc.y"
{ yyval = (intptr_t)cp; *cp++ = yyvsp[0]; }
break;
case 111:
#line 368 "bc.y"
{ *cp++ = yyvsp[0]; }
break;
case 112:
#line 372 "bc.y"
{ yyval = (intptr_t)cp; *cp++ = crs++; *cp++ = '\0';
if(crs == '[')crs+=3;
if(crs == 'a')crs='{';
if(crs >= 0241){yyerror("program too big");
getout();
}
bstack[bindx++] = lev++; }
break;
case 113:
#line 382 "bc.y"
{ yyval = (intptr_t)getf(yyvsp[-1]);
pre = (intptr_t *)"";
post = (intptr_t *)"";
lev = 1;
bstack[bindx=0] = 0;
}
break;
case 115:
#line 392 "bc.y"
{ pp( yyvsp[0] ); }
break;
case 116:
#line 394 "bc.y"
{ pp( yyvsp[0] ); }
break;
case 117:
#line 398 "bc.y"
{ tp(yyvsp[0]); }
break;
case 118:
#line 400 "bc.y"
{ tp(yyvsp[0]); }
break;
case 120:
#line 404 "bc.y"
{ yyval = (intptr_t)geta(yyvsp[-2]); }
break;
#line 1716 "y.tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state 0 to\
state %d\n", YYPREFIX, 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("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, 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("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yyssp, yystate);
#endif
if (yyssp >= yysslim && yygrowstack())
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}
syntax highlighted by Code2HTML, v. 0.9.1