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 152static 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 165const char *arith_buf, *arith_startbuf; 166 167void yyerror(const char *); 168#ifdef TESTARITH 169int main(int , char *[]); 170int 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) 189typedef 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. */ 247union 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. */ 326static 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. */ 362static 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. */ 370static 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. */ 385static 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. */ 396static 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. */ 410static 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. */ 419static 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. */ 427static 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. */ 437static 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]. */ 448static 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 456static 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]. */ 467static 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 477static 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 499static 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. */ 523static 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) \ 568do \ 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 } \ 582while (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) \ 615do { \ 616 if (yydebug) \ 617 YYFPRINTF Args; \ 618} while (0) 619 620# define YYDSYMPRINT(Args) \ 621do { \ 622 if (yydebug) \ 623 yysymprint Args; \ 624} while (0) 625 626# define YYDSYMPRINTF(Title, Token, Value, Location) \ 627do { \ 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) 643static void 644yy_stack_print (short int *bottom, short int *top) 645#else 646static void 647yy_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) \ 659do { \ 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) 670static void 671yy_reduce_print (int yyrule) 672#else 673static void 674yy_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) \ 689do { \ 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. */ 696int 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 728#if YYERROR_VERBOSE 729 730# ifndef yystrlen 731# if defined (__GLIBC__) && defined (_STRING_H) 732# define yystrlen strlen 733# else 734/* Return the length of YYSTR. */ 735static YYSIZE_T 736# if defined (__STDC__) || defined (__cplusplus) 737yystrlen (const char *yystr) 738# else 739yystrlen (yystr) 740 const char *yystr; 741# endif 742{ 743 register const char *yys = yystr; 744 745 while (*yys++ != '\0') 746 continue; 747 748 return yys - yystr - 1; 749} 750# endif 751# endif 752 753# ifndef yystpcpy 754# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) 755# define yystpcpy stpcpy 756# else 757/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 758 YYDEST. */ 759static char * 760# if defined (__STDC__) || defined (__cplusplus) 761yystpcpy (char *yydest, const char *yysrc) 762# else 763yystpcpy (yydest, yysrc) 764 char *yydest; 765 const char *yysrc; 766# endif 767{ 768 register char *yyd = yydest; 769 register const char *yys = yysrc; 770 771 while ((*yyd++ = *yys++) != '\0') 772 continue; 773 774 return yyd - 1; 775} 776# endif 777# endif 778 779#endif /* !YYERROR_VERBOSE */ 780 781 782 783#if YYDEBUG 784/*--------------------------------. 785| Print this symbol on YYOUTPUT. | 786`--------------------------------*/ 787 788#if defined (__STDC__) || defined (__cplusplus) 789static void 790yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) 791#else 792static void 793yysymprint (yyoutput, yytype, yyvaluep) 794 FILE *yyoutput; 795 int yytype; 796 YYSTYPE *yyvaluep; 797#endif 798{ 799 /* Pacify ``unused variable'' warnings. */ 800 (void) yyvaluep; 801 802 if (yytype < YYNTOKENS) 803 { 804 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); 805# ifdef YYPRINT 806 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 807# endif 808 } 809 else 810 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 811 812 switch (yytype) 813 { 814 default: 815 break; 816 } 817 YYFPRINTF (yyoutput, ")"); 818} 819 820#endif /* ! YYDEBUG */ 821/*-----------------------------------------------. 822| Release the memory associated to this symbol. | 823`-----------------------------------------------*/ 824 825#if defined (__STDC__) || defined (__cplusplus) 826static void 827yydestruct (int yytype, YYSTYPE *yyvaluep) 828#else 829static void 830yydestruct (yytype, yyvaluep) 831 int yytype; 832 YYSTYPE *yyvaluep; 833#endif 834{ 835 /* Pacify ``unused variable'' warnings. */ 836 (void) yyvaluep; 837 838 switch (yytype) 839 { 840 841 default: 842 break; 843 } 844} 845 846 847/* Prevent warnings from -Wmissing-prototypes. */ 848 849#ifdef YYPARSE_PARAM 850# if defined (__STDC__) || defined (__cplusplus) 851int yyparse (void *YYPARSE_PARAM); 852# else 853int yyparse (); 854# endif 855#else /* ! YYPARSE_PARAM */ 856#if defined (__STDC__) || defined (__cplusplus) 857int yyparse (void); 858#else 859int yyparse (); 860#endif 861#endif /* ! YYPARSE_PARAM */ 862 863 864 865/* The lookahead symbol. */ 866int yychar; 867 868/* The semantic value of the lookahead symbol. */ 869YYSTYPE yylval; 870 871/* Number of syntax errors so far. */ 872int yynerrs; 873 874 875 876/*----------. 877| yyparse. | 878`----------*/ 879 880#ifdef YYPARSE_PARAM 881# if defined (__STDC__) || defined (__cplusplus) 882int yyparse (void *YYPARSE_PARAM) 883# else 884int yyparse (YYPARSE_PARAM) 885 void *YYPARSE_PARAM; 886# endif 887#else /* ! YYPARSE_PARAM */ 888#if defined (__STDC__) || defined (__cplusplus) 889int 890yyparse (void) 891#else 892int 893yyparse () 894 895#endif 896#endif 897{ 898 899 register int yystate; 900 register int yyn; 901 int yyresult; 902 /* Number of tokens to shift before error messages enabled. */ 903 int yyerrstatus; 904 /* Lookahead token as an internal (translated) token number. */ 905 int yytoken = 0; 906 907 /* Three stacks and their tools: 908 `yyss': related to states, 909 `yyvs': related to semantic values, 910 `yyls': related to locations. 911 912 Refer to the stacks thru separate pointers, to allow yyoverflow 913 to reallocate them elsewhere. */ 914 915 /* The state stack. */ 916 short int yyssa[YYINITDEPTH]; 917 short int *yyss = yyssa; 918 register short int *yyssp; 919 920 /* The semantic value stack. */ 921 YYSTYPE yyvsa[YYINITDEPTH]; 922 YYSTYPE *yyvs = yyvsa; 923 register YYSTYPE *yyvsp; 924 925 926 927#define YYPOPSTACK (yyvsp--, yyssp--) 928 929 YYSIZE_T yystacksize = YYINITDEPTH; 930 931 /* The variables used to return semantic value and location from the 932 action routines. */ 933 YYSTYPE yyval; 934 935 936 /* When reducing, the number of symbols on the RHS of the reduced 937 rule. */ 938 int yylen; 939 940 YYDPRINTF ((stderr, "Starting parse\n")); 941 942 yystate = 0; 943 yyerrstatus = 0; 944 yynerrs = 0; 945 yychar = YYEMPTY; /* Cause a token to be read. */ 946 947 /* Initialize stack pointers. 948 Waste one element of value and location stack 949 so that they stay on the same level as the state stack. 950 The wasted elements are never initialized. */ 951 952 yyssp = yyss; 953 yyvsp = yyvs; 954 955 956 goto yysetstate; 957 958/*------------------------------------------------------------. 959| yynewstate -- Push a new state, which is found in yystate. | 960`------------------------------------------------------------*/ 961 yynewstate: 962 /* In all cases, when you get here, the value and location stacks 963 have just been pushed. so pushing a state here evens the stacks. 964 */ 965 yyssp++; 966 967 yysetstate: 968 *yyssp = yystate; 969 970 if (yyss + yystacksize - 1 <= yyssp) 971 { 972 /* Get the current used size of the three stacks, in elements. */ 973 YYSIZE_T yysize = yyssp - yyss + 1; 974 975#ifdef yyoverflow 976 { 977 /* Give user a chance to reallocate the stack. Use copies of 978 these so that the &'s don't force the real ones into 979 memory. */ 980 YYSTYPE *yyvs1 = yyvs; 981 short int *yyss1 = yyss; 982 983 984 /* Each stack pointer address is followed by the size of the 985 data in use in that stack, in bytes. This used to be a 986 conditional around just the two extra args, but that might 987 be undefined if yyoverflow is a macro. */ 988 yyoverflow ("parser stack overflow", 989 &yyss1, yysize * sizeof (*yyssp), 990 &yyvs1, yysize * sizeof (*yyvsp), 991 992 &yystacksize); 993 994 yyss = yyss1; 995 yyvs = yyvs1; 996 } 997#else /* no yyoverflow */ 998# ifndef YYSTACK_RELOCATE 999 goto yyoverflowlab; 1000# else 1001 /* Extend the stack our own way. */ 1002 if (YYMAXDEPTH <= yystacksize) 1003 goto yyoverflowlab; 1004 yystacksize *= 2; 1005 if (YYMAXDEPTH < yystacksize) 1006 yystacksize = YYMAXDEPTH; 1007 1008 { 1009 short int *yyss1 = yyss; 1010 union yyalloc *yyptr = 1011 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1012 if (! yyptr) 1013 goto yyoverflowlab; 1014 YYSTACK_RELOCATE (yyss); 1015 YYSTACK_RELOCATE (yyvs); 1016 1017# undef YYSTACK_RELOCATE 1018 if (yyss1 != yyssa) 1019 YYSTACK_FREE (yyss1); 1020 } 1021# endif 1022#endif /* no yyoverflow */ 1023 1024 yyssp = yyss + yysize - 1; 1025 yyvsp = yyvs + yysize - 1; 1026 1027 1028 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1029 (unsigned long int) yystacksize)); 1030 1031 if (yyss + yystacksize - 1 <= yyssp) 1032 YYABORT; 1033 } 1034 1035 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1036 1037 goto yybackup; 1038 1039/*-----------. 1040| yybackup. | 1041`-----------*/ 1042yybackup: 1043 1044/* Do appropriate processing given the current state. */ 1045/* Read a lookahead token if we need one and don't already have one. */ 1046/* yyresume: */ 1047 1048 /* First try to decide what to do without reference to lookahead token. */ 1049 1050 yyn = yypact[yystate]; 1051 if (yyn == YYPACT_NINF) 1052 goto yydefault; 1053 1054 /* Not known => get a lookahead token if don't already have one. */ 1055 1056 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ 1057 if (yychar == YYEMPTY) 1058 { 1059 YYDPRINTF ((stderr, "Reading a token: ")); 1060 yychar = YYLEX; 1061 } 1062 1063 if (yychar <= YYEOF) 1064 { 1065 yychar = yytoken = YYEOF; 1066 YYDPRINTF ((stderr, "Now at end of input.\n")); 1067 } 1068 else 1069 { 1070 yytoken = YYTRANSLATE (yychar); 1071 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); 1072 } 1073 1074 /* If the proper action on seeing token YYTOKEN is to reduce or to 1075 detect an error, take that action. */ 1076 yyn += yytoken; 1077 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1078 goto yydefault; 1079 yyn = yytable[yyn]; 1080 if (yyn <= 0) 1081 { 1082 if (yyn == 0 || yyn == YYTABLE_NINF) 1083 goto yyerrlab; 1084 yyn = -yyn; 1085 goto yyreduce; 1086 } 1087 1088 if (yyn == YYFINAL) 1089 YYACCEPT; 1090 1091 /* Shift the lookahead token. */ 1092 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); 1093 1094 /* Discard the token being shifted unless it is eof. */ 1095 if (yychar != YYEOF) 1096 yychar = YYEMPTY; 1097 1098 *++yyvsp = yylval; 1099 1100 1101 /* Count tokens shifted since error; after three, turn off error 1102 status. */ 1103 if (yyerrstatus) 1104 yyerrstatus--; 1105 1106 yystate = yyn; 1107 goto yynewstate; 1108 1109 1110/*-----------------------------------------------------------. 1111| yydefault -- do the default action for the current state. | 1112`-----------------------------------------------------------*/ 1113yydefault: 1114 yyn = yydefact[yystate]; 1115 if (yyn == 0) 1116 goto yyerrlab; 1117 goto yyreduce; 1118 1119 1120/*-----------------------------. 1121| yyreduce -- Do a reduction. | 1122`-----------------------------*/ 1123yyreduce: 1124 /* yyn is the number of a rule to reduce with. */ 1125 yylen = yyr2[yyn]; 1126 1127 /* If YYLEN is nonzero, implement the default value of the action: 1128 `$$ = $1'. 1129 1130 Otherwise, the following line sets YYVAL to garbage. 1131 This behavior is undocumented and Bison 1132 users should not rely upon it. Assigning to YYVAL 1133 unconditionally makes the parser a bit smaller, and it avoids a 1134 GCC warning that YYVAL may be used uninitialized. */ 1135 yyval = yyvsp[1-yylen]; 1136 1137 1138 YY_REDUCE_PRINT (yyn); 1139 switch (yyn) 1140 { 1141 case 2: 1142#line 76 "arith.y" 1143 { 1144 return (yyvsp[0]); 1145 ;} 1146 break; 1147 1148 case 3: 1149#line 82 "arith.y" 1150 { yyval = yyvsp[-1]; ;} 1151 break; 1152 1153 case 4: 1154#line 83 "arith.y" 1155 { yyval = yyvsp[-2] ? yyvsp[-2] : yyvsp[0] ? yyvsp[0] : 0; ;} 1156 break; 1157 1158 case 5: 1159#line 84 "arith.y" 1160 { yyval = yyvsp[-2] ? ( yyvsp[0] ? yyvsp[0] : 0 ) : 0; ;} 1161 break; 1162 1163 case 6: 1164#line 85 "arith.y" 1165 { yyval = yyvsp[-2] | yyvsp[0]; ;} 1166 break; 1167 1168 case 7: 1169#line 86 "arith.y" 1170 { yyval = yyvsp[-2] ^ yyvsp[0]; ;} 1171 break; 1172 1173 case 8: 1174#line 87 "arith.y" 1175 { yyval = yyvsp[-2] & yyvsp[0]; ;} 1176 break; 1177 1178 case 9: 1179#line 88 "arith.y" 1180 { yyval = yyvsp[-2] == yyvsp[0]; ;} 1181 break; 1182 1183 case 10: 1184#line 89 "arith.y" 1185 { yyval = yyvsp[-2] > yyvsp[0]; ;} 1186 break; 1187 1188 case 11: 1189#line 90 "arith.y" 1190 { yyval = yyvsp[-2] >= yyvsp[0]; ;} 1191 break; 1192 1193 case 12: 1194#line 91 "arith.y" 1195 { yyval = yyvsp[-2] < yyvsp[0]; ;} 1196 break; 1197 1198 case 13: 1199#line 92 "arith.y" 1200 { yyval = yyvsp[-2] <= yyvsp[0]; ;} 1201 break; 1202 1203 case 14: 1204#line 93 "arith.y" 1205 { yyval = yyvsp[-2] != yyvsp[0]; ;} 1206 break; 1207 1208 case 15: 1209#line 94 "arith.y" 1210 { yyval = yyvsp[-2] << yyvsp[0]; ;} 1211 break; 1212 1213 case 16: 1214#line 95 "arith.y" 1215 { yyval = yyvsp[-2] >> yyvsp[0]; ;} 1216 break; 1217 1218 case 17: 1219#line 96 "arith.y" 1220 { yyval = yyvsp[-2] + yyvsp[0]; ;} 1221 break; 1222 1223 case 18: 1224#line 97 "arith.y" 1225 { yyval = yyvsp[-2] - yyvsp[0]; ;} 1226 break; 1227 1228 case 19: 1229#line 98 "arith.y" 1230 { yyval = yyvsp[-2] * yyvsp[0]; ;} 1231 break; 1232 1233 case 20: 1234#line 99 "arith.y" 1235 { 1236 if (yyvsp[0] == 0) 1237 yyerror("division by zero"); 1238 yyval = yyvsp[-2] / yyvsp[0]; 1239 ;} 1240 break; 1241 1242 case 21: 1243#line 104 "arith.y" 1244 { 1245 if (yyvsp[0] == 0) 1246 yyerror("division by zero"); 1247 yyval = yyvsp[-2] % yyvsp[0]; 1248 ;} 1249 break; 1250 1251 case 22: 1252#line 109 "arith.y" 1253 { yyval = !(yyvsp[0]); ;} 1254 break; 1255 1256 case 23: 1257#line 110 "arith.y" 1258 { yyval = ~(yyvsp[0]); ;} 1259 break; 1260 1261 case 24: 1262#line 111 "arith.y" 1263 { yyval = -(yyvsp[0]); ;} 1264 break; 1265 1266 case 25: 1267#line 112 "arith.y" 1268 { yyval = yyvsp[0]; ;} 1269 break; 1270 1271 1272 } 1273 1274/* Line 1010 of yacc.c. */ 1275#line 1276 "arith.c" 1276 1277 yyvsp -= yylen; 1278 yyssp -= yylen; 1279 1280 1281 YY_STACK_PRINT (yyss, yyssp); 1282 1283 *++yyvsp = yyval; 1284 1285 1286 /* Now `shift' the result of the reduction. Determine what state 1287 that goes to, based on the state we popped back to and the rule 1288 number reduced by. */ 1289 1290 yyn = yyr1[yyn]; 1291 1292 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; 1293 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) 1294 yystate = yytable[yystate]; 1295 else 1296 yystate = yydefgoto[yyn - YYNTOKENS]; 1297 1298 goto yynewstate; 1299 1300 1301/*------------------------------------. 1302| yyerrlab -- here on detecting error | 1303`------------------------------------*/ 1304yyerrlab: 1305 /* If not already recovering from an error, report this error. */ 1306 if (!yyerrstatus) 1307 { 1308 ++yynerrs; 1309#if YYERROR_VERBOSE 1310 yyn = yypact[yystate]; 1311 1312 if (YYPACT_NINF < yyn && yyn < YYLAST) 1313 { 1314 YYSIZE_T yysize = 0; 1315 int yytype = YYTRANSLATE (yychar); 1316 const char* yyprefix; 1317 char *yymsg; 1318 int yyx; 1319 1320 /* Start YYX at -YYN if negative to avoid negative indexes in 1321 YYCHECK. */ 1322 int yyxbegin = yyn < 0 ? -yyn : 0; 1323 1324 /* Stay within bounds of both yycheck and yytname. */ 1325 int yychecklim = YYLAST - yyn; 1326 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 1327 int yycount = 0; 1328 1329 yyprefix = ", expecting "; 1330 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1331 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) 1332 { 1333 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); 1334 yycount += 1; 1335 if (yycount == 5) 1336 { 1337 yysize = 0; 1338 break; 1339 } 1340 } 1341 yysize += (sizeof ("syntax error, unexpected ") 1342 + yystrlen (yytname[yytype])); 1343 yymsg = (char *) YYSTACK_ALLOC (yysize); 1344 if (yymsg != 0) 1345 { 1346 char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); 1347 yyp = yystpcpy (yyp, yytname[yytype]); 1348 1349 if (yycount < 5) 1350 { 1351 yyprefix = ", expecting "; 1352 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1353 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) 1354 { 1355 yyp = yystpcpy (yyp, yyprefix); 1356 yyp = yystpcpy (yyp, yytname[yyx]); 1357 yyprefix = " or "; 1358 } 1359 } 1360 yyerror (yymsg); 1361 YYSTACK_FREE (yymsg); 1362 } 1363 else 1364 yyerror ("syntax error; also virtual memory exhausted"); 1365 } 1366 else 1367#endif /* YYERROR_VERBOSE */ 1368 yyerror ("syntax error"); 1369 } 1370 1371 1372 1373 if (yyerrstatus == 3) 1374 { 1375 /* If just tried and failed to reuse lookahead token after an 1376 error, discard it. */ 1377 1378 if (yychar <= YYEOF) 1379 { 1380 /* If at end of input, pop the error token, 1381 then the rest of the stack, then return failure. */ 1382 if (yychar == YYEOF) 1383 for (;;) 1384 { 1385 YYPOPSTACK; 1386 if (yyssp == yyss) 1387 YYABORT; 1388 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); 1389 yydestruct (yystos[*yyssp], yyvsp); 1390 } 1391 } 1392 else 1393 { 1394 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); 1395 yydestruct (yytoken, &yylval); 1396 yychar = YYEMPTY; 1397 1398 } 1399 } 1400 1401 /* Else will try to reuse lookahead token after shifting the error 1402 token. */ 1403 goto yyerrlab1; 1404 1405 1406/*---------------------------------------------------. 1407| yyerrorlab -- error raised explicitly by YYERROR. | 1408`---------------------------------------------------*/ 1409yyerrorlab: 1410 1411#ifdef __GNUC__ 1412 /* Pacify GCC when the user code never invokes YYERROR and the label 1413 yyerrorlab therefore never appears in user code. */ 1414 if (0) 1415 goto yyerrorlab; 1416#endif 1417 1418 yyvsp -= yylen; 1419 yyssp -= yylen; 1420 yystate = *yyssp; 1421 goto yyerrlab1; 1422 1423 1424/*-------------------------------------------------------------. 1425| yyerrlab1 -- common code for both syntax error and YYERROR. | 1426`-------------------------------------------------------------*/ 1427yyerrlab1: 1428 yyerrstatus = 3; /* Each real token shifted decrements this. */ 1429 1430 for (;;) 1431 { 1432 yyn = yypact[yystate]; 1433 if (yyn != YYPACT_NINF) 1434 { 1435 yyn += YYTERROR; 1436 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) 1437 { 1438 yyn = yytable[yyn]; 1439 if (0 < yyn) 1440 break; 1441 } 1442 } 1443 1444 /* Pop the current state because it cannot handle the error token. */ 1445 if (yyssp == yyss) 1446 YYABORT; 1447 1448 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); 1449 yydestruct (yystos[yystate], yyvsp); 1450 YYPOPSTACK; 1451 yystate = *yyssp; 1452 YY_STACK_PRINT (yyss, yyssp); 1453 } 1454 1455 if (yyn == YYFINAL) 1456 YYACCEPT; 1457 1458 YYDPRINTF ((stderr, "Shifting error token, ")); 1459 1460 *++yyvsp = yylval; 1461 1462 1463 yystate = yyn; 1464 goto yynewstate; 1465 1466 1467/*-------------------------------------. 1468| yyacceptlab -- YYACCEPT comes here. | 1469`-------------------------------------*/ 1470yyacceptlab: 1471 yyresult = 0; 1472 goto yyreturn; 1473 1474/*-----------------------------------. 1475| yyabortlab -- YYABORT comes here. | 1476`-----------------------------------*/ 1477yyabortlab: 1478 yyresult = 1; 1479 goto yyreturn; 1480 1481#ifndef yyoverflow 1482/*----------------------------------------------. 1483| yyoverflowlab -- parser overflow comes here. | 1484`----------------------------------------------*/ 1485yyoverflowlab: 1486 yyerror ("parser stack overflow"); 1487 yyresult = 2; 1488 /* Fall through. */ 1489#endif 1490 1491yyreturn: 1492#ifndef yyoverflow 1493 if (yyss != yyssa) 1494 YYSTACK_FREE (yyss); 1495#endif 1496 return yyresult; 1497} 1498 1499 1500#line 115 "arith.y" 1501 1502int 1503arith(s) 1504 const char *s; 1505{ 1506 long result; 1507 1508 arith_buf = arith_startbuf = s; 1509 1510 INTOFF; 1511 result = yyparse(); 1512 arith_lex_reset(); /* reprime lex */ 1513 INTON; 1514 1515 return (result); 1516} 1517 1518 1519/* 1520 * The exp(1) builtin. 1521 */ 1522int 1523expcmd(argc, argv) 1524 int argc; 1525 char **argv; 1526{ 1527 const char *p; 1528 char *concat; 1529 char **ap; 1530 long i; 1531 1532 if (argc > 1) { 1533 p = argv[1]; 1534 if (argc > 2) { 1535 /* 1536 * concatenate arguments 1537 */ 1538 STARTSTACKSTR(concat); 1539 ap = argv + 2; 1540 for (;;) { 1541 while (*p) 1542 STPUTC(*p++, concat); 1543 if ((p = *ap++) == NULL) 1544 break; 1545 STPUTC(' ', concat); 1546 } 1547 STPUTC('\0', concat); 1548 p = grabstackstr(concat); 1549 } 1550 } else 1551 p = ""; 1552 1553 i = arith(p); 1554 1555 out1fmt("%ld\n", i); 1556 return (! i); 1557} 1558 1559/*************************/ 1560#ifdef TEST_ARITH 1561#include <stdio.h> 1562main(argc, argv) 1563 char *argv[]; 1564{ 1565 printf("%d\n", exp(argv[1])); 1566} 1567error(s) 1568 char *s; 1569{ 1570 fprintf(stderr, "exp: %s\n", s); 1571 exit(1); 1572} 1573#endif 1574 1575void 1576yyerror(s) 1577 const char *s; 1578{ 1579 1580// yyerrok; 1581 yyclearin; 1582 arith_lex_reset(); /* reprime lex */ 1583 error("arithmetic expression: %s: \"%s\"", s, arith_startbuf); 1584 /* NOTREACHED */ 1585} 1586 1587 1588