Bug Summary

File:src/usr.bin/bc/obj/bc.c
Warning:line 1284, column 26
Use of zero-allocated memory

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name bc.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.bin/bc/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/usr.bin/bc -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused -fdebug-compilation-dir=/usr/src/usr.bin/bc/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c bc.c
1#include <stdlib.h>
2#include <string.h>
3#define YYBYACC1 1
4#define YYMAJOR1 1
5#define YYMINOR9 9
6#define YYLEXyylex() yylex()
7#define YYEMPTY-1 -1
8#define yyclearin(yychar=(-1)) (yychar=(YYEMPTY-1))
9#define yyerrok(yyerrflag=0) (yyerrflag=0)
10#define YYRECOVERING()(yyerrflag!=0) (yyerrflag!=0)
11#define YYPREFIX"yy" "yy"
12#line 2 "/usr/src/usr.bin/bc/bc.y"
13/* $OpenBSD: bc.y,v 1.52 2020/06/30 14:27:02 otto Exp $ */
14
15/*
16 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
17 *
18 * Permission to use, copy, modify, and distribute this software for any
19 * purpose with or without fee is hereby granted, provided that the above
20 * copyright notice and this permission notice appear in all copies.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
23 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
25 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
27 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
28 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 */
30
31/*
32 * This implementation of bc(1) uses concepts from the original 4.4
33 * BSD bc(1). The code itself is a complete rewrite, based on the
34 * Posix defined bc(1) grammar. Other differences include type safe
35 * usage of pointers to build the tree of emitted code, typed yacc
36 * rule values, dynamic allocation of all data structures and a
37 * completely rewritten lexical analyzer using lex(1).
38 *
39 * Some effort has been made to make sure that the generated code is
40 * the same as the code generated by the older version, to provide
41 * easy regression testing.
42 */
43
44#include <sys/types.h>
45#include <sys/wait.h>
46
47#include <ctype.h>
48#include <err.h>
49#include <errno(*__errno()).h>
50#include <histedit.h>
51#include <limits.h>
52#include <search.h>
53#include <signal.h>
54#include <stdarg.h>
55#include <string.h>
56#include <unistd.h>
57
58#include "extern.h"
59#include "pathnames.h"
60
61#define END_NODE((ssize_t) -1) ((ssize_t) -1)
62#define CONST_STRING((ssize_t) -2) ((ssize_t) -2)
63#define ALLOC_STRING((ssize_t) -3) ((ssize_t) -3)
64
65struct tree {
66 ssize_t index;
67 union {
68 char *astr;
69 const char *cstr;
70 } u;
71};
72
73int yyparse(void);
74int yywrap(void);
75
76int fileindex;
77int sargc;
78char **sargv;
79char *filename;
80char *cmdexpr;
81
82static void grow(void);
83static ssize_t cs(const char *);
84static ssize_t as(const char *);
85static ssize_t node(ssize_t, ...);
86static void emit(ssize_t, int);
87static void emit_macro(int, ssize_t);
88static void free_tree(void);
89static ssize_t numnode(int);
90static ssize_t lookup(char *, size_t, char);
91static ssize_t letter_node(char *);
92static ssize_t array_node(char *);
93static ssize_t function_node(char *);
94
95static void add_par(ssize_t);
96static void add_local(ssize_t);
97static void warning(const char *);
98static void init(void);
99static __dead__attribute__((__noreturn__)) void usage(void);
100static char *escape(const char *);
101
102static ssize_t instr_sz = 0;
103static struct tree *instructions = NULL((void *)0);
104static ssize_t current = 0;
105static int macro_char = '0';
106static int reset_macro_char = '0';
107static int nesting = 0;
108static int breakstack[16];
109static int breaksp = 0;
110static ssize_t prologue;
111static ssize_t epilogue;
112static bool_Bool st_has_continue;
113static char str_table[UCHAR_MAX(127*2 +1)][2];
114static bool_Bool do_fork = true1;
115static u_short var_count;
116static pid_t dc;
117
118extern char *__progname;
119
120#define BREAKSTACK_SZ(sizeof(breakstack)/sizeof(breakstack[0])) (sizeof(breakstack)/sizeof(breakstack[0]))
121
122/* These values are 4.4BSD bc compatible */
123#define FUNC_CHAR0x01 0x01
124#define ARRAY_CHAR0xa1 0xa1
125
126/* Skip '\0', [, \ and ] */
127#define ENCODE(c)((c) < '[' ? (c) : (c) + 3); ((c) < '[' ? (c) : (c) + 3);
128#define VAR_BASE(256-4) (256-4)
129#define MAX_VARIABLES((256-4) * (256-4)) (VAR_BASE(256-4) * VAR_BASE(256-4))
130
131#line 124 "/usr/src/usr.bin/bc/bc.y"
132#ifndef YYSTYPE_DEFINED
133#define YYSTYPE_DEFINED
134typedef union {
135 ssize_t node;
136 struct lvalue lvalue;
137 const char *str;
138 char *astr;
139} YYSTYPE;
140#endif /* YYSTYPE_DEFINED */
141#line 142 "bc.c"
142#define COMMA257 257
143#define SEMICOLON258 258
144#define LPAR259 259
145#define RPAR260 260
146#define LBRACE261 261
147#define RBRACE262 262
148#define LBRACKET263 263
149#define RBRACKET264 264
150#define DOT265 265
151#define NEWLINE266 266
152#define LETTER267 267
153#define NUMBER268 268
154#define STRING269 269
155#define DEFINE270 270
156#define BREAK271 271
157#define QUIT272 272
158#define LENGTH273 273
159#define RETURN274 274
160#define FOR275 275
161#define IF276 276
162#define WHILE277 277
163#define SQRT278 278
164#define SCALE279 279
165#define IBASE280 280
166#define OBASE281 281
167#define AUTO282 282
168#define CONTINUE283 283
169#define ELSE284 284
170#define PRINT285 285
171#define BOOL_OR286 286
172#define BOOL_AND287 287
173#define BOOL_NOT288 288
174#define EQUALS289 289
175#define LESS_EQ290 290
176#define GREATER_EQ291 291
177#define UNEQUALS292 292
178#define LESS293 293
179#define GREATER294 294
180#define ASSIGN_OP295 295
181#define PLUS296 296
182#define MINUS297 297
183#define MULTIPLY298 298
184#define DIVIDE299 299
185#define REMAINDER300 300
186#define EXPONENT301 301
187#define UMINUS302 302
188#define INCR303 303
189#define DECR304 304
190#define YYERRCODE256 256
191const short yylhs[] =
192 { -1,
193 0, 0, 7, 7, 7, 7, 16, 16, 16, 16,
194 18, 18, 18, 18, 18, 18, 11, 11, 17, 17,
195 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
196 17, 3, 19, 5, 6, 21, 21, 20, 20, 23,
197 23, 23, 23, 22, 22, 22, 24, 24, 24, 24,
198 8, 8, 2, 2, 2, 10, 10, 14, 14, 14,
199 14, 14, 14, 14, 15, 15, 15, 9, 9, 4,
200 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
201 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
202 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
203 1, 1, 1, 13, 13, 12, 12,
204};
205const short yylen[] =
206 { 2,
207 0, 2, 2, 1, 2, 2, 0, 1, 3, 2,
208 0, 1, 2, 3, 2, 3, 0, 1, 1, 3,
209 1, 1, 1, 1, 2, 11, 7, 11, 7, 3,
210 2, 0, 0, 9, 3, 0, 1, 0, 1, 1,
211 3, 3, 5, 0, 3, 3, 1, 3, 3, 5,
212 0, 1, 1, 3, 5, 0, 1, 3, 3, 3,
213 3, 3, 3, 1, 0, 1, 2, 0, 1, 1,
214 1, 1, 3, 4, 2, 3, 3, 3, 3, 3,
215 3, 2, 2, 2, 2, 3, 4, 4, 4, 2,
216 5, 5, 3, 3, 3, 3, 3, 3, 1, 4,
217 1, 1, 1, 1, 3, 1, 1,
218};
219const short yydefred[] =
220 { 1,
221 0, 0, 0, 0, 71, 0, 72, 21, 0, 22,
222 24, 0, 0, 0, 0, 0, 0, 0, 102, 103,
223 23, 0, 0, 0, 0, 0, 0, 0, 4, 0,
224 2, 0, 8, 5, 6, 0, 0, 12, 0, 0,
225 0, 0, 0, 0, 0, 25, 32, 32, 32, 0,
226 0, 107, 0, 104, 0, 0, 75, 0, 101, 82,
227 83, 0, 84, 85, 32, 32, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
229 0, 0, 3, 0, 73, 0, 30, 0, 0, 0,
230 0, 0, 35, 0, 67, 0, 33, 0, 0, 0,
231 0, 0, 33, 33, 0, 0, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
233 0, 16, 14, 0, 74, 100, 87, 0, 0, 0,
234 0, 0, 88, 89, 105, 0, 0, 41, 37, 0,
235 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 0, 0, 0, 57, 0,
237 0, 0, 0, 0, 0, 0, 33, 18, 0, 43,
238 55, 0, 0, 29, 0, 0, 0, 32, 0, 0,
239 0, 0, 33, 0, 0, 46, 45, 34, 33, 0,
240 48, 0, 26, 28, 0, 50,
241};
242const short yydgoto[] =
243 { 1,
244 36, 89, 96, 28, 29, 30, 31, 91, 129, 158,
245 167, 54, 55, 132, 46, 32, 168, 39, 130, 80,
246 140, 176, 81, 180,
247};
248const short yysindex[] =
249 { 0,
250 -77, -188, 196, 88, 0, -257, 0, 0, -260, 0,
251 0, -236, 223, -225, -109, -107, -103, -102, 0, 0,
252 0, 115, 196, 196, -227, -227, -291, -17, 0, -237,
253 0, -202, 0, 0, 0, -166, 479, 0, -89, 196,
254 196, -87, 196, 142, -17, 0, 0, 0, 0, 196,
255 196, 0, -17, 0, -195, 815, 0, -170, 0, 0,
256 0, 196, 0, 0, 0, 0, 196, 196, 196, 196,
257 196, 196, 196, 196, 196, 196, 196, 196, -85, -157,
258 -81, 88, 0, 196, 0, 88, 0, 88, -72, -17,
259 -73, 607, 0, 496, 0, 196, 0, 196, 514, 531,
260 115, 291, 0, 0, 291, 291, 291, 291, 291, 291,
261 126, 126, -71, -71, -71, -71, -33, -37, -32, 0,
262 291, 0, 0, 250, 0, 0, 0, -17, -21, 196,
263 787, -20, 0, 0, 0, 196, 196, 0, 0, -7,
264 -6, -216, -17, 196, 6, 196, 196, 196, 196, 196,
265 196, 88, 802, 815, -4, 7, 169, 20, 0, 88,
266 291, 291, 291, 291, 291, 291, 0, 0, 21, 0,
267 0, 196, 5, 0, 41, 88, 51, 0, 49, -207,
268 -45, 88, 0, 54, 65, 0, 0, 0, 0, 88,
269 0, 74, 0, 0, 76, 0,};
270const short yyrindex[] =
271 { 0,
272 -175, 0, 0, -43, 0, -48, 0, 0, 0, 0,
273 0, 0, 2, 0, 0, 0, 0, 1, 0, 0,
274 0, 0, 0, 0, 0, 0, 461, 221, 0, 81,
275 0, 0, 0, 0, 0, 275, 0, 0, 0, 82,
276 0, 0, 0, 0, 384, 0, 0, 0, 0, 0,
277 0, 0, 286, 0, 445, -229, 0, 320, 0, 0,
278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279 0, 0, 0, 0, 0, 0, 0, 0, -152, 0,
280 84, -133, 0, 0, 0, -34, 0, 72, 86, -86,
281 0, 0, 0, 0, 0, 90, 0, 0, 0, 0,
282 0, -126, 0, 0, 194, 663, 694, 704, 735, 745,
283 576, 590, 339, 383, 400, 444, 0, 89, 0, 0,
284 652, 0, 0, 0, 0, 0, 0, -197, 0, 0,
285 -117, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286 -74, -180, -35, 96, 0, 0, 0, 0, 0, 0,
287 0, 577, 786, 776, 0, 0, 0, 0, 0, 577,
288 -241, -160, -156, -53, 112, 119, 0, 0, 48, 0,
289 0, 98, 77, 0, 0, -43, 0, 0, -169, 0,
290 0, 577, 0, 0, 0, 0, 0, 0, 0, 577,
291 0, -104, 0, 0, 0, 0,};
292const short yygindex[] =
293 { 0,
294 -1, 0, -39, -2, 0, 0, 0, 0, 203, 0,
295 -146, 277, 0, -112, 0, 0, 4, 205, -88, 0,
296 0, 0, 0, 0,
297};
298#define YYTABLESIZE1116 1116
299const short yytable[] =
300 { 27,
301 37, 40, 27, 62, 33, 41, 42, 38, 97, 98,
302 45, 63, 64, 173, 136, 137, 58, 145, 58, 53,
303 56, 57, 43, 60, 61, 103, 104, 90, 90, 79,
304 90, 159, 90, 47, 90, 189, 90, 90, 92, 58,
305 94, 37, 40, 194, 93, 93, 157, 99, 100, 185,
306 186, 59, 19, 20, 90, 82, 90, 90, 187, 102,
307 69, 101, 69, 83, 105, 106, 107, 108, 109, 110,
308 111, 112, 113, 114, 115, 116, 99, 34, 174, 99,
309 27, 121, 7, 35, 27, 120, 27, 47, 47, 122,
310 7, 123, 41, 128, 190, 131, 47, 61, 53, 61,
311 193, 63, 118, 63, 40, 99, 99, 40, 99, 99,
312 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
313 99, 143, 99, 99, 10, 96, 96, 131, 84, 98,
314 98, 20, 10, 153, 154, 20, 63, 64, 183, 20,
315 64, 131, 64, 161, 162, 163, 164, 165, 166, 48,
316 27, 49, 49, 49, 92, 50, 51, 20, 27, 86,
317 86, 49, 86, 86, 86, 86, 86, 86, 86, 128,
318 53, 93, 87, 53, 27, 119, 88, 117, 2, 38,
319 27, 3, 42, 4, 124, 42, 125, 5, 27, 6,
320 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
321 17, 18, 19, 20, 59, 21, 59, 22, 99, 99,
322 23, 99, 86, 99, 11, 99, 188, 99, 11, 24,
323 88, 54, 11, 15, 54, 25, 26, 15, 139, 78,
324 138, 15, 94, 94, 141, 99, 144, 99, 99, 152,
325 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
326 99, 99, 99, 155, 99, 99, 156, 101, 101, 65,
327 101, 169, 101, 65, 101, 160, 101, 65, 65, 66,
328 170, 67, 68, 69, 70, 71, 72, 172, 73, 74,
329 75, 76, 77, 78, 101, 65, 101, 101, 178, 101,
330 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
331 101, 101, 175, 101, 101, 44, 44, 179, 44, 44,
332 182, 184, 44, 44, 44, 44, 44, 191, 44, 44,
333 44, 44, 44, 44, 44, 44, 44, 44, 44, 13,
334 44, 192, 44, 13, 27, 44, 195, 13, 27, 196,
335 38, 51, 27, 39, 44, 52, 3, 68, 4, 36,
336 44, 44, 5, 56, 6, 7, 8, 68, 10, 11,
337 12, 13, 14, 15, 16, 17, 18, 19, 20, 60,
338 21, 60, 22, 3, 177, 23, 62, 135, 62, 5,
339 181, 6, 7, 52, 24, 0, 0, 12, 0, 0,
340 25, 26, 17, 18, 19, 20, 0, 95, 95, 0,
341 3, 95, 23, 0, 97, 97, 5, 0, 6, 7,
342 0, 24, 0, 0, 12, 0, 0, 25, 26, 17,
343 18, 19, 20, 75, 76, 77, 78, 3, 0, 23,
344 0, 0, 171, 5, 0, 6, 7, 0, 24, 0,
345 0, 12, 0, 0, 25, 26, 17, 18, 19, 20,
346 93, 93, 0, 93, 3, 93, 23, 93, 0, 93,
347 5, 0, 6, 7, 0, 24, 0, 0, 12, 0,
348 0, 25, 26, 17, 18, 19, 20, 93, 19, 93,
349 93, 44, 19, 23, 0, 0, 19, 5, 0, 6,
350 7, 0, 24, 0, 0, 12, 0, 0, 25, 26,
351 17, 18, 19, 20, 19, 0, 0, 0, 3, 0,
352 23, 0, 0, 0, 5, 0, 142, 7, 0, 24,
353 0, 0, 12, 0, 0, 25, 26, 17, 18, 19,
354 20, 70, 70, 0, 70, 0, 70, 23, 70, 0,
355 70, 0, 106, 106, 0, 0, 24, 106, 0, 0,
356 0, 106, 25, 26, 0, 0, 0, 0, 70, 0,
357 70, 70, 0, 70, 70, 70, 70, 70, 70, 106,
358 70, 70, 70, 70, 70, 70, 99, 99, 0, 99,
359 0, 99, 0, 99, 0, 99, 73, 74, 75, 76,
360 77, 78, 0, 0, 0, 78, 78, 0, 78, 0,
361 78, 0, 78, 99, 78, 99, 99, 0, 99, 99,
362 99, 99, 99, 99, 0, 99, 99, 99, 99, 99,
363 99, 0, 78, 0, 78, 78, 0, 78, 78, 78,
364 78, 78, 78, 0, 78, 78, 78, 78, 78, 79,
365 79, 66, 79, 0, 79, 66, 79, 0, 79, 66,
366 0, 0, 0, 0, 0, 0, 80, 80, 0, 80,
367 0, 80, 0, 80, 0, 80, 79, 66, 79, 79,
368 0, 79, 79, 79, 79, 79, 79, 0, 79, 79,
369 79, 79, 79, 80, 0, 80, 80, 0, 80, 80,
370 80, 80, 80, 80, 0, 80, 80, 80, 80, 80,
371 81, 81, 31, 81, 0, 81, 31, 81, 0, 81,
372 31, 0, 0, 0, 0, 0, 0, 0, 70, 0,
373 0, 0, 70, 0, 0, 0, 70, 81, 31, 81,
374 81, 0, 81, 81, 81, 81, 81, 81, 85, 81,
375 81, 81, 81, 81, 70, 0, 70, 70, 0, 70,
376 70, 70, 70, 70, 70, 127, 70, 70, 70, 70,
377 70, 70, 0, 0, 65, 66, 0, 67, 68, 69,
378 70, 71, 72, 133, 73, 74, 75, 76, 77, 78,
379 0, 65, 66, 0, 67, 68, 69, 70, 71, 72,
380 134, 73, 74, 75, 76, 77, 78, 0, 0, 65,
381 66, 0, 67, 68, 69, 70, 71, 72, 0, 73,
382 74, 75, 76, 77, 78, 0, 65, 66, 0, 67,
383 68, 69, 70, 71, 72, 0, 73, 74, 75, 76,
384 77, 78, 76, 76, 17, 76, 0, 76, 17, 76,
385 0, 76, 17, 0, 0, 0, 77, 77, 0, 77,
386 0, 77, 0, 77, 0, 77, 0, 0, 0, 76,
387 17, 76, 76, 0, 76, 76, 76, 76, 76, 76,
388 126, 76, 76, 77, 0, 77, 77, 0, 77, 77,
389 77, 77, 77, 77, 0, 77, 77, 0, 0, 0,
390 0, 0, 65, 66, 0, 67, 68, 69, 70, 71,
391 72, 0, 73, 74, 75, 76, 77, 78, 86, 86,
392 0, 86, 0, 86, 0, 86, 0, 86, 0, 96,
393 96, 0, 96, 0, 96, 0, 96, 0, 96, 0,
394 0, 0, 0, 0, 0, 86, 0, 86, 86, 0,
395 86, 86, 86, 86, 86, 86, 96, 0, 96, 96,
396 98, 98, 0, 98, 0, 98, 0, 98, 0, 98,
397 94, 94, 0, 94, 0, 94, 0, 94, 0, 94,
398 0, 0, 0, 0, 0, 0, 0, 98, 0, 98,
399 98, 0, 0, 0, 0, 0, 0, 94, 0, 94,
400 94, 95, 95, 0, 95, 0, 95, 0, 95, 0,
401 95, 97, 97, 0, 97, 0, 97, 0, 97, 0,
402 97, 0, 0, 0, 0, 0, 0, 0, 95, 0,
403 95, 95, 0, 0, 0, 0, 0, 0, 97, 0,
404 97, 97, 91, 91, 0, 91, 0, 91, 0, 91,
405 0, 91, 92, 92, 0, 92, 0, 92, 0, 92,
406 0, 92, 0, 0, 0, 0, 0, 0, 0, 91,
407 0, 91, 91, 0, 0, 0, 0, 0, 0, 92,
408 0, 92, 65, 66, 0, 146, 147, 148, 149, 150,
409 151, 0, 73, 74, 75, 76, 77, 78, 66, 0,
410 67, 68, 69, 70, 71, 72, 0, 73, 74, 75,
411 76, 77, 78, 67, 68, 69, 70, 71, 72, 0,
412 73, 74, 75, 76, 77, 78,
413};
414const short yycheck[] =
415 { 1,
416 3, 259, 4, 295, 1, 263, 267, 4, 48, 49,
417 13, 303, 304, 160, 103, 104, 258, 130, 260, 22,
418 23, 24, 259, 25, 26, 65, 66, 257, 258, 267,
419 260, 144, 262, 259, 264, 182, 266, 40, 41, 267,
420 43, 44, 259, 190, 286, 287, 263, 50, 51, 257,
421 258, 279, 280, 281, 284, 258, 286, 287, 266, 62,
422 258, 257, 260, 266, 67, 68, 69, 70, 71, 72,
423 73, 74, 75, 76, 77, 78, 257, 266, 167, 260,
424 82, 84, 258, 272, 86, 82, 88, 257, 258, 86,
425 266, 88, 263, 96, 183, 98, 266, 258, 101, 260,
426 189, 258, 260, 260, 257, 286, 287, 260, 289, 290,
427 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
428 301, 124, 303, 304, 258, 286, 287, 130, 295, 286,
429 287, 258, 266, 136, 137, 262, 303, 304, 178, 266,
430 258, 144, 260, 146, 147, 148, 149, 150, 151, 259,
431 152, 259, 257, 258, 157, 259, 259, 284, 160, 286,
432 287, 266, 289, 290, 291, 292, 293, 294, 258, 172,
433 257, 259, 262, 260, 176, 257, 266, 263, 256, 176,
434 182, 259, 257, 261, 257, 260, 260, 265, 190, 267,
435 268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
436 278, 279, 280, 281, 258, 283, 260, 285, 257, 258,
437 288, 260, 258, 262, 258, 264, 262, 266, 262, 297,
438 266, 257, 266, 258, 260, 303, 304, 262, 266, 301,
439 264, 266, 286, 287, 267, 284, 258, 286, 287, 260,
440 289, 290, 291, 292, 293, 294, 295, 296, 297, 298,
441 299, 300, 301, 261, 303, 304, 263, 257, 258, 258,
442 260, 266, 262, 262, 264, 260, 266, 266, 286, 287,
443 264, 289, 290, 291, 292, 293, 294, 258, 296, 297,
444 298, 299, 300, 301, 284, 284, 286, 287, 284, 289,
445 290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
446 300, 301, 282, 303, 304, 258, 259, 267, 261, 262,
447 260, 263, 265, 266, 267, 268, 269, 264, 271, 272,
448 273, 274, 275, 276, 277, 278, 279, 280, 281, 258,
449 283, 267, 285, 262, 258, 288, 263, 266, 262, 264,
450 260, 260, 266, 260, 297, 260, 259, 258, 261, 261,
451 303, 304, 265, 258, 267, 268, 269, 260, 271, 272,
452 273, 274, 275, 276, 277, 278, 279, 280, 281, 258,
453 283, 260, 285, 259, 172, 288, 258, 101, 260, 265,
454 176, 267, 268, 269, 297, -1, -1, 273, -1, -1,
455 303, 304, 278, 279, 280, 281, -1, 286, 287, -1,
456 259, 260, 288, -1, 286, 287, 265, -1, 267, 268,
457 -1, 297, -1, -1, 273, -1, -1, 303, 304, 278,
458 279, 280, 281, 298, 299, 300, 301, 259, -1, 288,
459 -1, -1, 264, 265, -1, 267, 268, -1, 297, -1,
460 -1, 273, -1, -1, 303, 304, 278, 279, 280, 281,
461 257, 258, -1, 260, 259, 262, 288, 264, -1, 266,
462 265, -1, 267, 268, -1, 297, -1, -1, 273, -1,
463 -1, 303, 304, 278, 279, 280, 281, 284, 258, 286,
464 287, 259, 262, 288, -1, -1, 266, 265, -1, 267,
465 268, -1, 297, -1, -1, 273, -1, -1, 303, 304,
466 278, 279, 280, 281, 284, -1, -1, -1, 259, -1,
467 288, -1, -1, -1, 265, -1, 267, 268, -1, 297,
468 -1, -1, 273, -1, -1, 303, 304, 278, 279, 280,
469 281, 257, 258, -1, 260, -1, 262, 288, 264, -1,
470 266, -1, 257, 258, -1, -1, 297, 262, -1, -1,
471 -1, 266, 303, 304, -1, -1, -1, -1, 284, -1,
472 286, 287, -1, 289, 290, 291, 292, 293, 294, 284,
473 296, 297, 298, 299, 300, 301, 257, 258, -1, 260,
474 -1, 262, -1, 264, -1, 266, 296, 297, 298, 299,
475 300, 301, -1, -1, -1, 257, 258, -1, 260, -1,
476 262, -1, 264, 284, 266, 286, 287, -1, 289, 290,
477 291, 292, 293, 294, -1, 296, 297, 298, 299, 300,
478 301, -1, 284, -1, 286, 287, -1, 289, 290, 291,
479 292, 293, 294, -1, 296, 297, 298, 299, 300, 257,
480 258, 258, 260, -1, 262, 262, 264, -1, 266, 266,
481 -1, -1, -1, -1, -1, -1, 257, 258, -1, 260,
482 -1, 262, -1, 264, -1, 266, 284, 284, 286, 287,
483 -1, 289, 290, 291, 292, 293, 294, -1, 296, 297,
484 298, 299, 300, 284, -1, 286, 287, -1, 289, 290,
485 291, 292, 293, 294, -1, 296, 297, 298, 299, 300,
486 257, 258, 258, 260, -1, 262, 262, 264, -1, 266,
487 266, -1, -1, -1, -1, -1, -1, -1, 258, -1,
488 -1, -1, 262, -1, -1, -1, 266, 284, 284, 286,
489 287, -1, 289, 290, 291, 292, 293, 294, 260, 296,
490 297, 298, 299, 300, 284, -1, 286, 287, -1, 289,
491 290, 291, 292, 293, 294, 260, 296, 297, 298, 299,
492 300, 301, -1, -1, 286, 287, -1, 289, 290, 291,
493 292, 293, 294, 260, 296, 297, 298, 299, 300, 301,
494 -1, 286, 287, -1, 289, 290, 291, 292, 293, 294,
495 260, 296, 297, 298, 299, 300, 301, -1, -1, 286,
496 287, -1, 289, 290, 291, 292, 293, 294, -1, 296,
497 297, 298, 299, 300, 301, -1, 286, 287, -1, 289,
498 290, 291, 292, 293, 294, -1, 296, 297, 298, 299,
499 300, 301, 257, 258, 258, 260, -1, 262, 262, 264,
500 -1, 266, 266, -1, -1, -1, 257, 258, -1, 260,
501 -1, 262, -1, 264, -1, 266, -1, -1, -1, 284,
502 284, 286, 287, -1, 289, 290, 291, 292, 293, 294,
503 264, 296, 297, 284, -1, 286, 287, -1, 289, 290,
504 291, 292, 293, 294, -1, 296, 297, -1, -1, -1,
505 -1, -1, 286, 287, -1, 289, 290, 291, 292, 293,
506 294, -1, 296, 297, 298, 299, 300, 301, 257, 258,
507 -1, 260, -1, 262, -1, 264, -1, 266, -1, 257,
508 258, -1, 260, -1, 262, -1, 264, -1, 266, -1,
509 -1, -1, -1, -1, -1, 284, -1, 286, 287, -1,
510 289, 290, 291, 292, 293, 294, 284, -1, 286, 287,
511 257, 258, -1, 260, -1, 262, -1, 264, -1, 266,
512 257, 258, -1, 260, -1, 262, -1, 264, -1, 266,
513 -1, -1, -1, -1, -1, -1, -1, 284, -1, 286,
514 287, -1, -1, -1, -1, -1, -1, 284, -1, 286,
515 287, 257, 258, -1, 260, -1, 262, -1, 264, -1,
516 266, 257, 258, -1, 260, -1, 262, -1, 264, -1,
517 266, -1, -1, -1, -1, -1, -1, -1, 284, -1,
518 286, 287, -1, -1, -1, -1, -1, -1, 284, -1,
519 286, 287, 257, 258, -1, 260, -1, 262, -1, 264,
520 -1, 266, 257, 258, -1, 260, -1, 262, -1, 264,
521 -1, 266, -1, -1, -1, -1, -1, -1, -1, 284,
522 -1, 286, 287, -1, -1, -1, -1, -1, -1, 284,
523 -1, 286, 286, 287, -1, 289, 290, 291, 292, 293,
524 294, -1, 296, 297, 298, 299, 300, 301, 287, -1,
525 289, 290, 291, 292, 293, 294, -1, 296, 297, 298,
526 299, 300, 301, 289, 290, 291, 292, 293, 294, -1,
527 296, 297, 298, 299, 300, 301,
528};
529#define YYFINAL1 1
530#ifndef YYDEBUG0
531#define YYDEBUG0 0
532#endif
533#define YYMAXTOKEN304 304
534#if YYDEBUG0
535const char * const yyname[] =
536 {
537"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,
5380,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5390,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5400,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5420,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5430,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"COMMA","SEMICOLON","LPAR","RPAR",
544"LBRACE","RBRACE","LBRACKET","RBRACKET","DOT","NEWLINE","LETTER","NUMBER",
545"STRING","DEFINE","BREAK","QUIT","LENGTH","RETURN","FOR","IF","WHILE","SQRT",
546"SCALE","IBASE","OBASE","AUTO","CONTINUE","ELSE","PRINT","BOOL_OR","BOOL_AND",
547"BOOL_NOT","EQUALS","LESS_EQ","GREATER_EQ","UNEQUALS","LESS","GREATER",
548"ASSIGN_OP","PLUS","MINUS","MULTIPLY","DIVIDE","REMAINDER","EXPONENT","UMINUS",
549"INCR","DECR",
550};
551const char * const yyrule[] =
552 {"$accept : program",
553"program :",
554"program : program input_item",
555"input_item : semicolon_list NEWLINE",
556"input_item : function",
557"input_item : error NEWLINE",
558"input_item : error QUIT",
559"semicolon_list :",
560"semicolon_list : statement",
561"semicolon_list : semicolon_list SEMICOLON statement",
562"semicolon_list : semicolon_list SEMICOLON",
563"statement_list :",
564"statement_list : statement",
565"statement_list : statement_list NEWLINE",
566"statement_list : statement_list NEWLINE statement",
567"statement_list : statement_list SEMICOLON",
568"statement_list : statement_list SEMICOLON statement",
569"opt_statement :",
570"opt_statement : statement",
571"statement : expression",
572"statement : named_expression ASSIGN_OP expression",
573"statement : STRING",
574"statement : BREAK",
575"statement : CONTINUE",
576"statement : QUIT",
577"statement : RETURN return_expression",
578"statement : FOR LPAR alloc_macro opt_expression SEMICOLON opt_relational_expression SEMICOLON opt_expression RPAR opt_statement pop_nesting",
579"statement : IF LPAR alloc_macro pop_nesting relational_expression RPAR opt_statement",
580"statement : IF LPAR alloc_macro pop_nesting relational_expression RPAR opt_statement ELSE alloc_macro pop_nesting opt_statement",
581"statement : WHILE LPAR alloc_macro relational_expression RPAR opt_statement pop_nesting",
582"statement : LBRACE statement_list RBRACE",
583"statement : PRINT print_expression_list",
584"alloc_macro :",
585"pop_nesting :",
586"function : function_header opt_parameter_list RPAR opt_newline LBRACE NEWLINE opt_auto_define_list statement_list RBRACE",
587"function_header : DEFINE LETTER LPAR",
588"opt_newline :",
589"opt_newline : NEWLINE",
590"opt_parameter_list :",
591"opt_parameter_list : parameter_list",
592"parameter_list : LETTER",
593"parameter_list : LETTER LBRACKET RBRACKET",
594"parameter_list : parameter_list COMMA LETTER",
595"parameter_list : parameter_list COMMA LETTER LBRACKET RBRACKET",
596"opt_auto_define_list :",
597"opt_auto_define_list : AUTO define_list NEWLINE",
598"opt_auto_define_list : AUTO define_list SEMICOLON",
599"define_list : LETTER",
600"define_list : LETTER LBRACKET RBRACKET",
601"define_list : define_list COMMA LETTER",
602"define_list : define_list COMMA LETTER LBRACKET RBRACKET",
603"opt_argument_list :",
604"opt_argument_list : argument_list",
605"argument_list : expression",
606"argument_list : argument_list COMMA expression",
607"argument_list : argument_list COMMA LETTER LBRACKET RBRACKET",
608"opt_relational_expression :",
609"opt_relational_expression : relational_expression",
610"relational_expression : expression EQUALS expression",
611"relational_expression : expression UNEQUALS expression",
612"relational_expression : expression LESS expression",
613"relational_expression : expression LESS_EQ expression",
614"relational_expression : expression GREATER expression",
615"relational_expression : expression GREATER_EQ expression",
616"relational_expression : expression",
617"return_expression :",
618"return_expression : expression",
619"return_expression : LPAR RPAR",
620"opt_expression :",
621"opt_expression : expression",
622"expression : named_expression",
623"expression : DOT",
624"expression : NUMBER",
625"expression : LPAR expression RPAR",
626"expression : LETTER LPAR opt_argument_list RPAR",
627"expression : MINUS expression",
628"expression : expression PLUS expression",
629"expression : expression MINUS expression",
630"expression : expression MULTIPLY expression",
631"expression : expression DIVIDE expression",
632"expression : expression REMAINDER expression",
633"expression : expression EXPONENT expression",
634"expression : INCR named_expression",
635"expression : DECR named_expression",
636"expression : named_expression INCR",
637"expression : named_expression DECR",
638"expression : named_expression ASSIGN_OP expression",
639"expression : LENGTH LPAR expression RPAR",
640"expression : SQRT LPAR expression RPAR",
641"expression : SCALE LPAR expression RPAR",
642"expression : BOOL_NOT expression",
643"expression : expression BOOL_AND alloc_macro pop_nesting expression",
644"expression : expression BOOL_OR alloc_macro pop_nesting expression",
645"expression : expression EQUALS expression",
646"expression : expression UNEQUALS expression",
647"expression : expression LESS expression",
648"expression : expression LESS_EQ expression",
649"expression : expression GREATER expression",
650"expression : expression GREATER_EQ expression",
651"named_expression : LETTER",
652"named_expression : LETTER LBRACKET expression RBRACKET",
653"named_expression : SCALE",
654"named_expression : IBASE",
655"named_expression : OBASE",
656"print_expression_list : print_expression",
657"print_expression_list : print_expression_list COMMA print_expression",
658"print_expression : expression",
659"print_expression : STRING",
660};
661#endif
662#ifdef YYSTACKSIZE10000
663#undef YYMAXDEPTH10000
664#define YYMAXDEPTH10000 YYSTACKSIZE10000
665#else
666#ifdef YYMAXDEPTH10000
667#define YYSTACKSIZE10000 YYMAXDEPTH10000
668#else
669#define YYSTACKSIZE10000 10000
670#define YYMAXDEPTH10000 10000
671#endif
672#endif
673#define YYINITSTACKSIZE200 200
674/* LINTUSED */
675int yydebug;
676int yynerrs;
677int yyerrflag;
678int yychar;
679short *yyssp;
680YYSTYPE *yyvsp;
681YYSTYPE yyval;
682YYSTYPE yylval;
683short *yyss;
684short *yysslim;
685YYSTYPE *yyvs;
686unsigned int yystacksize;
687int yyparse(void);
688#line 743 "/usr/src/usr.bin/bc/bc.y"
689
690
691static void
692grow(void)
693{
694 struct tree *p;
695 size_t newsize;
696
697 if (current == instr_sz) {
698 newsize = instr_sz * 2 + 1;
699 p = reallocarray(instructions, newsize, sizeof(*p));
700 if (p == NULL((void *)0)) {
701 free(instructions);
702 err(1, NULL((void *)0));
703 }
704 instructions = p;
705 instr_sz = newsize;
706 }
707}
708
709static ssize_t
710cs(const char *str)
711{
712 grow();
713 instructions[current].index = CONST_STRING((ssize_t) -2);
714 instructions[current].u.cstr = str;
715 return current++;
716}
717
718static ssize_t
719as(const char *str)
720{
721 grow();
722 instructions[current].index = ALLOC_STRING((ssize_t) -3);
723 instructions[current].u.astr = strdup(str);
724 if (instructions[current].u.astr == NULL((void *)0))
725 err(1, NULL((void *)0));
726 return current++;
727}
728
729static ssize_t
730node(ssize_t arg, ...)
731{
732 va_list ap;
733 ssize_t ret;
734
735 va_start(ap, arg)__builtin_va_start(ap, arg);
736
737 ret = current;
738 grow();
739 instructions[current++].index = arg;
740
741 do {
742 arg = va_arg(ap, ssize_t)__builtin_va_arg(ap, ssize_t);
743 grow();
744 instructions[current++].index = arg;
745 } while (arg != END_NODE((ssize_t) -1));
746
747 va_end(ap)__builtin_va_end(ap);
748 return ret;
749}
750
751static void
752emit(ssize_t i, int level)
753{
754 if (level > 1000)
755 errx(1, "internal error: tree level > 1000");
756 if (instructions[i].index >= 0) {
757 while (instructions[i].index != END_NODE((ssize_t) -1) &&
758 instructions[i].index != i) {
759 emit(instructions[i].index, level + 1);
760 i++;
761 }
762 } else if (instructions[i].index != END_NODE((ssize_t) -1))
763 fputs(instructions[i].u.cstr, stdout(&__sF[1]));
764}
765
766static void
767emit_macro(int node, ssize_t code)
768{
769 putchar('[')(!__isthreaded ? __sputc('[', (&__sF[1])) : (putc)('[', (
&__sF[1])))
;
770 emit(code, 0);
771 printf("]s%s\n", instructions[node].u.cstr);
772 nesting--;
773}
774
775static void
776free_tree(void)
777{
778 ssize_t i;
779
780 for (i = 0; i < current; i++)
781 if (instructions[i].index == ALLOC_STRING((ssize_t) -3))
782 free(instructions[i].u.astr);
783 current = 0;
784}
785
786static ssize_t
787numnode(int num)
788{
789 const char *p;
790
791 if (num < 10)
792 p = str_table['0' + num];
793 else if (num < 16)
794 p = str_table['A' - 10 + num];
795 else
796 errx(1, "internal error: break num > 15");
797 return node(cs(" "), cs(p), END_NODE((ssize_t) -1));
798}
799
800
801static ssize_t
802lookup(char * str, size_t len, char type)
803{
804 ENTRY entry, *found;
805 u_short num;
806 u_char *p;
807
808 /* The scanner allocated an extra byte already */
809 if (str[len-1] != type) {
810 str[len] = type;
811 str[len+1] = '\0';
812 }
813 entry.key = str;
814 found = hsearch(entry, FIND);
815 if (found == NULL((void *)0)) {
816 if (var_count == MAX_VARIABLES((256-4) * (256-4)))
817 errx(1, "too many variables");
818 p = malloc(4);
819 if (p == NULL((void *)0))
820 err(1, NULL((void *)0));
821 num = var_count++;
822 p[0] = 255;
823 p[1] = ENCODE(num / VAR_BASE + 1)((num / (256-4) + 1) < '[' ? (num / (256-4) + 1) : (num / (
256-4) + 1) + 3);
;
824 p[2] = ENCODE(num % VAR_BASE + 1)((num % (256-4) + 1) < '[' ? (num % (256-4) + 1) : (num % (
256-4) + 1) + 3);
;
825 p[3] = '\0';
826
827 entry.data = (char *)p;
828 entry.key = strdup(str);
829 if (entry.key == NULL((void *)0))
830 err(1, NULL((void *)0));
831 found = hsearch(entry, ENTER);
832 if (found == NULL((void *)0))
833 err(1, NULL((void *)0));
834 }
835 return cs(found->data);
836}
837
838static ssize_t
839letter_node(char *str)
840{
841 size_t len;
842
843 len = strlen(str);
844 if (len == 1 && str[0] != '_')
845 return cs(str_table[(int)str[0]]);
846 else
847 return lookup(str, len, 'L');
848}
849
850static ssize_t
851array_node(char *str)
852{
853 size_t len;
854
855 len = strlen(str);
856 if (len == 1 && str[0] != '_')
857 return cs(str_table[(int)str[0] - 'a' + ARRAY_CHAR0xa1]);
858 else
859 return lookup(str, len, 'A');
860}
861
862static ssize_t
863function_node(char *str)
864{
865 size_t len;
866
867 len = strlen(str);
868 if (len == 1 && str[0] != '_')
869 return cs(str_table[(int)str[0] - 'a' + FUNC_CHAR0x01]);
870 else
871 return lookup(str, len, 'F');
872}
873
874static void
875add_par(ssize_t n)
876{
877 prologue = node(cs("S"), n, prologue, END_NODE((ssize_t) -1));
878 epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE((ssize_t) -1));
879}
880
881static void
882add_local(ssize_t n)
883{
884 prologue = node(cs("0S"), n, prologue, END_NODE((ssize_t) -1));
885 epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE((ssize_t) -1));
886}
887
888void
889yyerror(char *s)
890{
891 char *str, *p;
892 int n;
893
894 if (yyin != NULL((void *)0) && feof(yyin)(!__isthreaded ? (((yyin)->_flags & 0x0020) != 0) : (feof
)(yyin))
)
895 n = asprintf(&str, "%s: %s:%d: %s: unexpected EOF",
896 __progname, filename, lineno, s);
897 else if (yytext[0] == '\n')
898 n = asprintf(&str,
899 "%s: %s:%d: %s: newline unexpected",
900 __progname, filename, lineno, s);
901 else if (isspace((unsigned char)yytext[0]) ||
902 !isprint((unsigned char)yytext[0]))
903 n = asprintf(&str,
904 "%s: %s:%d: %s: ascii char 0x%02x unexpected",
905 __progname, filename, lineno, s, yytext[0] & 0xff);
906 else
907 n = asprintf(&str, "%s: %s:%d: %s: %s unexpected",
908 __progname, filename, lineno, s, yytext);
909 if (n == -1)
910 err(1, NULL((void *)0));
911
912 fputs("c[", stdout(&__sF[1]));
913 for (p = str; *p != '\0'; p++) {
914 if (*p == '[' || *p == ']' || *p =='\\')
915 putchar('\\')(!__isthreaded ? __sputc('\\', (&__sF[1])) : (putc)('\\',
(&__sF[1])))
;
916 putchar(*p)(!__isthreaded ? __sputc(*p, (&__sF[1])) : (putc)(*p, (&
__sF[1])))
;
917 }
918 fputs("]ec\n", stdout(&__sF[1]));
919 free(str);
920}
921
922void
923fatal(const char *s)
924{
925 errx(1, "%s:%d: %s", filename, lineno, s);
926}
927
928static void
929warning(const char *s)
930{
931 warnx("%s:%d: %s", filename, lineno, s);
932}
933
934static void
935init(void)
936{
937 int i;
938
939 for (i = 0; i < UCHAR_MAX(127*2 +1); i++) {
940 str_table[i][0] = i;
941 str_table[i][1] = '\0';
942 }
943 if (hcreate(1 << 16) == 0)
944 err(1, NULL((void *)0));
945}
946
947
948static __dead__attribute__((__noreturn__)) void
949usage(void)
950{
951 fprintf(stderr(&__sF[2]), "usage: %s [-cl] [-e expression] [file ...]\n",
952 __progname);
953 exit(1);
954}
955
956static char *
957escape(const char *str)
958{
959 char *ret, *p;
960
961 ret = malloc(strlen(str) + 1);
962 if (ret == NULL((void *)0))
963 err(1, NULL((void *)0));
964
965 p = ret;
966 while (*str != '\0') {
967 /*
968 * We get _escaped_ strings here. Single backslashes are
969 * already converted to double backslashes
970 */
971 if (*str == '\\') {
972 if (*++str == '\\') {
973 switch (*++str) {
974 case 'a':
975 *p++ = '\a';
976 break;
977 case 'b':
978 *p++ = '\b';
979 break;
980 case 'f':
981 *p++ = '\f';
982 break;
983 case 'n':
984 *p++ = '\n';
985 break;
986 case 'q':
987 *p++ = '"';
988 break;
989 case 'r':
990 *p++ = '\r';
991 break;
992 case 't':
993 *p++ = '\t';
994 break;
995 case '\\':
996 *p++ = '\\';
997 break;
998 }
999 if (*str == '\0')
1000 break;
1001 str++;
1002 } else {
1003 *p++ = '\\';
1004 *p++ = *str++;
1005 }
1006 } else
1007 *p++ = *str++;
1008 }
1009 *p = '\0';
1010 return ret;
1011}
1012
1013/* ARGSUSED */
1014static void
1015sigchld(int signo)
1016{
1017 pid_t pid;
1018 int status, save_errno = errno(*__errno());
1019
1020 for (;;) {
1021 pid = waitpid(dc, &status, WCONTINUED8 | WNOHANG1);
1022 if (pid == -1) {
1023 if (errno(*__errno()) == EINTR4)
1024 continue;
1025 _exit(0);
1026 } else if (pid == 0)
1027 break;
1028 if (WIFEXITED(status)(((status) & 0177) == 0) || WIFSIGNALED(status)(((status) & 0177) != 0177 && ((status) & 0177
) != 0)
)
1029 _exit(0);
1030 else
1031 break;
1032 }
1033 errno(*__errno()) = save_errno;
1034}
1035
1036static const char *
1037dummy_prompt(void)
1038{
1039
1040 return ("");
1041}
1042
1043int
1044main(int argc, char *argv[])
1045{
1046 int i, ch;
1047 int p[2];
1048 char *q;
1049
1050 if (pledge("stdio rpath proc tty", NULL((void *)0)) == -1)
1051 err(1, "pledge");
1052
1053 init();
1054 setvbuf(stdout(&__sF[1]), NULL((void *)0), _IOLBF1, 0);
1055
1056 sargv = reallocarray(NULL((void *)0), argc, sizeof(char *));
1057 if (sargv == NULL((void *)0))
1058 err(1, NULL((void *)0));
1059
1060 if ((cmdexpr = strdup("")) == NULL((void *)0))
1061 err(1, NULL((void *)0));
1062 /* The d debug option is 4.4 BSD bc(1) compatible */
1063 while ((ch = getopt(argc, argv, "cde:l")) != -1) {
1064 switch (ch) {
1065 case 'c':
1066 case 'd':
1067 do_fork = false0;
1068 break;
1069 case 'e':
1070 q = cmdexpr;
1071 if (asprintf(&cmdexpr, "%s%s\n", cmdexpr, optarg) == -1)
1072 err(1, NULL((void *)0));
1073 free(q);
1074 break;
1075 case 'l':
1076 sargv[sargc++] = _PATH_LIBB"/usr/share/misc/bc.library";
1077 break;
1078 default:
1079 usage();
1080 }
1081 }
1082
1083 argc -= optind;
1084 argv += optind;
1085
1086 interactive = isatty(STDIN_FILENO0) && isatty(STDOUT_FILENO1) &&
1087 isatty(STDERR_FILENO2);
1088 for (i = 0; i < argc; i++)
1089 sargv[sargc++] = argv[i];
1090
1091 if (do_fork) {
1092 if (pipe(p) == -1)
1093 err(1, "cannot create pipe");
1094 dc = fork();
1095 if (dc == -1)
1096 err(1, "cannot fork");
1097 else if (dc != 0) {
1098 signal(SIGCHLD20, sigchld);
1099 close(STDOUT_FILENO1);
1100 dup(p[1]);
1101 close(p[0]);
1102 close(p[1]);
1103 } else {
1104 char *dc_argv[] = { "dc", "-x", NULL((void *)0) };
1105 extern int dc_main(int, char **);
1106
1107 if (pledge("stdio", NULL((void *)0)) == -1)
1108 err(1, "pledge");
1109
1110 close(STDIN_FILENO0);
1111 dup(p[0]);
1112 close(p[0]);
1113 close(p[1]);
1114
1115 exit (dc_main(2, dc_argv));
1116 }
1117 }
1118 if (interactive) {
1119 gettty(&ttysaved);
1120 el = el_init("bc", stdin(&__sF[0]), stderr(&__sF[2]), stderr(&__sF[2]));
1121 hist = history_init();
1122 history(hist, &he, H_SETSIZE1, 100);
1123 el_set(el, EL_HIST10, history, hist);
1124 el_set(el, EL_EDITOR2, "emacs");
1125 el_set(el, EL_SIGNAL3, 0);
1126 el_set(el, EL_PROMPT0, dummy_prompt);
1127 el_set(el, EL_ADDFN9, "bc_eof", "", bc_eof);
1128 el_set(el, EL_BIND4, "^D", "bc_eof", NULL((void *)0));
1129 el_source(el, NULL((void *)0));
1130 }
1131
1132 if (pledge("stdio rpath tty", NULL((void *)0)) == -1)
1133 err(1, "pledge");
1134
1135 yywrap();
1136 return yyparse();
1137}
1138#line 1131 "bc.c"
1139/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1140static int yygrowstack(void)
1141{
1142 unsigned int newsize;
1143 long sslen;
1144 short *newss;
1145 YYSTYPE *newvs;
1146
1147 if ((newsize = yystacksize) == 0)
31
Assuming the condition is false
32
Taking false branch
1148 newsize = YYINITSTACKSIZE200;
1149 else if (newsize >= YYMAXDEPTH10000)
33
Assuming 'newsize' is < YYMAXDEPTH
34
Taking false branch
1150 return -1;
1151 else if ((newsize *= 2) > YYMAXDEPTH10000)
35
Assuming the condition is false
36
Taking false branch
1152 newsize = YYMAXDEPTH10000;
1153 sslen = yyssp - yyss;
1154#ifdef SIZE_MAX0xffffffffffffffffUL
1155#define YY_SIZE_MAX0xffffffffffffffffUL SIZE_MAX0xffffffffffffffffUL
1156#else
1157#define YY_SIZE_MAX0xffffffffffffffffUL 0xffffffffU
1158#endif
1159 if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newss)
37
Assuming 'newsize' is 0
1160 goto bail;
1161 newss = (short *)realloc(yyss, newsize * sizeof *newss);
1162 if (newss == NULL((void *)0))
38
Assuming 'newss' is not equal to NULL
39
Taking false branch
1163 goto bail;
1164 yyss = newss;
1165 yyssp = newss + sslen;
1166 if (newsize
39.1
'newsize' is 0
&& YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newvs)
1167 goto bail;
1168 newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs);
1169 if (newvs == NULL((void *)0))
40
Assuming 'newvs' is not equal to NULL
41
Taking false branch
1170 goto bail;
1171 yyvs = newvs;
1172 yyvsp = newvs + sslen;
1173 yystacksize = newsize;
1174 yysslim = yyss + newsize - 1;
1175 return 0;
1176bail:
1177 if (yyss)
1178 free(yyss);
1179 if (yyvs)
1180 free(yyvs);
1181 yyss = yyssp = NULL((void *)0);
1182 yyvs = yyvsp = NULL((void *)0);
1183 yystacksize = 0;
1184 return -1;
1185}
1186
1187#define YYABORTgoto yyabort goto yyabort
1188#define YYREJECTgoto yyabort goto yyabort
1189#define YYACCEPTgoto yyaccept goto yyaccept
1190#define YYERRORgoto yyerrlab goto yyerrlab
1191int
1192yyparse(void)
1193{
1194 int yym, yyn, yystate;
1195#if YYDEBUG0
1196 const char *yys;
1197
1198 if ((yys = getenv("YYDEBUG")))
1199 {
1200 yyn = *yys;
1201 if (yyn >= '0' && yyn <= '9')
1202 yydebug = yyn - '0';
1203 }
1204#endif /* YYDEBUG */
1205
1206 yynerrs = 0;
1207 yyerrflag = 0;
1208 yychar = (-1);
1209
1210 if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow;
1
Assuming 'yyss' is not equal to NULL
1211 yyssp = yyss;
1212 yyvsp = yyvs;
1213 *yyssp = yystate = 0;
1214
1215yyloop:
1216 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
2
Taking true branch
3
Control jumps to line 1323
13
Taking false branch
1217 if (yychar
13.1
'yychar' is >= 0
< 0)
14
Taking false branch
1218 {
1219 if ((yychar = yylex()) < 0) yychar = 0;
1220#if YYDEBUG0
1221 if (yydebug)
1222 {
1223 yys = 0;
1224 if (yychar <= YYMAXTOKEN304) yys = yyname[yychar];
1225 if (!yys) yys = "illegal-symbol";
1226 printf("%sdebug: state %d, reading %d (%s)\n",
1227 YYPREFIX"yy", yystate, yychar, yys);
1228 }
1229#endif
1230 }
1231 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
15
Assuming 'yyn' is not equal to 0
16
Assuming the condition is false
1232 yyn <= YYTABLESIZE1116 && yycheck[yyn] == yychar)
1233 {
1234#if YYDEBUG0
1235 if (yydebug)
1236 printf("%sdebug: state %d, shifting to state %d\n",
1237 YYPREFIX"yy", yystate, yytable[yyn]);
1238#endif
1239 if (yyssp >= yysslim && yygrowstack())
1240 {
1241 goto yyoverflow;
1242 }
1243 *++yyssp = yystate = yytable[yyn];
1244 *++yyvsp = yylval;
1245 yychar = (-1);
1246 if (yyerrflag > 0) --yyerrflag;
1247 goto yyloop;
1248 }
1249 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
17
Assuming 'yyn' is not equal to 0
1250 yyn <= YYTABLESIZE1116 && yycheck[yyn] == yychar)
1251 {
1252 yyn = yytable[yyn];
1253 goto yyreduce;
1254 }
1255 if (yyerrflag) goto yyinrecovery;
18
Assuming 'yyerrflag' is 0
19
Taking false branch
1256#if defined(__GNUC__4)
1257 goto yynewerror;
20
Control jumps to line 1260
1258#endif
1259yynewerror:
1260 yyerror("syntax error");
1261#if defined(__GNUC__4)
1262 goto yyerrlab;
21
Control jumps to line 1265
1263#endif
1264yyerrlab:
1265 ++yynerrs;
1266yyinrecovery:
1267 if (yyerrflag
21.1
'yyerrflag' is < 3
< 3)
22
Taking true branch
1268 {
1269 yyerrflag = 3;
1270 for (;;)
23
Loop condition is true. Entering loop body
1271 {
1272 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 &&
24
Assuming 'yyn' is not equal to 0
25
Assuming the condition is true
28
Taking true branch
1273 yyn <= YYTABLESIZE1116 && yycheck[yyn] == YYERRCODE256)
26
Assuming 'yyn' is <= YYTABLESIZE
27
Assuming the condition is true
1274 {
1275#if YYDEBUG0
1276 if (yydebug)
1277 printf("%sdebug: state %d, error recovery shifting\
1278 to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]);
1279#endif
1280 if (yyssp >= yysslim && yygrowstack())
29
Assuming 'yyssp' is >= 'yysslim'
30
Calling 'yygrowstack'
42
Returning from 'yygrowstack'
43
Taking false branch
1281 {
1282 goto yyoverflow;
1283 }
1284 *++yyssp = yystate = yytable[yyn];
44
Use of zero-allocated memory
1285 *++yyvsp = yylval;
1286 goto yyloop;
1287 }
1288 else
1289 {
1290#if YYDEBUG0
1291 if (yydebug)
1292 printf("%sdebug: error recovery discarding state %d\n",
1293 YYPREFIX"yy", *yyssp);
1294#endif
1295 if (yyssp <= yyss) goto yyabort;
1296 --yyssp;
1297 --yyvsp;
1298 }
1299 }
1300 }
1301 else
1302 {
1303 if (yychar == 0) goto yyabort;
1304#if YYDEBUG0
1305 if (yydebug)
1306 {
1307 yys = 0;
1308 if (yychar <= YYMAXTOKEN304) yys = yyname[yychar];
1309 if (!yys) yys = "illegal-symbol";
1310 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1311 YYPREFIX"yy", yystate, yychar, yys);
1312 }
1313#endif
1314 yychar = (-1);
1315 goto yyloop;
1316 }
1317yyreduce:
1318#if YYDEBUG0
1319 if (yydebug)
1320 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1321 YYPREFIX"yy", yystate, yyn, yyrule[yyn]);
1322#endif
1323 yym = yylen[yyn];
1324 if (yym
3.1
'yym' is 0
)
4
Taking false branch
1325 yyval = yyvsp[1-yym];
1326 else
1327 memset(&yyval, 0, sizeof yyval);
1328 switch (yyn)
5
'Default' branch taken. Execution continues on line 1985
1329 {
1330case 3:
1331#line 177 "/usr/src/usr.bin/bc/bc.y"
1332{
1333 emit(yyvsp[-1].node, 0);
1334 macro_char = reset_macro_char;
1335 putchar('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
1336 free_tree();
1337 st_has_continue = false0;
1338 }
1339break;
1340case 4:
1341#line 185 "/usr/src/usr.bin/bc/bc.y"
1342{
1343 putchar('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
1344 free_tree();
1345 st_has_continue = false0;
1346 }
1347break;
1348case 5:
1349#line 191 "/usr/src/usr.bin/bc/bc.y"
1350{
1351 yyerrok(yyerrflag=0);
1352 }
1353break;
1354case 6:
1355#line 195 "/usr/src/usr.bin/bc/bc.y"
1356{
1357 yyerrok(yyerrflag=0);
1358 }
1359break;
1360case 7:
1361#line 201 "/usr/src/usr.bin/bc/bc.y"
1362{
1363 yyval.node = cs("");
1364 }
1365break;
1366case 9:
1367#line 206 "/usr/src/usr.bin/bc/bc.y"
1368{
1369 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1370 }
1371break;
1372case 11:
1373#line 213 "/usr/src/usr.bin/bc/bc.y"
1374{
1375 yyval.node = cs("");
1376 }
1377break;
1378case 14:
1379#line 219 "/usr/src/usr.bin/bc/bc.y"
1380{
1381 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1382 }
1383break;
1384case 16:
1385#line 224 "/usr/src/usr.bin/bc/bc.y"
1386{
1387 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1388 }
1389break;
1390case 17:
1391#line 231 "/usr/src/usr.bin/bc/bc.y"
1392{
1393 yyval.node = cs("");
1394 }
1395break;
1396case 19:
1397#line 238 "/usr/src/usr.bin/bc/bc.y"
1398{
1399 yyval.node = node(yyvsp[0].node, cs("ps."), END_NODE((ssize_t) -1));
1400 }
1401break;
1402case 20:
1403#line 242 "/usr/src/usr.bin/bc/bc.y"
1404{
1405 if (yyvsp[-1].str[0] == '\0')
1406 yyval.node = node(yyvsp[0].node, cs(yyvsp[-1].str), yyvsp[-2].lvalue.store,
1407 END_NODE((ssize_t) -1));
1408 else
1409 yyval.node = node(yyvsp[-2].lvalue.load, yyvsp[0].node, cs(yyvsp[-1].str), yyvsp[-2].lvalue.store,
1410 END_NODE((ssize_t) -1));
1411 }
1412break;
1413case 21:
1414#line 251 "/usr/src/usr.bin/bc/bc.y"
1415{
1416 yyval.node = node(cs("["), as(yyvsp[0].str),
1417 cs("]P"), END_NODE((ssize_t) -1));
1418 }
1419break;
1420case 22:
1421#line 256 "/usr/src/usr.bin/bc/bc.y"
1422{
1423 if (breaksp == 0) {
1424 warning("break not in for or while");
1425 YYERRORgoto yyerrlab;
1426 } else {
1427 yyval.node = node(
1428 numnode(nesting -
1429 breakstack[breaksp-1]),
1430 cs("Q"), END_NODE((ssize_t) -1));
1431 }
1432 }
1433break;
1434case 23:
1435#line 268 "/usr/src/usr.bin/bc/bc.y"
1436{
1437 if (breaksp == 0) {
1438 warning("continue not in for or while");
1439 YYERRORgoto yyerrlab;
1440 } else {
1441 st_has_continue = true1;
1442 yyval.node = node(numnode(nesting -
1443 breakstack[breaksp-1] - 1),
1444 cs("J"), END_NODE((ssize_t) -1));
1445 }
1446 }
1447break;
1448case 24:
1449#line 280 "/usr/src/usr.bin/bc/bc.y"
1450{
1451 sigset_t mask;
1452
1453 putchar('q')(!__isthreaded ? __sputc('q', (&__sF[1])) : (putc)('q', (
&__sF[1])))
;
1454 fflush(stdout(&__sF[1]));
1455 if (dc) {
1456 sigprocmask(SIG_BLOCK1, NULL((void *)0), &mask);
1457 sigsuspend(&mask);
1458 } else
1459 exit(0);
1460 }
1461break;
1462case 25:
1463#line 292 "/usr/src/usr.bin/bc/bc.y"
1464{
1465 if (nesting == 0) {
1466 warning("return must be in a function");
1467 YYERRORgoto yyerrlab;
1468 }
1469 yyval.node = yyvsp[0].node;
1470 }
1471break;
1472case 26:
1473#line 302 "/usr/src/usr.bin/bc/bc.y"
1474{
1475 ssize_t n;
1476
1477 if (st_has_continue)
1478 n = node(yyvsp[-1].node, cs("M"), yyvsp[-3].node, cs("s."),
1479 yyvsp[-5].node, yyvsp[-8].node, END_NODE((ssize_t) -1));
1480 else
1481 n = node(yyvsp[-1].node, yyvsp[-3].node, cs("s."), yyvsp[-5].node, yyvsp[-8].node,
1482 END_NODE((ssize_t) -1));
1483
1484 emit_macro(yyvsp[-8].node, n);
1485 yyval.node = node(yyvsp[-7].node, cs("s."), yyvsp[-5].node, yyvsp[-8].node, cs(" "),
1486 END_NODE((ssize_t) -1));
1487 }
1488break;
1489case 27:
1490#line 318 "/usr/src/usr.bin/bc/bc.y"
1491{
1492 emit_macro(yyvsp[-4].node, yyvsp[0].node);
1493 yyval.node = node(yyvsp[-2].node, yyvsp[-4].node, cs(" "), END_NODE((ssize_t) -1));
1494 }
1495break;
1496case 28:
1497#line 324 "/usr/src/usr.bin/bc/bc.y"
1498{
1499 emit_macro(yyvsp[-8].node, yyvsp[-4].node);
1500 emit_macro(yyvsp[-2].node, yyvsp[0].node);
1501 yyval.node = node(yyvsp[-6].node, yyvsp[-8].node, cs("e"), yyvsp[-2].node, cs(" "),
1502 END_NODE((ssize_t) -1));
1503 }
1504break;
1505case 29:
1506#line 332 "/usr/src/usr.bin/bc/bc.y"
1507{
1508 ssize_t n;
1509
1510 if (st_has_continue)
1511 n = node(yyvsp[-1].node, cs("M"), yyvsp[-3].node, yyvsp[-4].node, END_NODE((ssize_t) -1));
1512 else
1513 n = node(yyvsp[-1].node, yyvsp[-3].node, yyvsp[-4].node, END_NODE((ssize_t) -1));
1514 emit_macro(yyvsp[-4].node, n);
1515 yyval.node = node(yyvsp[-3].node, yyvsp[-4].node, cs(" "), END_NODE((ssize_t) -1));
1516 }
1517break;
1518case 30:
1519#line 343 "/usr/src/usr.bin/bc/bc.y"
1520{
1521 yyval.node = yyvsp[-1].node;
1522 }
1523break;
1524case 31:
1525#line 347 "/usr/src/usr.bin/bc/bc.y"
1526{
1527 yyval.node = yyvsp[0].node;
1528 }
1529break;
1530case 32:
1531#line 353 "/usr/src/usr.bin/bc/bc.y"
1532{
1533 yyval.node = cs(str_table[macro_char]);
1534 macro_char++;
1535 /* Do not use [, \ and ] */
1536 if (macro_char == '[')
1537 macro_char += 3;
1538 /* skip letters */
1539 else if (macro_char == 'a')
1540 macro_char = '{';
1541 else if (macro_char == ARRAY_CHAR0xa1)
1542 macro_char += 26;
1543 else if (macro_char == 255)
1544 fatal("program too big");
1545 if (breaksp == BREAKSTACK_SZ(sizeof(breakstack)/sizeof(breakstack[0])))
1546 fatal("nesting too deep");
1547 breakstack[breaksp++] = nesting++;
1548 }
1549break;
1550case 33:
1551#line 373 "/usr/src/usr.bin/bc/bc.y"
1552{
1553 breaksp--;
1554 }
1555break;
1556case 34:
1557#line 381 "/usr/src/usr.bin/bc/bc.y"
1558{
1559 int n = node(prologue, yyvsp[-1].node, epilogue,
1560 cs("0"), numnode(nesting),
1561 cs("Q"), END_NODE((ssize_t) -1));
1562 emit_macro(yyvsp[-8].node, n);
1563 reset_macro_char = macro_char;
1564 nesting = 0;
1565 breaksp = 0;
1566 }
1567break;
1568case 35:
1569#line 393 "/usr/src/usr.bin/bc/bc.y"
1570{
1571 yyval.node = function_node(yyvsp[-1].astr);
1572 free(yyvsp[-1].astr);
1573 prologue = cs("");
1574 epilogue = cs("");
1575 nesting = 1;
1576 breaksp = 0;
1577 breakstack[breaksp] = 0;
1578 }
1579break;
1580case 40:
1581#line 415 "/usr/src/usr.bin/bc/bc.y"
1582{
1583 add_par(letter_node(yyvsp[0].astr));
1584 free(yyvsp[0].astr);
1585 }
1586break;
1587case 41:
1588#line 420 "/usr/src/usr.bin/bc/bc.y"
1589{
1590 add_par(array_node(yyvsp[-2].astr));
1591 free(yyvsp[-2].astr);
1592 }
1593break;
1594case 42:
1595#line 425 "/usr/src/usr.bin/bc/bc.y"
1596{
1597 add_par(letter_node(yyvsp[0].astr));
1598 free(yyvsp[0].astr);
1599 }
1600break;
1601case 43:
1602#line 430 "/usr/src/usr.bin/bc/bc.y"
1603{
1604 add_par(array_node(yyvsp[-2].astr));
1605 free(yyvsp[-2].astr);
1606 }
1607break;
1608case 47:
1609#line 446 "/usr/src/usr.bin/bc/bc.y"
1610{
1611 add_local(letter_node(yyvsp[0].astr));
1612 free(yyvsp[0].astr);
1613 }
1614break;
1615case 48:
1616#line 451 "/usr/src/usr.bin/bc/bc.y"
1617{
1618 add_local(array_node(yyvsp[-2].astr));
1619 free(yyvsp[-2].astr);
1620 }
1621break;
1622case 49:
1623#line 456 "/usr/src/usr.bin/bc/bc.y"
1624{
1625 add_local(letter_node(yyvsp[0].astr));
1626 free(yyvsp[0].astr);
1627 }
1628break;
1629case 50:
1630#line 461 "/usr/src/usr.bin/bc/bc.y"
1631{
1632 add_local(array_node(yyvsp[-2].astr));
1633 free(yyvsp[-2].astr);
1634 }
1635break;
1636case 51:
1637#line 470 "/usr/src/usr.bin/bc/bc.y"
1638{
1639 yyval.node = cs("");
1640 }
1641break;
1642case 54:
1643#line 479 "/usr/src/usr.bin/bc/bc.y"
1644{
1645 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1646 }
1647break;
1648case 55:
1649#line 483 "/usr/src/usr.bin/bc/bc.y"
1650{
1651 yyval.node = node(yyvsp[-4].node, cs("l"), array_node(yyvsp[-2].astr),
1652 END_NODE((ssize_t) -1));
1653 free(yyvsp[-2].astr);
1654 }
1655break;
1656case 56:
1657#line 492 "/usr/src/usr.bin/bc/bc.y"
1658{
1659 yyval.node = cs(" 0 0=");
1660 }
1661break;
1662case 58:
1663#line 500 "/usr/src/usr.bin/bc/bc.y"
1664{
1665 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("="), END_NODE((ssize_t) -1));
1666 }
1667break;
1668case 59:
1669#line 504 "/usr/src/usr.bin/bc/bc.y"
1670{
1671 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("!="), END_NODE((ssize_t) -1));
1672 }
1673break;
1674case 60:
1675#line 508 "/usr/src/usr.bin/bc/bc.y"
1676{
1677 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs(">"), END_NODE((ssize_t) -1));
1678 }
1679break;
1680case 61:
1681#line 512 "/usr/src/usr.bin/bc/bc.y"
1682{
1683 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("!<"), END_NODE((ssize_t) -1));
1684 }
1685break;
1686case 62:
1687#line 516 "/usr/src/usr.bin/bc/bc.y"
1688{
1689 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("<"), END_NODE((ssize_t) -1));
1690 }
1691break;
1692case 63:
1693#line 520 "/usr/src/usr.bin/bc/bc.y"
1694{
1695 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("!>"), END_NODE((ssize_t) -1));
1696 }
1697break;
1698case 64:
1699#line 524 "/usr/src/usr.bin/bc/bc.y"
1700{
1701 yyval.node = node(yyvsp[0].node, cs(" 0!="), END_NODE((ssize_t) -1));
1702 }
1703break;
1704case 65:
1705#line 532 "/usr/src/usr.bin/bc/bc.y"
1706{
1707 yyval.node = node(cs("0"), epilogue,
1708 numnode(nesting), cs("Q"), END_NODE((ssize_t) -1));
1709 }
1710break;
1711case 66:
1712#line 537 "/usr/src/usr.bin/bc/bc.y"
1713{
1714 yyval.node = node(yyvsp[0].node, epilogue,
1715 numnode(nesting), cs("Q"), END_NODE((ssize_t) -1));
1716 }
1717break;
1718case 67:
1719#line 542 "/usr/src/usr.bin/bc/bc.y"
1720{
1721 yyval.node = node(cs("0"), epilogue,
1722 numnode(nesting), cs("Q"), END_NODE((ssize_t) -1));
1723 }
1724break;
1725case 68:
1726#line 550 "/usr/src/usr.bin/bc/bc.y"
1727{
1728 yyval.node = cs(" 0");
1729 }
1730break;
1731case 70:
1732#line 557 "/usr/src/usr.bin/bc/bc.y"
1733{
1734 yyval.node = node(yyvsp[0].lvalue.load, END_NODE((ssize_t) -1));
1735 }
1736break;
1737case 71:
1738#line 560 "/usr/src/usr.bin/bc/bc.y"
1739{
1740 yyval.node = node(cs("l."), END_NODE((ssize_t) -1));
1741 }
1742break;
1743case 72:
1744#line 564 "/usr/src/usr.bin/bc/bc.y"
1745{
1746 yyval.node = node(cs(" "), as(yyvsp[0].str), END_NODE((ssize_t) -1));
1747 }
1748break;
1749case 73:
1750#line 568 "/usr/src/usr.bin/bc/bc.y"
1751{
1752 yyval.node = yyvsp[-1].node;
1753 }
1754break;
1755case 74:
1756#line 572 "/usr/src/usr.bin/bc/bc.y"
1757{
1758 yyval.node = node(yyvsp[-1].node, cs("l"),
1759 function_node(yyvsp[-3].astr), cs("x"),
1760 END_NODE((ssize_t) -1));
1761 free(yyvsp[-3].astr);
1762 }
1763break;
1764case 75:
1765#line 579 "/usr/src/usr.bin/bc/bc.y"
1766{
1767 yyval.node = node(cs(" 0"), yyvsp[0].node, cs("-"),
1768 END_NODE((ssize_t) -1));
1769 }
1770break;
1771case 76:
1772#line 584 "/usr/src/usr.bin/bc/bc.y"
1773{
1774 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("+"), END_NODE((ssize_t) -1));
1775 }
1776break;
1777case 77:
1778#line 588 "/usr/src/usr.bin/bc/bc.y"
1779{
1780 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("-"), END_NODE((ssize_t) -1));
1781 }
1782break;
1783case 78:
1784#line 592 "/usr/src/usr.bin/bc/bc.y"
1785{
1786 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("*"), END_NODE((ssize_t) -1));
1787 }
1788break;
1789case 79:
1790#line 596 "/usr/src/usr.bin/bc/bc.y"
1791{
1792 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("/"), END_NODE((ssize_t) -1));
1793 }
1794break;
1795case 80:
1796#line 600 "/usr/src/usr.bin/bc/bc.y"
1797{
1798 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("%"), END_NODE((ssize_t) -1));
1799 }
1800break;
1801case 81:
1802#line 604 "/usr/src/usr.bin/bc/bc.y"
1803{
1804 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("^"), END_NODE((ssize_t) -1));
1805 }
1806break;
1807case 82:
1808#line 608 "/usr/src/usr.bin/bc/bc.y"
1809{
1810 yyval.node = node(yyvsp[0].lvalue.load, cs("1+d"), yyvsp[0].lvalue.store,
1811 END_NODE((ssize_t) -1));
1812 }
1813break;
1814case 83:
1815#line 613 "/usr/src/usr.bin/bc/bc.y"
1816{
1817 yyval.node = node(yyvsp[0].lvalue.load, cs("1-d"),
1818 yyvsp[0].lvalue.store, END_NODE((ssize_t) -1));
1819 }
1820break;
1821case 84:
1822#line 618 "/usr/src/usr.bin/bc/bc.y"
1823{
1824 yyval.node = node(yyvsp[-1].lvalue.load, cs("d1+"),
1825 yyvsp[-1].lvalue.store, END_NODE((ssize_t) -1));
1826 }
1827break;
1828case 85:
1829#line 623 "/usr/src/usr.bin/bc/bc.y"
1830{
1831 yyval.node = node(yyvsp[-1].lvalue.load, cs("d1-"),
1832 yyvsp[-1].lvalue.store, END_NODE((ssize_t) -1));
1833 }
1834break;
1835case 86:
1836#line 628 "/usr/src/usr.bin/bc/bc.y"
1837{
1838 if (yyvsp[-1].str[0] == '\0')
1839 yyval.node = node(yyvsp[0].node, cs(yyvsp[-1].str), cs("d"), yyvsp[-2].lvalue.store,
1840 END_NODE((ssize_t) -1));
1841 else
1842 yyval.node = node(yyvsp[-2].lvalue.load, yyvsp[0].node, cs(yyvsp[-1].str), cs("d"),
1843 yyvsp[-2].lvalue.store, END_NODE((ssize_t) -1));
1844 }
1845break;
1846case 87:
1847#line 637 "/usr/src/usr.bin/bc/bc.y"
1848{
1849 yyval.node = node(yyvsp[-1].node, cs("Z"), END_NODE((ssize_t) -1));
1850 }
1851break;
1852case 88:
1853#line 641 "/usr/src/usr.bin/bc/bc.y"
1854{
1855 yyval.node = node(yyvsp[-1].node, cs("v"), END_NODE((ssize_t) -1));
1856 }
1857break;
1858case 89:
1859#line 645 "/usr/src/usr.bin/bc/bc.y"
1860{
1861 yyval.node = node(yyvsp[-1].node, cs("X"), END_NODE((ssize_t) -1));
1862 }
1863break;
1864case 90:
1865#line 649 "/usr/src/usr.bin/bc/bc.y"
1866{
1867 yyval.node = node(yyvsp[0].node, cs("N"), END_NODE((ssize_t) -1));
1868 }
1869break;
1870case 91:
1871#line 653 "/usr/src/usr.bin/bc/bc.y"
1872{
1873 ssize_t n = node(cs("R"), yyvsp[0].node, END_NODE((ssize_t) -1));
1874 emit_macro(yyvsp[-2].node, n);
1875 yyval.node = node(yyvsp[-4].node, cs("d0!="), yyvsp[-2].node, END_NODE((ssize_t) -1));
1876 }
1877break;
1878case 92:
1879#line 659 "/usr/src/usr.bin/bc/bc.y"
1880{
1881 ssize_t n = node(cs("R"), yyvsp[0].node, END_NODE((ssize_t) -1));
1882 emit_macro(yyvsp[-2].node, n);
1883 yyval.node = node(yyvsp[-4].node, cs("d0="), yyvsp[-2].node, END_NODE((ssize_t) -1));
1884 }
1885break;
1886case 93:
1887#line 665 "/usr/src/usr.bin/bc/bc.y"
1888{
1889 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("G"), END_NODE((ssize_t) -1));
1890 }
1891break;
1892case 94:
1893#line 669 "/usr/src/usr.bin/bc/bc.y"
1894{
1895 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("GN"), END_NODE((ssize_t) -1));
1896 }
1897break;
1898case 95:
1899#line 673 "/usr/src/usr.bin/bc/bc.y"
1900{
1901 yyval.node = node(yyvsp[0].node, yyvsp[-2].node, cs("("), END_NODE((ssize_t) -1));
1902 }
1903break;
1904case 96:
1905#line 677 "/usr/src/usr.bin/bc/bc.y"
1906{
1907 yyval.node = node(yyvsp[0].node, yyvsp[-2].node, cs("{"), END_NODE((ssize_t) -1));
1908 }
1909break;
1910case 97:
1911#line 681 "/usr/src/usr.bin/bc/bc.y"
1912{
1913 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("("), END_NODE((ssize_t) -1));
1914 }
1915break;
1916case 98:
1917#line 685 "/usr/src/usr.bin/bc/bc.y"
1918{
1919 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("{"), END_NODE((ssize_t) -1));
1920 }
1921break;
1922case 99:
1923#line 692 "/usr/src/usr.bin/bc/bc.y"
1924{
1925 yyval.lvalue.load = node(cs("l"), letter_node(yyvsp[0].astr),
1926 END_NODE((ssize_t) -1));
1927 yyval.lvalue.store = node(cs("s"), letter_node(yyvsp[0].astr),
1928 END_NODE((ssize_t) -1));
1929 free(yyvsp[0].astr);
1930 }
1931break;
1932case 100:
1933#line 700 "/usr/src/usr.bin/bc/bc.y"
1934{
1935 yyval.lvalue.load = node(yyvsp[-1].node, cs(";"),
1936 array_node(yyvsp[-3].astr), END_NODE((ssize_t) -1));
1937 yyval.lvalue.store = node(yyvsp[-1].node, cs(":"),
1938 array_node(yyvsp[-3].astr), END_NODE((ssize_t) -1));
1939 free(yyvsp[-3].astr);
1940 }
1941break;
1942case 101:
1943#line 708 "/usr/src/usr.bin/bc/bc.y"
1944{
1945 yyval.lvalue.load = cs("K");
1946 yyval.lvalue.store = cs("k");
1947 }
1948break;
1949case 102:
1950#line 713 "/usr/src/usr.bin/bc/bc.y"
1951{
1952 yyval.lvalue.load = cs("I");
1953 yyval.lvalue.store = cs("i");
1954 }
1955break;
1956case 103:
1957#line 718 "/usr/src/usr.bin/bc/bc.y"
1958{
1959 yyval.lvalue.load = cs("O");
1960 yyval.lvalue.store = cs("o");
1961 }
1962break;
1963case 105:
1964#line 727 "/usr/src/usr.bin/bc/bc.y"
1965{
1966 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1967 }
1968break;
1969case 106:
1970#line 733 "/usr/src/usr.bin/bc/bc.y"
1971{
1972 yyval.node = node(yyvsp[0].node, cs("ds.n"), END_NODE((ssize_t) -1));
1973 }
1974break;
1975case 107:
1976#line 737 "/usr/src/usr.bin/bc/bc.y"
1977{
1978 char *p = escape(yyvsp[0].str);
1979 yyval.node = node(cs("["), as(p), cs("]n"), END_NODE((ssize_t) -1));
1980 free(p);
1981 }
1982break;
1983#line 1976 "bc.c"
1984 }
1985 yyssp -= yym;
1986 yystate = *yyssp;
1987 yyvsp -= yym;
1988 yym = yylhs[yyn];
1989 if (yystate
5.1
'yystate' is equal to 0
== 0 && yym
5.2
'yym' is equal to 0
== 0)
6
Taking true branch
1990 {
1991#if YYDEBUG0
1992 if (yydebug)
1993 printf("%sdebug: after reduction, shifting from state 0 to\
1994 state %d\n", YYPREFIX"yy", YYFINAL1);
1995#endif
1996 yystate = YYFINAL1;
1997 *++yyssp = YYFINAL1;
1998 *++yyvsp = yyval;
1999 if (yychar
6.1
'yychar' is < 0
< 0)
7
Taking true branch
2000 {
2001 if ((yychar = yylex()) < 0) yychar = 0;
8
Assuming the condition is false
9
Taking false branch
2002#if YYDEBUG0
2003 if (yydebug)
2004 {
2005 yys = 0;
2006 if (yychar <= YYMAXTOKEN304) yys = yyname[yychar];
2007 if (!yys) yys = "illegal-symbol";
2008 printf("%sdebug: state %d, reading %d (%s)\n",
2009 YYPREFIX"yy", YYFINAL1, yychar, yys);
2010 }
2011#endif
2012 }
2013 if (yychar == 0) goto yyaccept;
10
Assuming 'yychar' is not equal to 0
11
Taking false branch
2014 goto yyloop;
12
Control jumps to line 1216
2015 }
2016 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
2017 yyn <= YYTABLESIZE1116 && yycheck[yyn] == yystate)
2018 yystate = yytable[yyn];
2019 else
2020 yystate = yydgoto[yym];
2021#if YYDEBUG0
2022 if (yydebug)
2023 printf("%sdebug: after reduction, shifting from state %d \
2024to state %d\n", YYPREFIX"yy", *yyssp, yystate);
2025#endif
2026 if (yyssp >= yysslim && yygrowstack())
2027 {
2028 goto yyoverflow;
2029 }
2030 *++yyssp = yystate;
2031 *++yyvsp = yyval;
2032 goto yyloop;
2033yyoverflow:
2034 yyerror("yacc stack overflow");
2035yyabort:
2036 if (yyss)
2037 free(yyss);
2038 if (yyvs)
2039 free(yyvs);
2040 yyss = yyssp = NULL((void *)0);
2041 yyvs = yyvsp = NULL((void *)0);
2042 yystacksize = 0;
2043 return (1);
2044yyaccept:
2045 if (yyss)
2046 free(yyss);
2047 if (yyvs)
2048 free(yyvs);
2049 yyss = yyssp = NULL((void *)0);
2050 yyvs = yyvsp = NULL((void *)0);
2051 yystacksize = 0;
2052 return (0);
2053}