1 /* A Bison parser, made by GNU Bison 1.875d. */ 2 3 /* Skeleton parser for Yacc-like parsing with Bison, 4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. */ 20 21 /* As a special exception, when this file is copied by Bison into a 22 Bison output file, you may use that output file without restriction. 23 This special exception was added by the Free Software Foundation 24 in version 1.24 of Bison. */ 25 26 /* Written by Richard Stallman by simplifying the original so called 27 ``semantic'' parser. */ 28 29 /* All symbols defined below should begin with yy or YY, to avoid 30 infringing on user name space. This should be done even for local 31 variables, as they might otherwise be expanded by user macros. 32 There are some unavoidable exceptions within include files to 33 define necessary library symbols; they are noted "INFRINGES ON 34 USER NAME SPACE" below. */ 35 36 /* Identify Bison output. */ 37 #define YYBISON 1 38 39 /* Skeleton name. */ 40 #define YYSKELETON_NAME "yacc.c" 41 42 /* Pure parsers. */ 43 #define YYPURE 0 44 45 /* Using locations. */ 46 #define YYLSP_NEEDED 0 47 48 49 50 /* Tokens. */ 51 #ifndef YYTOKENTYPE 52 # define YYTOKENTYPE 53 /* Put the tokens into the symbol table, so that GDB and other debuggers 54 know about them. */ 55 enum yytokentype { 56 ARITH_NUM = 258, 57 ARITH_LPAREN = 259, 58 ARITH_RPAREN = 260, 59 ARITH_OR = 261, 60 ARITH_AND = 262, 61 ARITH_BOR = 263, 62 ARITH_BXOR = 264, 63 ARITH_BAND = 265, 64 ARITH_NE = 266, 65 ARITH_EQ = 267, 66 ARITH_LE = 268, 67 ARITH_GE = 269, 68 ARITH_GT = 270, 69 ARITH_LT = 271, 70 ARITH_RSHIFT = 272, 71 ARITH_LSHIFT = 273, 72 ARITH_SUB = 274, 73 ARITH_ADD = 275, 74 ARITH_REM = 276, 75 ARITH_DIV = 277, 76 ARITH_MUL = 278, 77 ARITH_BNOT = 279, 78 ARITH_NOT = 280, 79 ARITH_UNARYPLUS = 281, 80 ARITH_UNARYMINUS = 282 81 }; 82 #endif 83 #define ARITH_NUM 258 84 #define ARITH_LPAREN 259 85 #define ARITH_RPAREN 260 86 #define ARITH_OR 261 87 #define ARITH_AND 262 88 #define ARITH_BOR 263 89 #define ARITH_BXOR 264 90 #define ARITH_BAND 265 91 #define ARITH_NE 266 92 #define ARITH_EQ 267 93 #define ARITH_LE 268 94 #define ARITH_GE 269 95 #define ARITH_GT 270 96 #define ARITH_LT 271 97 #define ARITH_RSHIFT 272 98 #define ARITH_LSHIFT 273 99 #define ARITH_SUB 274 100 #define ARITH_ADD 275 101 #define ARITH_REM 276 102 #define ARITH_DIV 277 103 #define ARITH_MUL 278 104 #define ARITH_BNOT 279 105 #define ARITH_NOT 280 106 #define ARITH_UNARYPLUS 281 107 #define ARITH_UNARYMINUS 282 108 109 110 111 112 /* Copy the first part of user declarations. */ 113 #line 1 "arith.y" 114 115 /* $NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $ */ 116 117 /*- 118 * Copyright (c) 1993 119 * The Regents of the University of California. All rights reserved. 120 * 121 * This code is derived from software contributed to Berkeley by 122 * Kenneth Almquist. 123 * 124 * Redistribution and use in source and binary forms, with or without 125 * modification, are permitted provided that the following conditions 126 * are met: 127 * 1. Redistributions of source code must retain the above copyright 128 * notice, this list of conditions and the following disclaimer. 129 * 2. Redistributions in binary form must reproduce the above copyright 130 * notice, this list of conditions and the following disclaimer in the 131 * documentation and/or other materials provided with the distribution. 132 * 3. Neither the name of the University nor the names of its contributors 133 * may be used to endorse or promote products derived from this software 134 * without specific prior written permission. 135 * 136 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 137 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 138 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 139 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 140 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 141 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 142 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 143 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 144 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 145 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 146 * SUCH DAMAGE. 147 */ 148 149 #include <sys/cdefs.h> 150 #ifndef lint 151 #if 0 152 static char sccsid[] = "@(#)arith.y 8.3 (Berkeley) 5/4/95"; 153 #else 154 __RCSID("$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $"); 155 #endif 156 #endif /* not lint */ 157 158 #include <stdlib.h> 159 #include "expand.h" 160 #include "shell.h" 161 #include "error.h" 162 #include "output.h" 163 #include "memalloc.h" 164 165 const char *arith_buf, *arith_startbuf; 166 167 void yyerror(const char *); 168 #ifdef TESTARITH 169 int main(int , char *[]); 170 int error(char *); 171 #endif 172 173 174 175 /* Enabling traces. */ 176 #ifndef YYDEBUG 177 # define YYDEBUG 0 178 #endif 179 180 /* Enabling verbose error messages. */ 181 #ifdef YYERROR_VERBOSE 182 # undef YYERROR_VERBOSE 183 # define YYERROR_VERBOSE 1 184 #else 185 # define YYERROR_VERBOSE 0 186 #endif 187 188 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) 189 typedef int YYSTYPE; 190 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ 191 # define YYSTYPE_IS_DECLARED 1 192 # define YYSTYPE_IS_TRIVIAL 1 193 #endif 194 195 196 197 /* Copy the second part of user declarations. */ 198 199 200 /* Line 214 of yacc.c. */ 201 #line 202 "arith.c" 202 203 #if ! defined (yyoverflow) || YYERROR_VERBOSE 204 205 # ifndef YYFREE 206 # define YYFREE free 207 # endif 208 # ifndef YYMALLOC 209 # define YYMALLOC malloc 210 # endif 211 212 /* The parser invokes alloca or malloc; define the necessary symbols. */ 213 214 # ifdef YYSTACK_USE_ALLOCA 215 # if YYSTACK_USE_ALLOCA 216 # define YYSTACK_ALLOC alloca 217 # endif 218 # else 219 # if defined (alloca) || defined (_ALLOCA_H) 220 # define YYSTACK_ALLOC alloca 221 # else 222 # ifdef __GNUC__ 223 # define YYSTACK_ALLOC __builtin_alloca 224 # endif 225 # endif 226 # endif 227 228 # ifdef YYSTACK_ALLOC 229 /* Pacify GCC's `empty if-body' warning. */ 230 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 231 # else 232 # if defined (__STDC__) || defined (__cplusplus) 233 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 234 # define YYSIZE_T size_t 235 # endif 236 # define YYSTACK_ALLOC YYMALLOC 237 # define YYSTACK_FREE YYFREE 238 # endif 239 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ 240 241 242 #if (! defined (yyoverflow) \ 243 && (! defined (__cplusplus) \ 244 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) 245 246 /* A type that is properly aligned for any stack member. */ 247 union yyalloc 248 { 249 short int yyss; 250 YYSTYPE yyvs; 251 }; 252 253 /* The size of the maximum gap between one aligned stack and the next. */ 254 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) 255 256 /* The size of an array large to enough to hold all stacks, each with 257 N elements. */ 258 # define YYSTACK_BYTES(N) \ 259 ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ 260 + YYSTACK_GAP_MAXIMUM) 261 262 /* Copy COUNT objects from FROM to TO. The source and destination do 263 not overlap. */ 264 # ifndef YYCOPY 265 # if defined (__GNUC__) && 1 < __GNUC__ 266 # define YYCOPY(To, From, Count) \ 267 __builtin_memcpy (To, From, (Count) * sizeof (*(From))) 268 # else 269 # define YYCOPY(To, From, Count) \ 270 do \ 271 { \ 272 register YYSIZE_T yyi; \ 273 for (yyi = 0; yyi < (Count); yyi++) \ 274 (To)[yyi] = (From)[yyi]; \ 275 } \ 276 while (0) 277 # endif 278 # endif 279 280 /* Relocate STACK from its old location to the new one. The 281 local variables YYSIZE and YYSTACKSIZE give the old and new number of 282 elements in the stack, and YYPTR gives the new location of the 283 stack. Advance YYPTR to a properly aligned location for the next 284 stack. */ 285 # define YYSTACK_RELOCATE(Stack) \ 286 do \ 287 { \ 288 YYSIZE_T yynewbytes; \ 289 YYCOPY (&yyptr->Stack, Stack, yysize); \ 290 Stack = &yyptr->Stack; \ 291 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 292 yyptr += yynewbytes / sizeof (*yyptr); \ 293 } \ 294 while (0) 295 296 #endif 297 298 #if defined (__STDC__) || defined (__cplusplus) 299 typedef signed char yysigned_char; 300 #else 301 typedef short int yysigned_char; 302 #endif 303 304 /* YYFINAL -- State number of the termination state. */ 305 #define YYFINAL 14 306 /* YYLAST -- Last index in YYTABLE. */ 307 #define YYLAST 170 308 309 /* YYNTOKENS -- Number of terminals. */ 310 #define YYNTOKENS 28 311 /* YYNNTS -- Number of nonterminals. */ 312 #define YYNNTS 3 313 /* YYNRULES -- Number of rules. */ 314 #define YYNRULES 26 315 /* YYNRULES -- Number of states. */ 316 #define YYNSTATES 52 317 318 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 319 #define YYUNDEFTOK 2 320 #define YYMAXUTOK 282 321 322 #define YYTRANSLATE(YYX) \ 323 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 324 325 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ 326 static const unsigned char yytranslate[] = 327 { 328 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 329 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 330 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 331 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 332 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 333 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 334 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 335 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 336 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 337 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 338 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 339 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 340 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 341 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 342 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 343 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 344 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 346 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 347 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 348 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 349 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 350 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 351 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 352 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 353 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 354 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 355 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 356 25, 26, 27 357 }; 358 359 #if YYDEBUG 360 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in 361 YYRHS. */ 362 static const unsigned char yyprhs[] = 363 { 364 0, 0, 3, 5, 9, 13, 17, 21, 25, 29, 365 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 366 73, 77, 81, 84, 87, 90, 93 367 }; 368 369 /* YYRHS -- A `-1'-separated list of the rules' RHS. */ 370 static const yysigned_char yyrhs[] = 371 { 372 29, 0, -1, 30, -1, 4, 30, 5, -1, 30, 373 6, 30, -1, 30, 7, 30, -1, 30, 8, 30, 374 -1, 30, 9, 30, -1, 30, 10, 30, -1, 30, 375 12, 30, -1, 30, 15, 30, -1, 30, 14, 30, 376 -1, 30, 16, 30, -1, 30, 13, 30, -1, 30, 377 11, 30, -1, 30, 18, 30, -1, 30, 17, 30, 378 -1, 30, 20, 30, -1, 30, 19, 30, -1, 30, 379 23, 30, -1, 30, 22, 30, -1, 30, 21, 30, 380 -1, 25, 30, -1, 24, 30, -1, 19, 30, -1, 381 20, 30, -1, 3, -1 382 }; 383 384 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 385 static const unsigned char yyrline[] = 386 { 387 0, 76, 76, 82, 83, 84, 85, 86, 87, 88, 388 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 389 99, 104, 109, 110, 111, 112, 113 390 }; 391 #endif 392 393 #if YYDEBUG || YYERROR_VERBOSE 394 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 395 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 396 static const char *const yytname[] = 397 { 398 "$end", "error", "$undefined", "ARITH_NUM", "ARITH_LPAREN", 399 "ARITH_RPAREN", "ARITH_OR", "ARITH_AND", "ARITH_BOR", "ARITH_BXOR", 400 "ARITH_BAND", "ARITH_NE", "ARITH_EQ", "ARITH_LE", "ARITH_GE", "ARITH_GT", 401 "ARITH_LT", "ARITH_RSHIFT", "ARITH_LSHIFT", "ARITH_SUB", "ARITH_ADD", 402 "ARITH_REM", "ARITH_DIV", "ARITH_MUL", "ARITH_BNOT", "ARITH_NOT", 403 "ARITH_UNARYPLUS", "ARITH_UNARYMINUS", "$accept", "exp", "expr", 0 404 }; 405 #endif 406 407 # ifdef YYPRINT 408 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to 409 token YYLEX-NUM. */ 410 static const unsigned short int yytoknum[] = 411 { 412 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 413 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 414 275, 276, 277, 278, 279, 280, 281, 282 415 }; 416 # endif 417 418 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 419 static const unsigned char yyr1[] = 420 { 421 0, 28, 29, 30, 30, 30, 30, 30, 30, 30, 422 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 423 30, 30, 30, 30, 30, 30, 30 424 }; 425 426 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 427 static const unsigned char yyr2[] = 428 { 429 0, 2, 1, 3, 3, 3, 3, 3, 3, 3, 430 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 431 3, 3, 2, 2, 2, 2, 1 432 }; 433 434 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state 435 STATE-NUM when YYTABLE doesn't specify something else to do. Zero 436 means the default is an error. */ 437 static const unsigned char yydefact[] = 438 { 439 0, 26, 0, 0, 0, 0, 0, 0, 2, 0, 440 24, 25, 23, 22, 1, 0, 0, 0, 0, 0, 441 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 442 0, 0, 0, 3, 4, 5, 6, 7, 8, 14, 443 9, 13, 11, 10, 12, 16, 15, 18, 17, 21, 444 20, 19 445 }; 446 447 /* YYDEFGOTO[NTERM-NUM]. */ 448 static const yysigned_char yydefgoto[] = 449 { 450 -1, 7, 8 451 }; 452 453 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 454 STATE-NUM. */ 455 #define YYPACT_NINF -13 456 static const short int yypact[] = 457 { 458 28, -13, 28, 28, 28, 28, 28, 12, 67, 49, 459 -13, -13, -13, -13, -13, 28, 28, 28, 28, 28, 460 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 461 28, 28, 28, -13, 84, 100, 115, 23, 128, 139, 462 139, -12, -12, -12, -12, 144, 144, 147, 147, -13, 463 -13, -13 464 }; 465 466 /* YYPGOTO[NTERM-NUM]. */ 467 static const yysigned_char yypgoto[] = 468 { 469 -13, -13, -2 470 }; 471 472 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 473 positive, shift that token. If negative, reduce the rule which 474 number is the opposite. If zero, do what YYDEFACT says. 475 If YYTABLE_NINF, syntax error. */ 476 #define YYTABLE_NINF -1 477 static const unsigned char yytable[] = 478 { 479 9, 10, 11, 12, 13, 26, 27, 28, 29, 30, 480 31, 32, 14, 34, 35, 36, 37, 38, 39, 40, 481 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 482 51, 1, 2, 19, 20, 21, 22, 23, 24, 25, 483 26, 27, 28, 29, 30, 31, 32, 3, 4, 0, 484 0, 0, 5, 6, 33, 15, 16, 17, 18, 19, 485 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 486 30, 31, 32, 15, 16, 17, 18, 19, 20, 21, 487 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 488 32, 16, 17, 18, 19, 20, 21, 22, 23, 24, 489 25, 26, 27, 28, 29, 30, 31, 32, 17, 18, 490 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 491 29, 30, 31, 32, 18, 19, 20, 21, 22, 23, 492 24, 25, 26, 27, 28, 29, 30, 31, 32, 20, 493 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 494 31, 32, 22, 23, 24, 25, 26, 27, 28, 29, 495 30, 31, 32, 28, 29, 30, 31, 32, 30, 31, 496 32 497 }; 498 499 static const yysigned_char yycheck[] = 500 { 501 2, 3, 4, 5, 6, 17, 18, 19, 20, 21, 502 22, 23, 0, 15, 16, 17, 18, 19, 20, 21, 503 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 504 32, 3, 4, 10, 11, 12, 13, 14, 15, 16, 505 17, 18, 19, 20, 21, 22, 23, 19, 20, -1, 506 -1, -1, 24, 25, 5, 6, 7, 8, 9, 10, 507 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 508 21, 22, 23, 6, 7, 8, 9, 10, 11, 12, 509 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 510 23, 7, 8, 9, 10, 11, 12, 13, 14, 15, 511 16, 17, 18, 19, 20, 21, 22, 23, 8, 9, 512 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 513 20, 21, 22, 23, 9, 10, 11, 12, 13, 14, 514 15, 16, 17, 18, 19, 20, 21, 22, 23, 11, 515 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 516 22, 23, 13, 14, 15, 16, 17, 18, 19, 20, 517 21, 22, 23, 19, 20, 21, 22, 23, 21, 22, 518 23 519 }; 520 521 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 522 symbol of state STATE-NUM. */ 523 static const unsigned char yystos[] = 524 { 525 0, 3, 4, 19, 20, 24, 25, 29, 30, 30, 526 30, 30, 30, 30, 0, 6, 7, 8, 9, 10, 527 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 528 21, 22, 23, 5, 30, 30, 30, 30, 30, 30, 529 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 530 30, 30 531 }; 532 533 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) 534 # define YYSIZE_T __SIZE_TYPE__ 535 #endif 536 #if ! defined (YYSIZE_T) && defined (size_t) 537 # define YYSIZE_T size_t 538 #endif 539 #if ! defined (YYSIZE_T) 540 # if defined (__STDC__) || defined (__cplusplus) 541 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 542 # define YYSIZE_T size_t 543 # endif 544 #endif 545 #if ! defined (YYSIZE_T) 546 # define YYSIZE_T unsigned int 547 #endif 548 549 #define yyerrok (yyerrstatus = 0) 550 #define yyclearin (yychar = YYEMPTY) 551 #define YYEMPTY (-2) 552 #define YYEOF 0 553 554 #define YYACCEPT goto yyacceptlab 555 #define YYABORT goto yyabortlab 556 #define YYERROR goto yyerrorlab 557 558 559 /* Like YYERROR except do call yyerror. This remains here temporarily 560 to ease the transition to the new meaning of YYERROR, for GCC. 561 Once GCC version 2 has supplanted version 1, this can go. */ 562 563 #define YYFAIL goto yyerrlab 564 565 #define YYRECOVERING() (!!yyerrstatus) 566 567 #define YYBACKUP(Token, Value) \ 568 do \ 569 if (yychar == YYEMPTY && yylen == 1) \ 570 { \ 571 yychar = (Token); \ 572 yylval = (Value); \ 573 yytoken = YYTRANSLATE (yychar); \ 574 YYPOPSTACK; \ 575 goto yybackup; \ 576 } \ 577 else \ 578 { \ 579 yyerror ("syntax error: cannot back up");\ 580 YYERROR; \ 581 } \ 582 while (0) 583 584 #define YYTERROR 1 585 #define YYERRCODE 256 586 587 /* YYLLOC_DEFAULT -- Compute the default location (before the actions 588 are run). */ 589 590 #ifndef YYLLOC_DEFAULT 591 # define YYLLOC_DEFAULT(Current, Rhs, N) \ 592 ((Current).first_line = (Rhs)[1].first_line, \ 593 (Current).first_column = (Rhs)[1].first_column, \ 594 (Current).last_line = (Rhs)[N].last_line, \ 595 (Current).last_column = (Rhs)[N].last_column) 596 #endif 597 598 /* YYLEX -- calling `yylex' with the right arguments. */ 599 600 #ifdef YYLEX_PARAM 601 # define YYLEX yylex (YYLEX_PARAM) 602 #else 603 # define YYLEX yylex () 604 #endif 605 606 /* Enable debugging if requested. */ 607 #if YYDEBUG 608 609 # ifndef YYFPRINTF 610 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ 611 # define YYFPRINTF fprintf 612 # endif 613 614 # define YYDPRINTF(Args) \ 615 do { \ 616 if (yydebug) \ 617 YYFPRINTF Args; \ 618 } while (0) 619 620 # define YYDSYMPRINT(Args) \ 621 do { \ 622 if (yydebug) \ 623 yysymprint Args; \ 624 } while (0) 625 626 # define YYDSYMPRINTF(Title, Token, Value, Location) \ 627 do { \ 628 if (yydebug) \ 629 { \ 630 YYFPRINTF (stderr, "%s ", Title); \ 631 yysymprint (stderr, \ 632 Token, Value); \ 633 YYFPRINTF (stderr, "\n"); \ 634 } \ 635 } while (0) 636 637 /*------------------------------------------------------------------. 638 | yy_stack_print -- Print the state stack from its BOTTOM up to its | 639 | TOP (included). | 640 `------------------------------------------------------------------*/ 641 642 #if defined (__STDC__) || defined (__cplusplus) 643 static void 644 yy_stack_print (short int *bottom, short int *top) 645 #else 646 static void 647 yy_stack_print (bottom, top) 648 short int *bottom; 649 short int *top; 650 #endif 651 { 652 YYFPRINTF (stderr, "Stack now"); 653 for (/* Nothing. */; bottom <= top; ++bottom) 654 YYFPRINTF (stderr, " %d", *bottom); 655 YYFPRINTF (stderr, "\n"); 656 } 657 658 # define YY_STACK_PRINT(Bottom, Top) \ 659 do { \ 660 if (yydebug) \ 661 yy_stack_print ((Bottom), (Top)); \ 662 } while (0) 663 664 665 /*------------------------------------------------. 666 | Report that the YYRULE is going to be reduced. | 667 `------------------------------------------------*/ 668 669 #if defined (__STDC__) || defined (__cplusplus) 670 static void 671 yy_reduce_print (int yyrule) 672 #else 673 static void 674 yy_reduce_print (yyrule) 675 int yyrule; 676 #endif 677 { 678 int yyi; 679 unsigned int yylno = yyrline[yyrule]; 680 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", 681 yyrule - 1, yylno); 682 /* Print the symbols being reduced, and their result. */ 683 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) 684 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); 685 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); 686 } 687 688 # define YY_REDUCE_PRINT(Rule) \ 689 do { \ 690 if (yydebug) \ 691 yy_reduce_print (Rule); \ 692 } while (0) 693 694 /* Nonzero means print parse trace. It is left uninitialized so that 695 multiple parsers can coexist. */ 696 int yydebug; 697 #else /* !YYDEBUG */ 698 # define YYDPRINTF(Args) 699 # define YYDSYMPRINT(Args) 700 # define YYDSYMPRINTF(Title, Token, Value, Location) 701 # define YY_STACK_PRINT(Bottom, Top) 702 # define YY_REDUCE_PRINT(Rule) 703 #endif /* !YYDEBUG */ 704 705 706 /* YYINITDEPTH -- initial size of the parser's stacks. */ 707 #ifndef YYINITDEPTH 708 # define YYINITDEPTH 200 709 #endif 710 711 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 712 if the built-in stack extension method is used). 713 714 Do not make this value too large; the results are undefined if 715 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) 716 evaluated with infinite-precision integer arithmetic. */ 717 718 #if defined (YYMAXDEPTH) && YYMAXDEPTH == 0 719 # undef YYMAXDEPTH 720 #endif 721 722 #ifndef YYMAXDEPTH 723 # define YYMAXDEPTH 10000 724 #endif 725 726 727 729 #if YYERROR_VERBOSE 730 731 # ifndef yystrlen 732 # if defined (__GLIBC__) && defined (_STRING_H) 733 # define yystrlen strlen 734 # else 735 /* Return the length of YYSTR. */ 736 static YYSIZE_T 737 # if defined (__STDC__) || defined (__cplusplus) 738 yystrlen (const char *yystr) 739 # else 740 yystrlen (yystr) 741 const char *yystr; 742 # endif 743 { 744 register const char *yys = yystr; 745 746 while (*yys++ != '\0') 747 continue; 748 749 return yys - yystr - 1; 750 } 751 # endif 752 # endif 753 754 # ifndef yystpcpy 755 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) 756 # define yystpcpy stpcpy 757 # else 758 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 759 YYDEST. */ 760 static char * 761 # if defined (__STDC__) || defined (__cplusplus) 762 yystpcpy (char *yydest, const char *yysrc) 763 # else 764 yystpcpy (yydest, yysrc) 765 char *yydest; 766 const char *yysrc; 767 # endif 768 { 769 register char *yyd = yydest; 770 register const char *yys = yysrc; 771 772 while ((*yyd++ = *yys++) != '\0') 773 continue; 774 775 return yyd - 1; 776 } 777 # endif 778 # endif 779 780 #endif /* !YYERROR_VERBOSE */ 781 782 783 785 #if YYDEBUG 786 /*--------------------------------. 787 | Print this symbol on YYOUTPUT. | 788 `--------------------------------*/ 789 790 #if defined (__STDC__) || defined (__cplusplus) 791 static void 792 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) 793 #else 794 static void 795 yysymprint (yyoutput, yytype, yyvaluep) 796 FILE *yyoutput; 797 int yytype; 798 YYSTYPE *yyvaluep; 799 #endif 800 { 801 /* Pacify ``unused variable'' warnings. */ 802 (void) yyvaluep; 803 804 if (yytype < YYNTOKENS) 805 { 806 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); 807 # ifdef YYPRINT 808 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 809 # endif 810 } 811 else 812 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 813 814 switch (yytype) 815 { 816 default: 817 break; 818 } 819 YYFPRINTF (yyoutput, ")"); 820 } 821 822 #endif /* ! YYDEBUG */ 823 /*-----------------------------------------------. 824 | Release the memory associated to this symbol. | 825 `-----------------------------------------------*/ 826 827 #if defined (__STDC__) || defined (__cplusplus) 828 static void 829 yydestruct (int yytype, YYSTYPE *yyvaluep) 830 #else 831 static void 832 yydestruct (yytype, yyvaluep) 833 int yytype; 834 YYSTYPE *yyvaluep; 835 #endif 836 { 837 /* Pacify ``unused variable'' warnings. */ 838 (void) yyvaluep; 839 840 switch (yytype) 841 { 842 843 default: 844 break; 845 } 846 } 847 848 850 /* Prevent warnings from -Wmissing-prototypes. */ 851 852 #ifdef YYPARSE_PARAM 853 # if defined (__STDC__) || defined (__cplusplus) 854 int yyparse (void *YYPARSE_PARAM); 855 # else 856 int yyparse (); 857 # endif 858 #else /* ! YYPARSE_PARAM */ 859 #if defined (__STDC__) || defined (__cplusplus) 860 int yyparse (void); 861 #else 862 int yyparse (); 863 #endif 864 #endif /* ! YYPARSE_PARAM */ 865 866 867 868 /* The lookahead symbol. */ 869 int yychar; 870 871 /* The semantic value of the lookahead symbol. */ 872 YYSTYPE yylval; 873 874 /* Number of syntax errors so far. */ 875 int yynerrs; 876 877 878 879 /*----------. 880 | yyparse. | 881 `----------*/ 882 883 #ifdef YYPARSE_PARAM 884 # if defined (__STDC__) || defined (__cplusplus) 885 int yyparse (void *YYPARSE_PARAM) 886 # else 887 int yyparse (YYPARSE_PARAM) 888 void *YYPARSE_PARAM; 889 # endif 890 #else /* ! YYPARSE_PARAM */ 891 #if defined (__STDC__) || defined (__cplusplus) 892 int 893 yyparse (void) 894 #else 895 int 896 yyparse () 897 898 #endif 899 #endif 900 { 901 902 register int yystate; 903 register int yyn; 904 int yyresult; 905 /* Number of tokens to shift before error messages enabled. */ 906 int yyerrstatus; 907 /* Lookahead token as an internal (translated) token number. */ 908 int yytoken = 0; 909 910 /* Three stacks and their tools: 911 `yyss': related to states, 912 `yyvs': related to semantic values, 913 `yyls': related to locations. 914 915 Refer to the stacks thru separate pointers, to allow yyoverflow 916 to reallocate them elsewhere. */ 917 918 /* The state stack. */ 919 short int yyssa[YYINITDEPTH]; 920 short int *yyss = yyssa; 921 register short int *yyssp; 922 923 /* The semantic value stack. */ 924 YYSTYPE yyvsa[YYINITDEPTH]; 925 YYSTYPE *yyvs = yyvsa; 926 register YYSTYPE *yyvsp; 927 928 929 930 #define YYPOPSTACK (yyvsp--, yyssp--) 931 932 YYSIZE_T yystacksize = YYINITDEPTH; 933 934 /* The variables used to return semantic value and location from the 935 action routines. */ 936 YYSTYPE yyval; 937 938 939 /* When reducing, the number of symbols on the RHS of the reduced 940 rule. */ 941 int yylen; 942 943 YYDPRINTF ((stderr, "Starting parse\n")); 944 945 yystate = 0; 946 yyerrstatus = 0; 947 yynerrs = 0; 948 yychar = YYEMPTY; /* Cause a token to be read. */ 949 950 /* Initialize stack pointers. 951 Waste one element of value and location stack 952 so that they stay on the same level as the state stack. 953 The wasted elements are never initialized. */ 954 955 yyssp = yyss; 956 yyvsp = yyvs; 957 958 959 goto yysetstate; 960 961 /*------------------------------------------------------------. 962 | yynewstate -- Push a new state, which is found in yystate. | 963 `------------------------------------------------------------*/ 964 yynewstate: 965 /* In all cases, when you get here, the value and location stacks 966 have just been pushed. so pushing a state here evens the stacks. 967 */ 968 yyssp++; 969 970 yysetstate: 971 *yyssp = yystate; 972 973 if (yyss + yystacksize - 1 <= yyssp) 974 { 975 /* Get the current used size of the three stacks, in elements. */ 976 YYSIZE_T yysize = yyssp - yyss + 1; 977 978 #ifdef yyoverflow 979 { 980 /* Give user a chance to reallocate the stack. Use copies of 981 these so that the &'s don't force the real ones into 982 memory. */ 983 YYSTYPE *yyvs1 = yyvs; 984 short int *yyss1 = yyss; 985 986 987 /* Each stack pointer address is followed by the size of the 988 data in use in that stack, in bytes. This used to be a 989 conditional around just the two extra args, but that might 990 be undefined if yyoverflow is a macro. */ 991 yyoverflow ("parser stack overflow", 992 &yyss1, yysize * sizeof (*yyssp), 993 &yyvs1, yysize * sizeof (*yyvsp), 994 995 &yystacksize); 996 997 yyss = yyss1; 998 yyvs = yyvs1; 999 } 1000 #else /* no yyoverflow */ 1001 # ifndef YYSTACK_RELOCATE 1002 goto yyoverflowlab; 1003 # else 1004 /* Extend the stack our own way. */ 1005 if (YYMAXDEPTH <= yystacksize) 1006 goto yyoverflowlab; 1007 yystacksize *= 2; 1008 if (YYMAXDEPTH < yystacksize) 1009 yystacksize = YYMAXDEPTH; 1010 1011 { 1012 short int *yyss1 = yyss; 1013 union yyalloc *yyptr = 1014 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1015 if (! yyptr) 1016 goto yyoverflowlab; 1017 YYSTACK_RELOCATE (yyss); 1018 YYSTACK_RELOCATE (yyvs); 1019 1020 # undef YYSTACK_RELOCATE 1021 if (yyss1 != yyssa) 1022 YYSTACK_FREE (yyss1); 1023 } 1024 # endif 1025 #endif /* no yyoverflow */ 1026 1027 yyssp = yyss + yysize - 1; 1028 yyvsp = yyvs + yysize - 1; 1029 1030 1031 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1032 (unsigned long int) yystacksize)); 1033 1034 if (yyss + yystacksize - 1 <= yyssp) 1035 YYABORT; 1036 } 1037 1038 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1039 1040 goto yybackup; 1041 1042 /*-----------. 1043 | yybackup. | 1044 `-----------*/ 1045 yybackup: 1046 1047 /* Do appropriate processing given the current state. */ 1048 /* Read a lookahead token if we need one and don't already have one. */ 1049 /* yyresume: */ 1050 1051 /* First try to decide what to do without reference to lookahead token. */ 1052 1053 yyn = yypact[yystate]; 1054 if (yyn == YYPACT_NINF) 1055 goto yydefault; 1056 1057 /* Not known => get a lookahead token if don't already have one. */ 1058 1059 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ 1060 if (yychar == YYEMPTY) 1061 { 1062 YYDPRINTF ((stderr, "Reading a token: ")); 1063 yychar = YYLEX; 1064 } 1065 1066 if (yychar <= YYEOF) 1067 { 1068 yychar = yytoken = YYEOF; 1069 YYDPRINTF ((stderr, "Now at end of input.\n")); 1070 } 1071 else 1072 { 1073 yytoken = YYTRANSLATE (yychar); 1074 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); 1075 } 1076 1077 /* If the proper action on seeing token YYTOKEN is to reduce or to 1078 detect an error, take that action. */ 1079 yyn += yytoken; 1080 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1081 goto yydefault; 1082 yyn = yytable[yyn]; 1083 if (yyn <= 0) 1084 { 1085 if (yyn == 0 || yyn == YYTABLE_NINF) 1086 goto yyerrlab; 1087 yyn = -yyn; 1088 goto yyreduce; 1089 } 1090 1091 if (yyn == YYFINAL) 1092 YYACCEPT; 1093 1094 /* Shift the lookahead token. */ 1095 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); 1096 1097 /* Discard the token being shifted unless it is eof. */ 1098 if (yychar != YYEOF) 1099 yychar = YYEMPTY; 1100 1101 *++yyvsp = yylval; 1102 1103 1104 /* Count tokens shifted since error; after three, turn off error 1105 status. */ 1106 if (yyerrstatus) 1107 yyerrstatus--; 1108 1109 yystate = yyn; 1110 goto yynewstate; 1111 1112 1113 /*-----------------------------------------------------------. 1114 | yydefault -- do the default action for the current state. | 1115 `-----------------------------------------------------------*/ 1116 yydefault: 1117 yyn = yydefact[yystate]; 1118 if (yyn == 0) 1119 goto yyerrlab; 1120 goto yyreduce; 1121 1122 1123 /*-----------------------------. 1124 | yyreduce -- Do a reduction. | 1125 `-----------------------------*/ 1126 yyreduce: 1127 /* yyn is the number of a rule to reduce with. */ 1128 yylen = yyr2[yyn]; 1129 1130 /* If YYLEN is nonzero, implement the default value of the action: 1131 `$$ = $1'. 1132 1133 Otherwise, the following line sets YYVAL to garbage. 1134 This behavior is undocumented and Bison 1135 users should not rely upon it. Assigning to YYVAL 1136 unconditionally makes the parser a bit smaller, and it avoids a 1137 GCC warning that YYVAL may be used uninitialized. */ 1138 yyval = yyvsp[1-yylen]; 1139 1140 1141 YY_REDUCE_PRINT (yyn); 1142 switch (yyn) 1143 { 1144 case 2: 1145 #line 76 "arith.y" 1146 { 1147 return (yyvsp[0]); 1148 ;} 1149 break; 1150 1151 case 3: 1152 #line 82 "arith.y" 1153 { yyval = yyvsp[-1]; ;} 1154 break; 1155 1156 case 4: 1157 #line 83 "arith.y" 1158 { yyval = yyvsp[-2] ? yyvsp[-2] : yyvsp[0] ? yyvsp[0] : 0; ;} 1159 break; 1160 1161 case 5: 1162 #line 84 "arith.y" 1163 { yyval = yyvsp[-2] ? ( yyvsp[0] ? yyvsp[0] : 0 ) : 0; ;} 1164 break; 1165 1166 case 6: 1167 #line 85 "arith.y" 1168 { yyval = yyvsp[-2] | yyvsp[0]; ;} 1169 break; 1170 1171 case 7: 1172 #line 86 "arith.y" 1173 { yyval = yyvsp[-2] ^ yyvsp[0]; ;} 1174 break; 1175 1176 case 8: 1177 #line 87 "arith.y" 1178 { yyval = yyvsp[-2] & yyvsp[0]; ;} 1179 break; 1180 1181 case 9: 1182 #line 88 "arith.y" 1183 { yyval = yyvsp[-2] == yyvsp[0]; ;} 1184 break; 1185 1186 case 10: 1187 #line 89 "arith.y" 1188 { yyval = yyvsp[-2] > yyvsp[0]; ;} 1189 break; 1190 1191 case 11: 1192 #line 90 "arith.y" 1193 { yyval = yyvsp[-2] >= yyvsp[0]; ;} 1194 break; 1195 1196 case 12: 1197 #line 91 "arith.y" 1198 { yyval = yyvsp[-2] < yyvsp[0]; ;} 1199 break; 1200 1201 case 13: 1202 #line 92 "arith.y" 1203 { yyval = yyvsp[-2] <= yyvsp[0]; ;} 1204 break; 1205 1206 case 14: 1207 #line 93 "arith.y" 1208 { yyval = yyvsp[-2] != yyvsp[0]; ;} 1209 break; 1210 1211 case 15: 1212 #line 94 "arith.y" 1213 { yyval = yyvsp[-2] << yyvsp[0]; ;} 1214 break; 1215 1216 case 16: 1217 #line 95 "arith.y" 1218 { yyval = yyvsp[-2] >> yyvsp[0]; ;} 1219 break; 1220 1221 case 17: 1222 #line 96 "arith.y" 1223 { yyval = yyvsp[-2] + yyvsp[0]; ;} 1224 break; 1225 1226 case 18: 1227 #line 97 "arith.y" 1228 { yyval = yyvsp[-2] - yyvsp[0]; ;} 1229 break; 1230 1231 case 19: 1232 #line 98 "arith.y" 1233 { yyval = yyvsp[-2] * yyvsp[0]; ;} 1234 break; 1235 1236 case 20: 1237 #line 99 "arith.y" 1238 { 1239 if (yyvsp[0] == 0) 1240 yyerror("division by zero"); 1241 yyval = yyvsp[-2] / yyvsp[0]; 1242 ;} 1243 break; 1244 1245 case 21: 1246 #line 104 "arith.y" 1247 { 1248 if (yyvsp[0] == 0) 1249 yyerror("division by zero"); 1250 yyval = yyvsp[-2] % yyvsp[0]; 1251 ;} 1252 break; 1253 1254 case 22: 1255 #line 109 "arith.y" 1256 { yyval = !(yyvsp[0]); ;} 1257 break; 1258 1259 case 23: 1260 #line 110 "arith.y" 1261 { yyval = ~(yyvsp[0]); ;} 1262 break; 1263 1264 case 24: 1265 #line 111 "arith.y" 1266 { yyval = -(yyvsp[0]); ;} 1267 break; 1268 1269 case 25: 1270 #line 112 "arith.y" 1271 { yyval = yyvsp[0]; ;} 1272 break; 1273 1274 1275 } 1276 1277 /* Line 1010 of yacc.c. */ 1278 #line 1276 "arith.c" 1279 1280 yyvsp -= yylen; 1282 yyssp -= yylen; 1283 1284 1285 YY_STACK_PRINT (yyss, yyssp); 1286 1287 *++yyvsp = yyval; 1288 1289 1290 /* Now `shift' the result of the reduction. Determine what state 1291 that goes to, based on the state we popped back to and the rule 1292 number reduced by. */ 1293 1294 yyn = yyr1[yyn]; 1295 1296 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; 1297 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) 1298 yystate = yytable[yystate]; 1299 else 1300 yystate = yydefgoto[yyn - YYNTOKENS]; 1301 1302 goto yynewstate; 1303 1304 1305 /*------------------------------------. 1306 | yyerrlab -- here on detecting error | 1307 `------------------------------------*/ 1308 yyerrlab: 1309 /* If not already recovering from an error, report this error. */ 1310 if (!yyerrstatus) 1311 { 1312 ++yynerrs; 1313 #if YYERROR_VERBOSE 1314 yyn = yypact[yystate]; 1315 1316 if (YYPACT_NINF < yyn && yyn < YYLAST) 1317 { 1318 YYSIZE_T yysize = 0; 1319 int yytype = YYTRANSLATE (yychar); 1320 const char* yyprefix; 1321 char *yymsg; 1322 int yyx; 1323 1324 /* Start YYX at -YYN if negative to avoid negative indexes in 1325 YYCHECK. */ 1326 int yyxbegin = yyn < 0 ? -yyn : 0; 1327 1328 /* Stay within bounds of both yycheck and yytname. */ 1329 int yychecklim = YYLAST - yyn; 1330 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 1331 int yycount = 0; 1332 1333 yyprefix = ", expecting "; 1334 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1335 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) 1336 { 1337 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); 1338 yycount += 1; 1339 if (yycount == 5) 1340 { 1341 yysize = 0; 1342 break; 1343 } 1344 } 1345 yysize += (sizeof ("syntax error, unexpected ") 1346 + yystrlen (yytname[yytype])); 1347 yymsg = (char *) YYSTACK_ALLOC (yysize); 1348 if (yymsg != 0) 1349 { 1350 char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); 1351 yyp = yystpcpy (yyp, yytname[yytype]); 1352 1353 if (yycount < 5) 1354 { 1355 yyprefix = ", expecting "; 1356 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1357 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) 1358 { 1359 yyp = yystpcpy (yyp, yyprefix); 1360 yyp = yystpcpy (yyp, yytname[yyx]); 1361 yyprefix = " or "; 1362 } 1363 } 1364 yyerror (yymsg); 1365 YYSTACK_FREE (yymsg); 1366 } 1367 else 1368 yyerror ("syntax error; also virtual memory exhausted"); 1369 } 1370 else 1371 #endif /* YYERROR_VERBOSE */ 1372 yyerror ("syntax error"); 1373 } 1374 1375 1376 1377 if (yyerrstatus == 3) 1378 { 1379 /* If just tried and failed to reuse lookahead token after an 1380 error, discard it. */ 1381 1382 if (yychar <= YYEOF) 1383 { 1384 /* If at end of input, pop the error token, 1385 then the rest of the stack, then return failure. */ 1386 if (yychar == YYEOF) 1387 for (;;) 1388 { 1389 YYPOPSTACK; 1390 if (yyssp == yyss) 1391 YYABORT; 1392 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); 1393 yydestruct (yystos[*yyssp], yyvsp); 1394 } 1395 } 1396 else 1397 { 1398 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); 1399 yydestruct (yytoken, &yylval); 1400 yychar = YYEMPTY; 1401 1402 } 1403 } 1404 1405 /* Else will try to reuse lookahead token after shifting the error 1406 token. */ 1407 goto yyerrlab1; 1408 1409 1410 /*---------------------------------------------------. 1411 | yyerrorlab -- error raised explicitly by YYERROR. | 1412 `---------------------------------------------------*/ 1413 yyerrorlab: 1414 1415 #ifdef __GNUC__ 1416 /* Pacify GCC when the user code never invokes YYERROR and the label 1417 yyerrorlab therefore never appears in user code. */ 1418 if (0) 1419 goto yyerrorlab; 1420 #endif 1421 1422 yyvsp -= yylen; 1423 yyssp -= yylen; 1424 yystate = *yyssp; 1425 goto yyerrlab1; 1426 1427 1428 /*-------------------------------------------------------------. 1429 | yyerrlab1 -- common code for both syntax error and YYERROR. | 1430 `-------------------------------------------------------------*/ 1431 yyerrlab1: 1432 yyerrstatus = 3; /* Each real token shifted decrements this. */ 1433 1434 for (;;) 1435 { 1436 yyn = yypact[yystate]; 1437 if (yyn != YYPACT_NINF) 1438 { 1439 yyn += YYTERROR; 1440 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) 1441 { 1442 yyn = yytable[yyn]; 1443 if (0 < yyn) 1444 break; 1445 } 1446 } 1447 1448 /* Pop the current state because it cannot handle the error token. */ 1449 if (yyssp == yyss) 1450 YYABORT; 1451 1452 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); 1453 yydestruct (yystos[yystate], yyvsp); 1454 YYPOPSTACK; 1455 yystate = *yyssp; 1456 YY_STACK_PRINT (yyss, yyssp); 1457 } 1458 1459 if (yyn == YYFINAL) 1460 YYACCEPT; 1461 1462 YYDPRINTF ((stderr, "Shifting error token, ")); 1463 1464 *++yyvsp = yylval; 1465 1466 1467 yystate = yyn; 1468 goto yynewstate; 1469 1470 1471 /*-------------------------------------. 1472 | yyacceptlab -- YYACCEPT comes here. | 1473 `-------------------------------------*/ 1474 yyacceptlab: 1475 yyresult = 0; 1476 goto yyreturn; 1477 1478 /*-----------------------------------. 1479 | yyabortlab -- YYABORT comes here. | 1480 `-----------------------------------*/ 1481 yyabortlab: 1482 yyresult = 1; 1483 goto yyreturn; 1484 1485 #ifndef yyoverflow 1486 /*----------------------------------------------. 1487 | yyoverflowlab -- parser overflow comes here. | 1488 `----------------------------------------------*/ 1489 yyoverflowlab: 1490 yyerror ("parser stack overflow"); 1491 yyresult = 2; 1492 /* Fall through. */ 1493 #endif 1494 1495 yyreturn: 1496 #ifndef yyoverflow 1497 if (yyss != yyssa) 1498 YYSTACK_FREE (yyss); 1499 #endif 1500 return yyresult; 1501 } 1502 1503 1504 #line 115 "arith.y" 1505 1506 int 1507 arith(s) 1508 const char *s; 1509 { 1510 long result; 1511 1512 arith_buf = arith_startbuf = s; 1513 1514 INTOFF; 1515 result = yyparse(); 1516 arith_lex_reset(); /* reprime lex */ 1517 INTON; 1518 1519 return (result); 1520 } 1521 1522 1523 /* 1524 * The exp(1) builtin. 1525 */ 1526 int 1527 expcmd(argc, argv) 1528 int argc; 1529 char **argv; 1530 { 1531 const char *p; 1532 char *concat; 1533 char **ap; 1534 long i; 1535 1536 if (argc > 1) { 1537 p = argv[1]; 1538 if (argc > 2) { 1539 /* 1540 * concatenate arguments 1541 */ 1542 STARTSTACKSTR(concat); 1543 ap = argv + 2; 1544 for (;;) { 1545 while (*p) 1546 STPUTC(*p++, concat); 1547 if ((p = *ap++) == NULL) 1548 break; 1549 STPUTC(' ', concat); 1550 } 1551 STPUTC('\0', concat); 1552 p = grabstackstr(concat); 1553 } 1554 } else 1555 p = ""; 1556 1557 i = arith(p); 1558 1559 out1fmt("%ld\n", i); 1560 return (! i); 1561 } 1562 1563 /*************************/ 1564 #ifdef TEST_ARITH 1565 #include <stdio.h> 1566 main(argc, argv) 1567 char *argv[]; 1568 { 1569 printf("%d\n", exp(argv[1])); 1570 } 1571 error(s) 1572 char *s; 1573 { 1574 fprintf(stderr, "exp: %s\n", s); 1575 exit(1); 1576 } 1577 #endif 1578 1579 void 1580 yyerror(s) 1581 const char *s; 1582 { 1583 1584 // yyerrok; 1585 yyclearin; 1586 arith_lex_reset(); /* reprime lex */ 1587 error("arithmetic expression: %s: \"%s\"", s, arith_startbuf); 1588 /* NOTREACHED */ 1589 } 1590 1591 1592