gfx/angle/src/compiler/preprocessor/ExpressionParser.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* A Bison parser, made by GNU Bison 2.7. */
michael@0 2
michael@0 3 /* Bison implementation for Yacc-like parsers in C
michael@0 4
michael@0 5 Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
michael@0 6
michael@0 7 This program is free software: you can redistribute it and/or modify
michael@0 8 it under the terms of the GNU General Public License as published by
michael@0 9 the Free Software Foundation, either version 3 of the License, or
michael@0 10 (at your option) any later version.
michael@0 11
michael@0 12 This program is distributed in the hope that it will be useful,
michael@0 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
michael@0 15 GNU General Public License for more details.
michael@0 16
michael@0 17 You should have received a copy of the GNU General Public License
michael@0 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
michael@0 19
michael@0 20 /* As a special exception, you may create a larger work that contains
michael@0 21 part or all of the Bison parser skeleton and distribute that work
michael@0 22 under terms of your choice, so long as that work isn't itself a
michael@0 23 parser generator using the skeleton or a modified version thereof
michael@0 24 as a parser skeleton. Alternatively, if you modify or redistribute
michael@0 25 the parser skeleton itself, you may (at your option) remove this
michael@0 26 special exception, which will cause the skeleton and the resulting
michael@0 27 Bison output files to be licensed under the GNU General Public
michael@0 28 License without this special exception.
michael@0 29
michael@0 30 This special exception was added by the Free Software Foundation in
michael@0 31 version 2.2 of Bison. */
michael@0 32
michael@0 33 /* C LALR(1) parser skeleton written by Richard Stallman, by
michael@0 34 simplifying the original so-called "semantic" parser. */
michael@0 35
michael@0 36 /* All symbols defined below should begin with yy or YY, to avoid
michael@0 37 infringing on user name space. This should be done even for local
michael@0 38 variables, as they might otherwise be expanded by user macros.
michael@0 39 There are some unavoidable exceptions within include files to
michael@0 40 define necessary library symbols; they are noted "INFRINGES ON
michael@0 41 USER NAME SPACE" below. */
michael@0 42
michael@0 43 /* Identify Bison output. */
michael@0 44 #define YYBISON 1
michael@0 45
michael@0 46 /* Bison version. */
michael@0 47 #define YYBISON_VERSION "2.7"
michael@0 48
michael@0 49 /* Skeleton name. */
michael@0 50 #define YYSKELETON_NAME "yacc.c"
michael@0 51
michael@0 52 /* Pure parsers. */
michael@0 53 #define YYPURE 1
michael@0 54
michael@0 55 /* Push parsers. */
michael@0 56 #define YYPUSH 0
michael@0 57
michael@0 58 /* Pull parsers. */
michael@0 59 #define YYPULL 1
michael@0 60
michael@0 61
michael@0 62 /* Substitute the variable and function names. */
michael@0 63 #define yyparse ppparse
michael@0 64 #define yylex pplex
michael@0 65 #define yyerror pperror
michael@0 66 #define yylval pplval
michael@0 67 #define yychar ppchar
michael@0 68 #define yydebug ppdebug
michael@0 69 #define yynerrs ppnerrs
michael@0 70
michael@0 71 /* Copy the first part of user declarations. */
michael@0 72
michael@0 73
michael@0 74 //
michael@0 75 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
michael@0 76 // Use of this source code is governed by a BSD-style license that can be
michael@0 77 // found in the LICENSE file.
michael@0 78 //
michael@0 79
michael@0 80 // This file is auto-generated by generate_parser.sh. DO NOT EDIT!
michael@0 81
michael@0 82 #if defined(__GNUC__)
michael@0 83 // Triggered by the auto-generated pplval variable.
michael@0 84 #if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
michael@0 85 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
michael@0 86 #else
michael@0 87 #pragma GCC diagnostic ignored "-Wuninitialized"
michael@0 88 #endif
michael@0 89 #elif defined(_MSC_VER)
michael@0 90 #pragma warning(disable: 4065 4701)
michael@0 91 #endif
michael@0 92
michael@0 93 #include "ExpressionParser.h"
michael@0 94
michael@0 95 #include <cassert>
michael@0 96 #include <sstream>
michael@0 97
michael@0 98 #include "DiagnosticsBase.h"
michael@0 99 #include "Lexer.h"
michael@0 100 #include "Token.h"
michael@0 101
michael@0 102 #if defined(_MSC_VER)
michael@0 103 typedef __int64 YYSTYPE;
michael@0 104 #else
michael@0 105 #include <stdint.h>
michael@0 106 typedef intmax_t YYSTYPE;
michael@0 107 #endif // _MSC_VER
michael@0 108 #define YYENABLE_NLS 0
michael@0 109 #define YYLTYPE_IS_TRIVIAL 1
michael@0 110 #define YYSTYPE_IS_TRIVIAL 1
michael@0 111 #define YYSTYPE_IS_DECLARED 1
michael@0 112
michael@0 113 namespace {
michael@0 114 struct Context
michael@0 115 {
michael@0 116 pp::Diagnostics* diagnostics;
michael@0 117 pp::Lexer* lexer;
michael@0 118 pp::Token* token;
michael@0 119 int* result;
michael@0 120 };
michael@0 121 } // namespace
michael@0 122
michael@0 123
michael@0 124 static int yylex(YYSTYPE* lvalp, Context* context);
michael@0 125 static void yyerror(Context* context, const char* reason);
michael@0 126
michael@0 127
michael@0 128
michael@0 129 # ifndef YY_NULL
michael@0 130 # if defined __cplusplus && 201103L <= __cplusplus
michael@0 131 # define YY_NULL nullptr
michael@0 132 # else
michael@0 133 # define YY_NULL 0
michael@0 134 # endif
michael@0 135 # endif
michael@0 136
michael@0 137 /* Enabling verbose error messages. */
michael@0 138 #ifdef YYERROR_VERBOSE
michael@0 139 # undef YYERROR_VERBOSE
michael@0 140 # define YYERROR_VERBOSE 1
michael@0 141 #else
michael@0 142 # define YYERROR_VERBOSE 0
michael@0 143 #endif
michael@0 144
michael@0 145
michael@0 146 /* Enabling traces. */
michael@0 147 #ifndef YYDEBUG
michael@0 148 # define YYDEBUG 0
michael@0 149 #endif
michael@0 150 #if YYDEBUG
michael@0 151 extern int ppdebug;
michael@0 152 #endif
michael@0 153
michael@0 154 /* Tokens. */
michael@0 155 #ifndef YYTOKENTYPE
michael@0 156 # define YYTOKENTYPE
michael@0 157 /* Put the tokens into the symbol table, so that GDB and other debuggers
michael@0 158 know about them. */
michael@0 159 enum yytokentype {
michael@0 160 TOK_CONST_INT = 258,
michael@0 161 TOK_OP_OR = 259,
michael@0 162 TOK_OP_AND = 260,
michael@0 163 TOK_OP_NE = 261,
michael@0 164 TOK_OP_EQ = 262,
michael@0 165 TOK_OP_GE = 263,
michael@0 166 TOK_OP_LE = 264,
michael@0 167 TOK_OP_RIGHT = 265,
michael@0 168 TOK_OP_LEFT = 266,
michael@0 169 TOK_UNARY = 267
michael@0 170 };
michael@0 171 #endif
michael@0 172
michael@0 173
michael@0 174 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
michael@0 175 typedef int YYSTYPE;
michael@0 176 # define YYSTYPE_IS_TRIVIAL 1
michael@0 177 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
michael@0 178 # define YYSTYPE_IS_DECLARED 1
michael@0 179 #endif
michael@0 180
michael@0 181
michael@0 182 #ifdef YYPARSE_PARAM
michael@0 183 #if defined __STDC__ || defined __cplusplus
michael@0 184 int ppparse (void *YYPARSE_PARAM);
michael@0 185 #else
michael@0 186 int ppparse ();
michael@0 187 #endif
michael@0 188 #else /* ! YYPARSE_PARAM */
michael@0 189 #if defined __STDC__ || defined __cplusplus
michael@0 190 int ppparse (Context *context);
michael@0 191 #else
michael@0 192 int ppparse ();
michael@0 193 #endif
michael@0 194 #endif /* ! YYPARSE_PARAM */
michael@0 195
michael@0 196
michael@0 197
michael@0 198 /* Copy the second part of user declarations. */
michael@0 199
michael@0 200
michael@0 201
michael@0 202 #ifdef short
michael@0 203 # undef short
michael@0 204 #endif
michael@0 205
michael@0 206 #ifdef YYTYPE_UINT8
michael@0 207 typedef YYTYPE_UINT8 yytype_uint8;
michael@0 208 #else
michael@0 209 typedef unsigned char yytype_uint8;
michael@0 210 #endif
michael@0 211
michael@0 212 #ifdef YYTYPE_INT8
michael@0 213 typedef YYTYPE_INT8 yytype_int8;
michael@0 214 #elif (defined __STDC__ || defined __C99__FUNC__ \
michael@0 215 || defined __cplusplus || defined _MSC_VER)
michael@0 216 typedef signed char yytype_int8;
michael@0 217 #else
michael@0 218 typedef short int yytype_int8;
michael@0 219 #endif
michael@0 220
michael@0 221 #ifdef YYTYPE_UINT16
michael@0 222 typedef YYTYPE_UINT16 yytype_uint16;
michael@0 223 #else
michael@0 224 typedef unsigned short int yytype_uint16;
michael@0 225 #endif
michael@0 226
michael@0 227 #ifdef YYTYPE_INT16
michael@0 228 typedef YYTYPE_INT16 yytype_int16;
michael@0 229 #else
michael@0 230 typedef short int yytype_int16;
michael@0 231 #endif
michael@0 232
michael@0 233 #ifndef YYSIZE_T
michael@0 234 # ifdef __SIZE_TYPE__
michael@0 235 # define YYSIZE_T __SIZE_TYPE__
michael@0 236 # elif defined size_t
michael@0 237 # define YYSIZE_T size_t
michael@0 238 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
michael@0 239 || defined __cplusplus || defined _MSC_VER)
michael@0 240 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
michael@0 241 # define YYSIZE_T size_t
michael@0 242 # else
michael@0 243 # define YYSIZE_T unsigned int
michael@0 244 # endif
michael@0 245 #endif
michael@0 246
michael@0 247 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
michael@0 248
michael@0 249 #ifndef YY_
michael@0 250 # if defined YYENABLE_NLS && YYENABLE_NLS
michael@0 251 # if ENABLE_NLS
michael@0 252 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
michael@0 253 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
michael@0 254 # endif
michael@0 255 # endif
michael@0 256 # ifndef YY_
michael@0 257 # define YY_(Msgid) Msgid
michael@0 258 # endif
michael@0 259 #endif
michael@0 260
michael@0 261 /* Suppress unused-variable warnings by "using" E. */
michael@0 262 #if ! defined lint || defined __GNUC__
michael@0 263 # define YYUSE(E) ((void) (E))
michael@0 264 #else
michael@0 265 # define YYUSE(E) /* empty */
michael@0 266 #endif
michael@0 267
michael@0 268 /* Identity function, used to suppress warnings about constant conditions. */
michael@0 269 #ifndef lint
michael@0 270 # define YYID(N) (N)
michael@0 271 #else
michael@0 272 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 273 || defined __cplusplus || defined _MSC_VER)
michael@0 274 static int
michael@0 275 YYID (int yyi)
michael@0 276 #else
michael@0 277 static int
michael@0 278 YYID (yyi)
michael@0 279 int yyi;
michael@0 280 #endif
michael@0 281 {
michael@0 282 return yyi;
michael@0 283 }
michael@0 284 #endif
michael@0 285
michael@0 286 #if ! defined yyoverflow || YYERROR_VERBOSE
michael@0 287
michael@0 288 /* The parser invokes alloca or malloc; define the necessary symbols. */
michael@0 289
michael@0 290 # ifdef YYSTACK_USE_ALLOCA
michael@0 291 # if YYSTACK_USE_ALLOCA
michael@0 292 # ifdef __GNUC__
michael@0 293 # define YYSTACK_ALLOC __builtin_alloca
michael@0 294 # elif defined __BUILTIN_VA_ARG_INCR
michael@0 295 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
michael@0 296 # elif defined _AIX
michael@0 297 # define YYSTACK_ALLOC __alloca
michael@0 298 # elif defined _MSC_VER
michael@0 299 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
michael@0 300 # define alloca _alloca
michael@0 301 # else
michael@0 302 # define YYSTACK_ALLOC alloca
michael@0 303 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
michael@0 304 || defined __cplusplus || defined _MSC_VER)
michael@0 305 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
michael@0 306 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
michael@0 307 # ifndef EXIT_SUCCESS
michael@0 308 # define EXIT_SUCCESS 0
michael@0 309 # endif
michael@0 310 # endif
michael@0 311 # endif
michael@0 312 # endif
michael@0 313 # endif
michael@0 314
michael@0 315 # ifdef YYSTACK_ALLOC
michael@0 316 /* Pacify GCC's `empty if-body' warning. */
michael@0 317 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
michael@0 318 # ifndef YYSTACK_ALLOC_MAXIMUM
michael@0 319 /* The OS might guarantee only one guard page at the bottom of the stack,
michael@0 320 and a page size can be as small as 4096 bytes. So we cannot safely
michael@0 321 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
michael@0 322 to allow for a few compiler-allocated temporary stack slots. */
michael@0 323 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
michael@0 324 # endif
michael@0 325 # else
michael@0 326 # define YYSTACK_ALLOC YYMALLOC
michael@0 327 # define YYSTACK_FREE YYFREE
michael@0 328 # ifndef YYSTACK_ALLOC_MAXIMUM
michael@0 329 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
michael@0 330 # endif
michael@0 331 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
michael@0 332 && ! ((defined YYMALLOC || defined malloc) \
michael@0 333 && (defined YYFREE || defined free)))
michael@0 334 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
michael@0 335 # ifndef EXIT_SUCCESS
michael@0 336 # define EXIT_SUCCESS 0
michael@0 337 # endif
michael@0 338 # endif
michael@0 339 # ifndef YYMALLOC
michael@0 340 # define YYMALLOC malloc
michael@0 341 # if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
michael@0 342 || defined __cplusplus || defined _MSC_VER)
michael@0 343 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
michael@0 344 # endif
michael@0 345 # endif
michael@0 346 # ifndef YYFREE
michael@0 347 # define YYFREE free
michael@0 348 # if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
michael@0 349 || defined __cplusplus || defined _MSC_VER)
michael@0 350 void free (void *); /* INFRINGES ON USER NAME SPACE */
michael@0 351 # endif
michael@0 352 # endif
michael@0 353 # endif
michael@0 354 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
michael@0 355
michael@0 356
michael@0 357 #if (! defined yyoverflow \
michael@0 358 && (! defined __cplusplus \
michael@0 359 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
michael@0 360
michael@0 361 /* A type that is properly aligned for any stack member. */
michael@0 362 union yyalloc
michael@0 363 {
michael@0 364 yytype_int16 yyss_alloc;
michael@0 365 YYSTYPE yyvs_alloc;
michael@0 366 };
michael@0 367
michael@0 368 /* The size of the maximum gap between one aligned stack and the next. */
michael@0 369 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
michael@0 370
michael@0 371 /* The size of an array large to enough to hold all stacks, each with
michael@0 372 N elements. */
michael@0 373 # define YYSTACK_BYTES(N) \
michael@0 374 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
michael@0 375 + YYSTACK_GAP_MAXIMUM)
michael@0 376
michael@0 377 # define YYCOPY_NEEDED 1
michael@0 378
michael@0 379 /* Relocate STACK from its old location to the new one. The
michael@0 380 local variables YYSIZE and YYSTACKSIZE give the old and new number of
michael@0 381 elements in the stack, and YYPTR gives the new location of the
michael@0 382 stack. Advance YYPTR to a properly aligned location for the next
michael@0 383 stack. */
michael@0 384 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
michael@0 385 do \
michael@0 386 { \
michael@0 387 YYSIZE_T yynewbytes; \
michael@0 388 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
michael@0 389 Stack = &yyptr->Stack_alloc; \
michael@0 390 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
michael@0 391 yyptr += yynewbytes / sizeof (*yyptr); \
michael@0 392 } \
michael@0 393 while (YYID (0))
michael@0 394
michael@0 395 #endif
michael@0 396
michael@0 397 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
michael@0 398 /* Copy COUNT objects from SRC to DST. The source and destination do
michael@0 399 not overlap. */
michael@0 400 # ifndef YYCOPY
michael@0 401 # if defined __GNUC__ && 1 < __GNUC__
michael@0 402 # define YYCOPY(Dst, Src, Count) \
michael@0 403 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
michael@0 404 # else
michael@0 405 # define YYCOPY(Dst, Src, Count) \
michael@0 406 do \
michael@0 407 { \
michael@0 408 YYSIZE_T yyi; \
michael@0 409 for (yyi = 0; yyi < (Count); yyi++) \
michael@0 410 (Dst)[yyi] = (Src)[yyi]; \
michael@0 411 } \
michael@0 412 while (YYID (0))
michael@0 413 # endif
michael@0 414 # endif
michael@0 415 #endif /* !YYCOPY_NEEDED */
michael@0 416
michael@0 417 /* YYFINAL -- State number of the termination state. */
michael@0 418 #define YYFINAL 14
michael@0 419 /* YYLAST -- Last index in YYTABLE. */
michael@0 420 #define YYLAST 175
michael@0 421
michael@0 422 /* YYNTOKENS -- Number of terminals. */
michael@0 423 #define YYNTOKENS 27
michael@0 424 /* YYNNTS -- Number of nonterminals. */
michael@0 425 #define YYNNTS 3
michael@0 426 /* YYNRULES -- Number of rules. */
michael@0 427 #define YYNRULES 26
michael@0 428 /* YYNRULES -- Number of states. */
michael@0 429 #define YYNSTATES 52
michael@0 430
michael@0 431 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
michael@0 432 #define YYUNDEFTOK 2
michael@0 433 #define YYMAXUTOK 267
michael@0 434
michael@0 435 #define YYTRANSLATE(YYX) \
michael@0 436 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
michael@0 437
michael@0 438 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
michael@0 439 static const yytype_uint8 yytranslate[] =
michael@0 440 {
michael@0 441 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 442 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 443 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 444 2, 2, 2, 23, 2, 2, 2, 21, 8, 2,
michael@0 445 25, 26, 19, 17, 2, 18, 2, 20, 2, 2,
michael@0 446 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 447 11, 2, 12, 2, 2, 2, 2, 2, 2, 2,
michael@0 448 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 449 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 450 2, 2, 2, 2, 7, 2, 2, 2, 2, 2,
michael@0 451 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 452 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 453 2, 2, 2, 2, 6, 2, 24, 2, 2, 2,
michael@0 454 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 455 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 456 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 457 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 458 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 459 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 460 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 461 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 462 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 463 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 464 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 465 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
michael@0 466 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
michael@0 467 5, 9, 10, 13, 14, 15, 16, 22
michael@0 468 };
michael@0 469
michael@0 470 #if YYDEBUG
michael@0 471 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
michael@0 472 YYRHS. */
michael@0 473 static const yytype_uint8 yyprhs[] =
michael@0 474 {
michael@0 475 0, 0, 3, 5, 7, 11, 15, 19, 23, 27,
michael@0 476 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
michael@0 477 71, 75, 79, 82, 85, 88, 91
michael@0 478 };
michael@0 479
michael@0 480 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
michael@0 481 static const yytype_int8 yyrhs[] =
michael@0 482 {
michael@0 483 28, 0, -1, 29, -1, 3, -1, 29, 4, 29,
michael@0 484 -1, 29, 5, 29, -1, 29, 6, 29, -1, 29,
michael@0 485 7, 29, -1, 29, 8, 29, -1, 29, 9, 29,
michael@0 486 -1, 29, 10, 29, -1, 29, 13, 29, -1, 29,
michael@0 487 14, 29, -1, 29, 12, 29, -1, 29, 11, 29,
michael@0 488 -1, 29, 15, 29, -1, 29, 16, 29, -1, 29,
michael@0 489 18, 29, -1, 29, 17, 29, -1, 29, 21, 29,
michael@0 490 -1, 29, 20, 29, -1, 29, 19, 29, -1, 23,
michael@0 491 29, -1, 24, 29, -1, 18, 29, -1, 17, 29,
michael@0 492 -1, 25, 29, 26, -1
michael@0 493 };
michael@0 494
michael@0 495 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
michael@0 496 static const yytype_uint8 yyrline[] =
michael@0 497 {
michael@0 498 0, 91, 91, 98, 99, 102, 105, 108, 111, 114,
michael@0 499 117, 120, 123, 126, 129, 132, 135, 138, 141, 144,
michael@0 500 157, 170, 173, 176, 179, 182, 185
michael@0 501 };
michael@0 502 #endif
michael@0 503
michael@0 504 #if YYDEBUG || YYERROR_VERBOSE || 0
michael@0 505 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
michael@0 506 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
michael@0 507 static const char *const yytname[] =
michael@0 508 {
michael@0 509 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_OP_OR",
michael@0 510 "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_NE", "TOK_OP_EQ", "'<'",
michael@0 511 "'>'", "TOK_OP_GE", "TOK_OP_LE", "TOK_OP_RIGHT", "TOK_OP_LEFT", "'+'",
michael@0 512 "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('", "')'",
michael@0 513 "$accept", "input", "expression", YY_NULL
michael@0 514 };
michael@0 515 #endif
michael@0 516
michael@0 517 # ifdef YYPRINT
michael@0 518 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
michael@0 519 token YYLEX-NUM. */
michael@0 520 static const yytype_uint16 yytoknum[] =
michael@0 521 {
michael@0 522 0, 256, 257, 258, 259, 260, 124, 94, 38, 261,
michael@0 523 262, 60, 62, 263, 264, 265, 266, 43, 45, 42,
michael@0 524 47, 37, 267, 33, 126, 40, 41
michael@0 525 };
michael@0 526 # endif
michael@0 527
michael@0 528 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
michael@0 529 static const yytype_uint8 yyr1[] =
michael@0 530 {
michael@0 531 0, 27, 28, 29, 29, 29, 29, 29, 29, 29,
michael@0 532 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
michael@0 533 29, 29, 29, 29, 29, 29, 29
michael@0 534 };
michael@0 535
michael@0 536 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
michael@0 537 static const yytype_uint8 yyr2[] =
michael@0 538 {
michael@0 539 0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
michael@0 540 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
michael@0 541 3, 3, 2, 2, 2, 2, 3
michael@0 542 };
michael@0 543
michael@0 544 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
michael@0 545 Performed when YYTABLE doesn't specify something else to do. Zero
michael@0 546 means the default is an error. */
michael@0 547 static const yytype_uint8 yydefact[] =
michael@0 548 {
michael@0 549 0, 3, 0, 0, 0, 0, 0, 0, 2, 25,
michael@0 550 24, 22, 23, 0, 1, 0, 0, 0, 0, 0,
michael@0 551 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
michael@0 552 0, 0, 0, 26, 4, 5, 6, 7, 8, 9,
michael@0 553 10, 14, 13, 11, 12, 15, 16, 18, 17, 21,
michael@0 554 20, 19
michael@0 555 };
michael@0 556
michael@0 557 /* YYDEFGOTO[NTERM-NUM]. */
michael@0 558 static const yytype_int8 yydefgoto[] =
michael@0 559 {
michael@0 560 -1, 7, 8
michael@0 561 };
michael@0 562
michael@0 563 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
michael@0 564 STATE-NUM. */
michael@0 565 #define YYPACT_NINF -11
michael@0 566 static const yytype_int16 yypact[] =
michael@0 567 {
michael@0 568 46, -11, 46, 46, 46, 46, 46, 12, 68, -11,
michael@0 569 -11, -11, -11, 27, -11, 46, 46, 46, 46, 46,
michael@0 570 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
michael@0 571 46, 46, 46, -11, 85, 101, 116, 130, 143, 154,
michael@0 572 154, -10, -10, -10, -10, 37, 37, 31, 31, -11,
michael@0 573 -11, -11
michael@0 574 };
michael@0 575
michael@0 576 /* YYPGOTO[NTERM-NUM]. */
michael@0 577 static const yytype_int8 yypgoto[] =
michael@0 578 {
michael@0 579 -11, -11, -2
michael@0 580 };
michael@0 581
michael@0 582 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
michael@0 583 positive, shift that token. If negative, reduce the rule which
michael@0 584 number is the opposite. If YYTABLE_NINF, syntax error. */
michael@0 585 #define YYTABLE_NINF -1
michael@0 586 static const yytype_uint8 yytable[] =
michael@0 587 {
michael@0 588 9, 10, 11, 12, 13, 26, 27, 28, 29, 30,
michael@0 589 31, 32, 14, 34, 35, 36, 37, 38, 39, 40,
michael@0 590 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
michael@0 591 51, 15, 16, 17, 18, 19, 20, 21, 22, 23,
michael@0 592 24, 25, 26, 27, 28, 29, 30, 31, 32, 1,
michael@0 593 30, 31, 32, 33, 28, 29, 30, 31, 32, 0,
michael@0 594 0, 0, 0, 2, 3, 0, 0, 0, 0, 4,
michael@0 595 5, 6, 15, 16, 17, 18, 19, 20, 21, 22,
michael@0 596 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
michael@0 597 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
michael@0 598 26, 27, 28, 29, 30, 31, 32, 17, 18, 19,
michael@0 599 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
michael@0 600 30, 31, 32, 18, 19, 20, 21, 22, 23, 24,
michael@0 601 25, 26, 27, 28, 29, 30, 31, 32, 19, 20,
michael@0 602 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
michael@0 603 31, 32, 20, 21, 22, 23, 24, 25, 26, 27,
michael@0 604 28, 29, 30, 31, 32, 22, 23, 24, 25, 26,
michael@0 605 27, 28, 29, 30, 31, 32
michael@0 606 };
michael@0 607
michael@0 608 #define yypact_value_is_default(Yystate) \
michael@0 609 (!!((Yystate) == (-11)))
michael@0 610
michael@0 611 #define yytable_value_is_error(Yytable_value) \
michael@0 612 YYID (0)
michael@0 613
michael@0 614 static const yytype_int8 yycheck[] =
michael@0 615 {
michael@0 616 2, 3, 4, 5, 6, 15, 16, 17, 18, 19,
michael@0 617 20, 21, 0, 15, 16, 17, 18, 19, 20, 21,
michael@0 618 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
michael@0 619 32, 4, 5, 6, 7, 8, 9, 10, 11, 12,
michael@0 620 13, 14, 15, 16, 17, 18, 19, 20, 21, 3,
michael@0 621 19, 20, 21, 26, 17, 18, 19, 20, 21, -1,
michael@0 622 -1, -1, -1, 17, 18, -1, -1, -1, -1, 23,
michael@0 623 24, 25, 4, 5, 6, 7, 8, 9, 10, 11,
michael@0 624 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
michael@0 625 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 626 15, 16, 17, 18, 19, 20, 21, 6, 7, 8,
michael@0 627 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
michael@0 628 19, 20, 21, 7, 8, 9, 10, 11, 12, 13,
michael@0 629 14, 15, 16, 17, 18, 19, 20, 21, 8, 9,
michael@0 630 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
michael@0 631 20, 21, 9, 10, 11, 12, 13, 14, 15, 16,
michael@0 632 17, 18, 19, 20, 21, 11, 12, 13, 14, 15,
michael@0 633 16, 17, 18, 19, 20, 21
michael@0 634 };
michael@0 635
michael@0 636 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
michael@0 637 symbol of state STATE-NUM. */
michael@0 638 static const yytype_uint8 yystos[] =
michael@0 639 {
michael@0 640 0, 3, 17, 18, 23, 24, 25, 28, 29, 29,
michael@0 641 29, 29, 29, 29, 0, 4, 5, 6, 7, 8,
michael@0 642 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
michael@0 643 19, 20, 21, 26, 29, 29, 29, 29, 29, 29,
michael@0 644 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
michael@0 645 29, 29
michael@0 646 };
michael@0 647
michael@0 648 #define yyerrok (yyerrstatus = 0)
michael@0 649 #define yyclearin (yychar = YYEMPTY)
michael@0 650 #define YYEMPTY (-2)
michael@0 651 #define YYEOF 0
michael@0 652
michael@0 653 #define YYACCEPT goto yyacceptlab
michael@0 654 #define YYABORT goto yyabortlab
michael@0 655 #define YYERROR goto yyerrorlab
michael@0 656
michael@0 657
michael@0 658 /* Like YYERROR except do call yyerror. This remains here temporarily
michael@0 659 to ease the transition to the new meaning of YYERROR, for GCC.
michael@0 660 Once GCC version 2 has supplanted version 1, this can go. However,
michael@0 661 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
michael@0 662 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
michael@0 663 discussed. */
michael@0 664
michael@0 665 #define YYFAIL goto yyerrlab
michael@0 666 #if defined YYFAIL
michael@0 667 /* This is here to suppress warnings from the GCC cpp's
michael@0 668 -Wunused-macros. Normally we don't worry about that warning, but
michael@0 669 some users do, and we want to make it easy for users to remove
michael@0 670 YYFAIL uses, which will produce warnings from Bison 2.5. */
michael@0 671 #endif
michael@0 672
michael@0 673 #define YYRECOVERING() (!!yyerrstatus)
michael@0 674
michael@0 675 #define YYBACKUP(Token, Value) \
michael@0 676 do \
michael@0 677 if (yychar == YYEMPTY) \
michael@0 678 { \
michael@0 679 yychar = (Token); \
michael@0 680 yylval = (Value); \
michael@0 681 YYPOPSTACK (yylen); \
michael@0 682 yystate = *yyssp; \
michael@0 683 goto yybackup; \
michael@0 684 } \
michael@0 685 else \
michael@0 686 { \
michael@0 687 yyerror (context, YY_("syntax error: cannot back up")); \
michael@0 688 YYERROR; \
michael@0 689 } \
michael@0 690 while (YYID (0))
michael@0 691
michael@0 692 /* Error token number */
michael@0 693 #define YYTERROR 1
michael@0 694 #define YYERRCODE 256
michael@0 695
michael@0 696
michael@0 697 /* This macro is provided for backward compatibility. */
michael@0 698 #ifndef YY_LOCATION_PRINT
michael@0 699 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
michael@0 700 #endif
michael@0 701
michael@0 702
michael@0 703 /* YYLEX -- calling `yylex' with the right arguments. */
michael@0 704 #ifdef YYLEX_PARAM
michael@0 705 # define YYLEX yylex (&yylval, YYLEX_PARAM)
michael@0 706 #else
michael@0 707 # define YYLEX yylex (&yylval, context)
michael@0 708 #endif
michael@0 709
michael@0 710 /* Enable debugging if requested. */
michael@0 711 #if YYDEBUG
michael@0 712
michael@0 713 # ifndef YYFPRINTF
michael@0 714 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
michael@0 715 # define YYFPRINTF fprintf
michael@0 716 # endif
michael@0 717
michael@0 718 # define YYDPRINTF(Args) \
michael@0 719 do { \
michael@0 720 if (yydebug) \
michael@0 721 YYFPRINTF Args; \
michael@0 722 } while (YYID (0))
michael@0 723
michael@0 724 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
michael@0 725 do { \
michael@0 726 if (yydebug) \
michael@0 727 { \
michael@0 728 YYFPRINTF (stderr, "%s ", Title); \
michael@0 729 yy_symbol_print (stderr, \
michael@0 730 Type, Value, context); \
michael@0 731 YYFPRINTF (stderr, "\n"); \
michael@0 732 } \
michael@0 733 } while (YYID (0))
michael@0 734
michael@0 735
michael@0 736 /*--------------------------------.
michael@0 737 | Print this symbol on YYOUTPUT. |
michael@0 738 `--------------------------------*/
michael@0 739
michael@0 740 /*ARGSUSED*/
michael@0 741 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 742 || defined __cplusplus || defined _MSC_VER)
michael@0 743 static void
michael@0 744 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
michael@0 745 #else
michael@0 746 static void
michael@0 747 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context)
michael@0 748 FILE *yyoutput;
michael@0 749 int yytype;
michael@0 750 YYSTYPE const * const yyvaluep;
michael@0 751 Context *context;
michael@0 752 #endif
michael@0 753 {
michael@0 754 FILE *yyo = yyoutput;
michael@0 755 YYUSE (yyo);
michael@0 756 if (!yyvaluep)
michael@0 757 return;
michael@0 758 YYUSE (context);
michael@0 759 # ifdef YYPRINT
michael@0 760 if (yytype < YYNTOKENS)
michael@0 761 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
michael@0 762 # else
michael@0 763 YYUSE (yyoutput);
michael@0 764 # endif
michael@0 765 switch (yytype)
michael@0 766 {
michael@0 767 default:
michael@0 768 break;
michael@0 769 }
michael@0 770 }
michael@0 771
michael@0 772
michael@0 773 /*--------------------------------.
michael@0 774 | Print this symbol on YYOUTPUT. |
michael@0 775 `--------------------------------*/
michael@0 776
michael@0 777 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 778 || defined __cplusplus || defined _MSC_VER)
michael@0 779 static void
michael@0 780 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
michael@0 781 #else
michael@0 782 static void
michael@0 783 yy_symbol_print (yyoutput, yytype, yyvaluep, context)
michael@0 784 FILE *yyoutput;
michael@0 785 int yytype;
michael@0 786 YYSTYPE const * const yyvaluep;
michael@0 787 Context *context;
michael@0 788 #endif
michael@0 789 {
michael@0 790 if (yytype < YYNTOKENS)
michael@0 791 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
michael@0 792 else
michael@0 793 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
michael@0 794
michael@0 795 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
michael@0 796 YYFPRINTF (yyoutput, ")");
michael@0 797 }
michael@0 798
michael@0 799 /*------------------------------------------------------------------.
michael@0 800 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
michael@0 801 | TOP (included). |
michael@0 802 `------------------------------------------------------------------*/
michael@0 803
michael@0 804 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 805 || defined __cplusplus || defined _MSC_VER)
michael@0 806 static void
michael@0 807 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
michael@0 808 #else
michael@0 809 static void
michael@0 810 yy_stack_print (yybottom, yytop)
michael@0 811 yytype_int16 *yybottom;
michael@0 812 yytype_int16 *yytop;
michael@0 813 #endif
michael@0 814 {
michael@0 815 YYFPRINTF (stderr, "Stack now");
michael@0 816 for (; yybottom <= yytop; yybottom++)
michael@0 817 {
michael@0 818 int yybot = *yybottom;
michael@0 819 YYFPRINTF (stderr, " %d", yybot);
michael@0 820 }
michael@0 821 YYFPRINTF (stderr, "\n");
michael@0 822 }
michael@0 823
michael@0 824 # define YY_STACK_PRINT(Bottom, Top) \
michael@0 825 do { \
michael@0 826 if (yydebug) \
michael@0 827 yy_stack_print ((Bottom), (Top)); \
michael@0 828 } while (YYID (0))
michael@0 829
michael@0 830
michael@0 831 /*------------------------------------------------.
michael@0 832 | Report that the YYRULE is going to be reduced. |
michael@0 833 `------------------------------------------------*/
michael@0 834
michael@0 835 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 836 || defined __cplusplus || defined _MSC_VER)
michael@0 837 static void
michael@0 838 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, Context *context)
michael@0 839 #else
michael@0 840 static void
michael@0 841 yy_reduce_print (yyvsp, yyrule, context)
michael@0 842 YYSTYPE *yyvsp;
michael@0 843 int yyrule;
michael@0 844 Context *context;
michael@0 845 #endif
michael@0 846 {
michael@0 847 int yynrhs = yyr2[yyrule];
michael@0 848 int yyi;
michael@0 849 unsigned long int yylno = yyrline[yyrule];
michael@0 850 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
michael@0 851 yyrule - 1, yylno);
michael@0 852 /* The symbols being reduced. */
michael@0 853 for (yyi = 0; yyi < yynrhs; yyi++)
michael@0 854 {
michael@0 855 YYFPRINTF (stderr, " $%d = ", yyi + 1);
michael@0 856 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
michael@0 857 &(yyvsp[(yyi + 1) - (yynrhs)])
michael@0 858 , context);
michael@0 859 YYFPRINTF (stderr, "\n");
michael@0 860 }
michael@0 861 }
michael@0 862
michael@0 863 # define YY_REDUCE_PRINT(Rule) \
michael@0 864 do { \
michael@0 865 if (yydebug) \
michael@0 866 yy_reduce_print (yyvsp, Rule, context); \
michael@0 867 } while (YYID (0))
michael@0 868
michael@0 869 /* Nonzero means print parse trace. It is left uninitialized so that
michael@0 870 multiple parsers can coexist. */
michael@0 871 int yydebug;
michael@0 872 #else /* !YYDEBUG */
michael@0 873 # define YYDPRINTF(Args)
michael@0 874 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
michael@0 875 # define YY_STACK_PRINT(Bottom, Top)
michael@0 876 # define YY_REDUCE_PRINT(Rule)
michael@0 877 #endif /* !YYDEBUG */
michael@0 878
michael@0 879
michael@0 880 /* YYINITDEPTH -- initial size of the parser's stacks. */
michael@0 881 #ifndef YYINITDEPTH
michael@0 882 # define YYINITDEPTH 200
michael@0 883 #endif
michael@0 884
michael@0 885 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
michael@0 886 if the built-in stack extension method is used).
michael@0 887
michael@0 888 Do not make this value too large; the results are undefined if
michael@0 889 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
michael@0 890 evaluated with infinite-precision integer arithmetic. */
michael@0 891
michael@0 892 #ifndef YYMAXDEPTH
michael@0 893 # define YYMAXDEPTH 10000
michael@0 894 #endif
michael@0 895
michael@0 896
michael@0 897 #if YYERROR_VERBOSE
michael@0 898
michael@0 899 # ifndef yystrlen
michael@0 900 # if defined __GLIBC__ && defined _STRING_H
michael@0 901 # define yystrlen strlen
michael@0 902 # else
michael@0 903 /* Return the length of YYSTR. */
michael@0 904 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 905 || defined __cplusplus || defined _MSC_VER)
michael@0 906 static YYSIZE_T
michael@0 907 yystrlen (const char *yystr)
michael@0 908 #else
michael@0 909 static YYSIZE_T
michael@0 910 yystrlen (yystr)
michael@0 911 const char *yystr;
michael@0 912 #endif
michael@0 913 {
michael@0 914 YYSIZE_T yylen;
michael@0 915 for (yylen = 0; yystr[yylen]; yylen++)
michael@0 916 continue;
michael@0 917 return yylen;
michael@0 918 }
michael@0 919 # endif
michael@0 920 # endif
michael@0 921
michael@0 922 # ifndef yystpcpy
michael@0 923 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
michael@0 924 # define yystpcpy stpcpy
michael@0 925 # else
michael@0 926 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
michael@0 927 YYDEST. */
michael@0 928 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 929 || defined __cplusplus || defined _MSC_VER)
michael@0 930 static char *
michael@0 931 yystpcpy (char *yydest, const char *yysrc)
michael@0 932 #else
michael@0 933 static char *
michael@0 934 yystpcpy (yydest, yysrc)
michael@0 935 char *yydest;
michael@0 936 const char *yysrc;
michael@0 937 #endif
michael@0 938 {
michael@0 939 char *yyd = yydest;
michael@0 940 const char *yys = yysrc;
michael@0 941
michael@0 942 while ((*yyd++ = *yys++) != '\0')
michael@0 943 continue;
michael@0 944
michael@0 945 return yyd - 1;
michael@0 946 }
michael@0 947 # endif
michael@0 948 # endif
michael@0 949
michael@0 950 # ifndef yytnamerr
michael@0 951 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
michael@0 952 quotes and backslashes, so that it's suitable for yyerror. The
michael@0 953 heuristic is that double-quoting is unnecessary unless the string
michael@0 954 contains an apostrophe, a comma, or backslash (other than
michael@0 955 backslash-backslash). YYSTR is taken from yytname. If YYRES is
michael@0 956 null, do not copy; instead, return the length of what the result
michael@0 957 would have been. */
michael@0 958 static YYSIZE_T
michael@0 959 yytnamerr (char *yyres, const char *yystr)
michael@0 960 {
michael@0 961 if (*yystr == '"')
michael@0 962 {
michael@0 963 YYSIZE_T yyn = 0;
michael@0 964 char const *yyp = yystr;
michael@0 965
michael@0 966 for (;;)
michael@0 967 switch (*++yyp)
michael@0 968 {
michael@0 969 case '\'':
michael@0 970 case ',':
michael@0 971 goto do_not_strip_quotes;
michael@0 972
michael@0 973 case '\\':
michael@0 974 if (*++yyp != '\\')
michael@0 975 goto do_not_strip_quotes;
michael@0 976 /* Fall through. */
michael@0 977 default:
michael@0 978 if (yyres)
michael@0 979 yyres[yyn] = *yyp;
michael@0 980 yyn++;
michael@0 981 break;
michael@0 982
michael@0 983 case '"':
michael@0 984 if (yyres)
michael@0 985 yyres[yyn] = '\0';
michael@0 986 return yyn;
michael@0 987 }
michael@0 988 do_not_strip_quotes: ;
michael@0 989 }
michael@0 990
michael@0 991 if (! yyres)
michael@0 992 return yystrlen (yystr);
michael@0 993
michael@0 994 return yystpcpy (yyres, yystr) - yyres;
michael@0 995 }
michael@0 996 # endif
michael@0 997
michael@0 998 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
michael@0 999 about the unexpected token YYTOKEN for the state stack whose top is
michael@0 1000 YYSSP.
michael@0 1001
michael@0 1002 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
michael@0 1003 not large enough to hold the message. In that case, also set
michael@0 1004 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
michael@0 1005 required number of bytes is too large to store. */
michael@0 1006 static int
michael@0 1007 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
michael@0 1008 yytype_int16 *yyssp, int yytoken)
michael@0 1009 {
michael@0 1010 YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
michael@0 1011 YYSIZE_T yysize = yysize0;
michael@0 1012 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
michael@0 1013 /* Internationalized format string. */
michael@0 1014 const char *yyformat = YY_NULL;
michael@0 1015 /* Arguments of yyformat. */
michael@0 1016 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
michael@0 1017 /* Number of reported tokens (one for the "unexpected", one per
michael@0 1018 "expected"). */
michael@0 1019 int yycount = 0;
michael@0 1020
michael@0 1021 /* There are many possibilities here to consider:
michael@0 1022 - Assume YYFAIL is not used. It's too flawed to consider. See
michael@0 1023 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
michael@0 1024 for details. YYERROR is fine as it does not invoke this
michael@0 1025 function.
michael@0 1026 - If this state is a consistent state with a default action, then
michael@0 1027 the only way this function was invoked is if the default action
michael@0 1028 is an error action. In that case, don't check for expected
michael@0 1029 tokens because there are none.
michael@0 1030 - The only way there can be no lookahead present (in yychar) is if
michael@0 1031 this state is a consistent state with a default action. Thus,
michael@0 1032 detecting the absence of a lookahead is sufficient to determine
michael@0 1033 that there is no unexpected or expected token to report. In that
michael@0 1034 case, just report a simple "syntax error".
michael@0 1035 - Don't assume there isn't a lookahead just because this state is a
michael@0 1036 consistent state with a default action. There might have been a
michael@0 1037 previous inconsistent state, consistent state with a non-default
michael@0 1038 action, or user semantic action that manipulated yychar.
michael@0 1039 - Of course, the expected token list depends on states to have
michael@0 1040 correct lookahead information, and it depends on the parser not
michael@0 1041 to perform extra reductions after fetching a lookahead from the
michael@0 1042 scanner and before detecting a syntax error. Thus, state merging
michael@0 1043 (from LALR or IELR) and default reductions corrupt the expected
michael@0 1044 token list. However, the list is correct for canonical LR with
michael@0 1045 one exception: it will still contain any token that will not be
michael@0 1046 accepted due to an error action in a later state.
michael@0 1047 */
michael@0 1048 if (yytoken != YYEMPTY)
michael@0 1049 {
michael@0 1050 int yyn = yypact[*yyssp];
michael@0 1051 yyarg[yycount++] = yytname[yytoken];
michael@0 1052 if (!yypact_value_is_default (yyn))
michael@0 1053 {
michael@0 1054 /* Start YYX at -YYN if negative to avoid negative indexes in
michael@0 1055 YYCHECK. In other words, skip the first -YYN actions for
michael@0 1056 this state because they are default actions. */
michael@0 1057 int yyxbegin = yyn < 0 ? -yyn : 0;
michael@0 1058 /* Stay within bounds of both yycheck and yytname. */
michael@0 1059 int yychecklim = YYLAST - yyn + 1;
michael@0 1060 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
michael@0 1061 int yyx;
michael@0 1062
michael@0 1063 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
michael@0 1064 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
michael@0 1065 && !yytable_value_is_error (yytable[yyx + yyn]))
michael@0 1066 {
michael@0 1067 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
michael@0 1068 {
michael@0 1069 yycount = 1;
michael@0 1070 yysize = yysize0;
michael@0 1071 break;
michael@0 1072 }
michael@0 1073 yyarg[yycount++] = yytname[yyx];
michael@0 1074 {
michael@0 1075 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
michael@0 1076 if (! (yysize <= yysize1
michael@0 1077 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
michael@0 1078 return 2;
michael@0 1079 yysize = yysize1;
michael@0 1080 }
michael@0 1081 }
michael@0 1082 }
michael@0 1083 }
michael@0 1084
michael@0 1085 switch (yycount)
michael@0 1086 {
michael@0 1087 # define YYCASE_(N, S) \
michael@0 1088 case N: \
michael@0 1089 yyformat = S; \
michael@0 1090 break
michael@0 1091 YYCASE_(0, YY_("syntax error"));
michael@0 1092 YYCASE_(1, YY_("syntax error, unexpected %s"));
michael@0 1093 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
michael@0 1094 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
michael@0 1095 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
michael@0 1096 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
michael@0 1097 # undef YYCASE_
michael@0 1098 }
michael@0 1099
michael@0 1100 {
michael@0 1101 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
michael@0 1102 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
michael@0 1103 return 2;
michael@0 1104 yysize = yysize1;
michael@0 1105 }
michael@0 1106
michael@0 1107 if (*yymsg_alloc < yysize)
michael@0 1108 {
michael@0 1109 *yymsg_alloc = 2 * yysize;
michael@0 1110 if (! (yysize <= *yymsg_alloc
michael@0 1111 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
michael@0 1112 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
michael@0 1113 return 1;
michael@0 1114 }
michael@0 1115
michael@0 1116 /* Avoid sprintf, as that infringes on the user's name space.
michael@0 1117 Don't have undefined behavior even if the translation
michael@0 1118 produced a string with the wrong number of "%s"s. */
michael@0 1119 {
michael@0 1120 char *yyp = *yymsg;
michael@0 1121 int yyi = 0;
michael@0 1122 while ((*yyp = *yyformat) != '\0')
michael@0 1123 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
michael@0 1124 {
michael@0 1125 yyp += yytnamerr (yyp, yyarg[yyi++]);
michael@0 1126 yyformat += 2;
michael@0 1127 }
michael@0 1128 else
michael@0 1129 {
michael@0 1130 yyp++;
michael@0 1131 yyformat++;
michael@0 1132 }
michael@0 1133 }
michael@0 1134 return 0;
michael@0 1135 }
michael@0 1136 #endif /* YYERROR_VERBOSE */
michael@0 1137
michael@0 1138 /*-----------------------------------------------.
michael@0 1139 | Release the memory associated to this symbol. |
michael@0 1140 `-----------------------------------------------*/
michael@0 1141
michael@0 1142 /*ARGSUSED*/
michael@0 1143 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 1144 || defined __cplusplus || defined _MSC_VER)
michael@0 1145 static void
michael@0 1146 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
michael@0 1147 #else
michael@0 1148 static void
michael@0 1149 yydestruct (yymsg, yytype, yyvaluep, context)
michael@0 1150 const char *yymsg;
michael@0 1151 int yytype;
michael@0 1152 YYSTYPE *yyvaluep;
michael@0 1153 Context *context;
michael@0 1154 #endif
michael@0 1155 {
michael@0 1156 YYUSE (yyvaluep);
michael@0 1157 YYUSE (context);
michael@0 1158
michael@0 1159 if (!yymsg)
michael@0 1160 yymsg = "Deleting";
michael@0 1161 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
michael@0 1162
michael@0 1163 switch (yytype)
michael@0 1164 {
michael@0 1165
michael@0 1166 default:
michael@0 1167 break;
michael@0 1168 }
michael@0 1169 }
michael@0 1170
michael@0 1171
michael@0 1172
michael@0 1173
michael@0 1174 /*----------.
michael@0 1175 | yyparse. |
michael@0 1176 `----------*/
michael@0 1177
michael@0 1178 #ifdef YYPARSE_PARAM
michael@0 1179 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 1180 || defined __cplusplus || defined _MSC_VER)
michael@0 1181 int
michael@0 1182 yyparse (void *YYPARSE_PARAM)
michael@0 1183 #else
michael@0 1184 int
michael@0 1185 yyparse (YYPARSE_PARAM)
michael@0 1186 void *YYPARSE_PARAM;
michael@0 1187 #endif
michael@0 1188 #else /* ! YYPARSE_PARAM */
michael@0 1189 #if (defined __STDC__ || defined __C99__FUNC__ \
michael@0 1190 || defined __cplusplus || defined _MSC_VER)
michael@0 1191 int
michael@0 1192 yyparse (Context *context)
michael@0 1193 #else
michael@0 1194 int
michael@0 1195 yyparse (context)
michael@0 1196 Context *context;
michael@0 1197 #endif
michael@0 1198 #endif
michael@0 1199 {
michael@0 1200 /* The lookahead symbol. */
michael@0 1201 int yychar;
michael@0 1202
michael@0 1203
michael@0 1204 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
michael@0 1205 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
michael@0 1206 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
michael@0 1207 _Pragma ("GCC diagnostic push") \
michael@0 1208 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
michael@0 1209 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
michael@0 1210 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
michael@0 1211 _Pragma ("GCC diagnostic pop")
michael@0 1212 #else
michael@0 1213 /* Default value used for initialization, for pacifying older GCCs
michael@0 1214 or non-GCC compilers. */
michael@0 1215 static YYSTYPE yyval_default;
michael@0 1216 # define YY_INITIAL_VALUE(Value) = Value
michael@0 1217 #endif
michael@0 1218 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
michael@0 1219 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
michael@0 1220 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
michael@0 1221 #endif
michael@0 1222 #ifndef YY_INITIAL_VALUE
michael@0 1223 # define YY_INITIAL_VALUE(Value) /* Nothing. */
michael@0 1224 #endif
michael@0 1225
michael@0 1226 /* The semantic value of the lookahead symbol. */
michael@0 1227 YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
michael@0 1228
michael@0 1229 /* Number of syntax errors so far. */
michael@0 1230 int yynerrs;
michael@0 1231
michael@0 1232 int yystate;
michael@0 1233 /* Number of tokens to shift before error messages enabled. */
michael@0 1234 int yyerrstatus;
michael@0 1235
michael@0 1236 /* The stacks and their tools:
michael@0 1237 `yyss': related to states.
michael@0 1238 `yyvs': related to semantic values.
michael@0 1239
michael@0 1240 Refer to the stacks through separate pointers, to allow yyoverflow
michael@0 1241 to reallocate them elsewhere. */
michael@0 1242
michael@0 1243 /* The state stack. */
michael@0 1244 yytype_int16 yyssa[YYINITDEPTH];
michael@0 1245 yytype_int16 *yyss;
michael@0 1246 yytype_int16 *yyssp;
michael@0 1247
michael@0 1248 /* The semantic value stack. */
michael@0 1249 YYSTYPE yyvsa[YYINITDEPTH];
michael@0 1250 YYSTYPE *yyvs;
michael@0 1251 YYSTYPE *yyvsp;
michael@0 1252
michael@0 1253 YYSIZE_T yystacksize;
michael@0 1254
michael@0 1255 int yyn;
michael@0 1256 int yyresult;
michael@0 1257 /* Lookahead token as an internal (translated) token number. */
michael@0 1258 int yytoken = 0;
michael@0 1259 /* The variables used to return semantic value and location from the
michael@0 1260 action routines. */
michael@0 1261 YYSTYPE yyval;
michael@0 1262
michael@0 1263 #if YYERROR_VERBOSE
michael@0 1264 /* Buffer for error messages, and its allocated size. */
michael@0 1265 char yymsgbuf[128];
michael@0 1266 char *yymsg = yymsgbuf;
michael@0 1267 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
michael@0 1268 #endif
michael@0 1269
michael@0 1270 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
michael@0 1271
michael@0 1272 /* The number of symbols on the RHS of the reduced rule.
michael@0 1273 Keep to zero when no symbol should be popped. */
michael@0 1274 int yylen = 0;
michael@0 1275
michael@0 1276 yyssp = yyss = yyssa;
michael@0 1277 yyvsp = yyvs = yyvsa;
michael@0 1278 yystacksize = YYINITDEPTH;
michael@0 1279
michael@0 1280 YYDPRINTF ((stderr, "Starting parse\n"));
michael@0 1281
michael@0 1282 yystate = 0;
michael@0 1283 yyerrstatus = 0;
michael@0 1284 yynerrs = 0;
michael@0 1285 yychar = YYEMPTY; /* Cause a token to be read. */
michael@0 1286 goto yysetstate;
michael@0 1287
michael@0 1288 /*------------------------------------------------------------.
michael@0 1289 | yynewstate -- Push a new state, which is found in yystate. |
michael@0 1290 `------------------------------------------------------------*/
michael@0 1291 yynewstate:
michael@0 1292 /* In all cases, when you get here, the value and location stacks
michael@0 1293 have just been pushed. So pushing a state here evens the stacks. */
michael@0 1294 yyssp++;
michael@0 1295
michael@0 1296 yysetstate:
michael@0 1297 *yyssp = yystate;
michael@0 1298
michael@0 1299 if (yyss + yystacksize - 1 <= yyssp)
michael@0 1300 {
michael@0 1301 /* Get the current used size of the three stacks, in elements. */
michael@0 1302 YYSIZE_T yysize = yyssp - yyss + 1;
michael@0 1303
michael@0 1304 #ifdef yyoverflow
michael@0 1305 {
michael@0 1306 /* Give user a chance to reallocate the stack. Use copies of
michael@0 1307 these so that the &'s don't force the real ones into
michael@0 1308 memory. */
michael@0 1309 YYSTYPE *yyvs1 = yyvs;
michael@0 1310 yytype_int16 *yyss1 = yyss;
michael@0 1311
michael@0 1312 /* Each stack pointer address is followed by the size of the
michael@0 1313 data in use in that stack, in bytes. This used to be a
michael@0 1314 conditional around just the two extra args, but that might
michael@0 1315 be undefined if yyoverflow is a macro. */
michael@0 1316 yyoverflow (YY_("memory exhausted"),
michael@0 1317 &yyss1, yysize * sizeof (*yyssp),
michael@0 1318 &yyvs1, yysize * sizeof (*yyvsp),
michael@0 1319 &yystacksize);
michael@0 1320
michael@0 1321 yyss = yyss1;
michael@0 1322 yyvs = yyvs1;
michael@0 1323 }
michael@0 1324 #else /* no yyoverflow */
michael@0 1325 # ifndef YYSTACK_RELOCATE
michael@0 1326 goto yyexhaustedlab;
michael@0 1327 # else
michael@0 1328 /* Extend the stack our own way. */
michael@0 1329 if (YYMAXDEPTH <= yystacksize)
michael@0 1330 goto yyexhaustedlab;
michael@0 1331 yystacksize *= 2;
michael@0 1332 if (YYMAXDEPTH < yystacksize)
michael@0 1333 yystacksize = YYMAXDEPTH;
michael@0 1334
michael@0 1335 {
michael@0 1336 yytype_int16 *yyss1 = yyss;
michael@0 1337 union yyalloc *yyptr =
michael@0 1338 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
michael@0 1339 if (! yyptr)
michael@0 1340 goto yyexhaustedlab;
michael@0 1341 YYSTACK_RELOCATE (yyss_alloc, yyss);
michael@0 1342 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
michael@0 1343 # undef YYSTACK_RELOCATE
michael@0 1344 if (yyss1 != yyssa)
michael@0 1345 YYSTACK_FREE (yyss1);
michael@0 1346 }
michael@0 1347 # endif
michael@0 1348 #endif /* no yyoverflow */
michael@0 1349
michael@0 1350 yyssp = yyss + yysize - 1;
michael@0 1351 yyvsp = yyvs + yysize - 1;
michael@0 1352
michael@0 1353 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
michael@0 1354 (unsigned long int) yystacksize));
michael@0 1355
michael@0 1356 if (yyss + yystacksize - 1 <= yyssp)
michael@0 1357 YYABORT;
michael@0 1358 }
michael@0 1359
michael@0 1360 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
michael@0 1361
michael@0 1362 if (yystate == YYFINAL)
michael@0 1363 YYACCEPT;
michael@0 1364
michael@0 1365 goto yybackup;
michael@0 1366
michael@0 1367 /*-----------.
michael@0 1368 | yybackup. |
michael@0 1369 `-----------*/
michael@0 1370 yybackup:
michael@0 1371
michael@0 1372 /* Do appropriate processing given the current state. Read a
michael@0 1373 lookahead token if we need one and don't already have one. */
michael@0 1374
michael@0 1375 /* First try to decide what to do without reference to lookahead token. */
michael@0 1376 yyn = yypact[yystate];
michael@0 1377 if (yypact_value_is_default (yyn))
michael@0 1378 goto yydefault;
michael@0 1379
michael@0 1380 /* Not known => get a lookahead token if don't already have one. */
michael@0 1381
michael@0 1382 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
michael@0 1383 if (yychar == YYEMPTY)
michael@0 1384 {
michael@0 1385 YYDPRINTF ((stderr, "Reading a token: "));
michael@0 1386 yychar = YYLEX;
michael@0 1387 }
michael@0 1388
michael@0 1389 if (yychar <= YYEOF)
michael@0 1390 {
michael@0 1391 yychar = yytoken = YYEOF;
michael@0 1392 YYDPRINTF ((stderr, "Now at end of input.\n"));
michael@0 1393 }
michael@0 1394 else
michael@0 1395 {
michael@0 1396 yytoken = YYTRANSLATE (yychar);
michael@0 1397 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
michael@0 1398 }
michael@0 1399
michael@0 1400 /* If the proper action on seeing token YYTOKEN is to reduce or to
michael@0 1401 detect an error, take that action. */
michael@0 1402 yyn += yytoken;
michael@0 1403 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
michael@0 1404 goto yydefault;
michael@0 1405 yyn = yytable[yyn];
michael@0 1406 if (yyn <= 0)
michael@0 1407 {
michael@0 1408 if (yytable_value_is_error (yyn))
michael@0 1409 goto yyerrlab;
michael@0 1410 yyn = -yyn;
michael@0 1411 goto yyreduce;
michael@0 1412 }
michael@0 1413
michael@0 1414 /* Count tokens shifted since error; after three, turn off error
michael@0 1415 status. */
michael@0 1416 if (yyerrstatus)
michael@0 1417 yyerrstatus--;
michael@0 1418
michael@0 1419 /* Shift the lookahead token. */
michael@0 1420 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
michael@0 1421
michael@0 1422 /* Discard the shifted token. */
michael@0 1423 yychar = YYEMPTY;
michael@0 1424
michael@0 1425 yystate = yyn;
michael@0 1426 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
michael@0 1427 *++yyvsp = yylval;
michael@0 1428 YY_IGNORE_MAYBE_UNINITIALIZED_END
michael@0 1429
michael@0 1430 goto yynewstate;
michael@0 1431
michael@0 1432
michael@0 1433 /*-----------------------------------------------------------.
michael@0 1434 | yydefault -- do the default action for the current state. |
michael@0 1435 `-----------------------------------------------------------*/
michael@0 1436 yydefault:
michael@0 1437 yyn = yydefact[yystate];
michael@0 1438 if (yyn == 0)
michael@0 1439 goto yyerrlab;
michael@0 1440 goto yyreduce;
michael@0 1441
michael@0 1442
michael@0 1443 /*-----------------------------.
michael@0 1444 | yyreduce -- Do a reduction. |
michael@0 1445 `-----------------------------*/
michael@0 1446 yyreduce:
michael@0 1447 /* yyn is the number of a rule to reduce with. */
michael@0 1448 yylen = yyr2[yyn];
michael@0 1449
michael@0 1450 /* If YYLEN is nonzero, implement the default value of the action:
michael@0 1451 `$$ = $1'.
michael@0 1452
michael@0 1453 Otherwise, the following line sets YYVAL to garbage.
michael@0 1454 This behavior is undocumented and Bison
michael@0 1455 users should not rely upon it. Assigning to YYVAL
michael@0 1456 unconditionally makes the parser a bit smaller, and it avoids a
michael@0 1457 GCC warning that YYVAL may be used uninitialized. */
michael@0 1458 yyval = yyvsp[1-yylen];
michael@0 1459
michael@0 1460
michael@0 1461 YY_REDUCE_PRINT (yyn);
michael@0 1462 switch (yyn)
michael@0 1463 {
michael@0 1464 case 2:
michael@0 1465
michael@0 1466 {
michael@0 1467 *(context->result) = static_cast<int>((yyvsp[(1) - (1)]));
michael@0 1468 YYACCEPT;
michael@0 1469 }
michael@0 1470 break;
michael@0 1471
michael@0 1472 case 4:
michael@0 1473
michael@0 1474 {
michael@0 1475 (yyval) = (yyvsp[(1) - (3)]) || (yyvsp[(3) - (3)]);
michael@0 1476 }
michael@0 1477 break;
michael@0 1478
michael@0 1479 case 5:
michael@0 1480
michael@0 1481 {
michael@0 1482 (yyval) = (yyvsp[(1) - (3)]) && (yyvsp[(3) - (3)]);
michael@0 1483 }
michael@0 1484 break;
michael@0 1485
michael@0 1486 case 6:
michael@0 1487
michael@0 1488 {
michael@0 1489 (yyval) = (yyvsp[(1) - (3)]) | (yyvsp[(3) - (3)]);
michael@0 1490 }
michael@0 1491 break;
michael@0 1492
michael@0 1493 case 7:
michael@0 1494
michael@0 1495 {
michael@0 1496 (yyval) = (yyvsp[(1) - (3)]) ^ (yyvsp[(3) - (3)]);
michael@0 1497 }
michael@0 1498 break;
michael@0 1499
michael@0 1500 case 8:
michael@0 1501
michael@0 1502 {
michael@0 1503 (yyval) = (yyvsp[(1) - (3)]) & (yyvsp[(3) - (3)]);
michael@0 1504 }
michael@0 1505 break;
michael@0 1506
michael@0 1507 case 9:
michael@0 1508
michael@0 1509 {
michael@0 1510 (yyval) = (yyvsp[(1) - (3)]) != (yyvsp[(3) - (3)]);
michael@0 1511 }
michael@0 1512 break;
michael@0 1513
michael@0 1514 case 10:
michael@0 1515
michael@0 1516 {
michael@0 1517 (yyval) = (yyvsp[(1) - (3)]) == (yyvsp[(3) - (3)]);
michael@0 1518 }
michael@0 1519 break;
michael@0 1520
michael@0 1521 case 11:
michael@0 1522
michael@0 1523 {
michael@0 1524 (yyval) = (yyvsp[(1) - (3)]) >= (yyvsp[(3) - (3)]);
michael@0 1525 }
michael@0 1526 break;
michael@0 1527
michael@0 1528 case 12:
michael@0 1529
michael@0 1530 {
michael@0 1531 (yyval) = (yyvsp[(1) - (3)]) <= (yyvsp[(3) - (3)]);
michael@0 1532 }
michael@0 1533 break;
michael@0 1534
michael@0 1535 case 13:
michael@0 1536
michael@0 1537 {
michael@0 1538 (yyval) = (yyvsp[(1) - (3)]) > (yyvsp[(3) - (3)]);
michael@0 1539 }
michael@0 1540 break;
michael@0 1541
michael@0 1542 case 14:
michael@0 1543
michael@0 1544 {
michael@0 1545 (yyval) = (yyvsp[(1) - (3)]) < (yyvsp[(3) - (3)]);
michael@0 1546 }
michael@0 1547 break;
michael@0 1548
michael@0 1549 case 15:
michael@0 1550
michael@0 1551 {
michael@0 1552 (yyval) = (yyvsp[(1) - (3)]) >> (yyvsp[(3) - (3)]);
michael@0 1553 }
michael@0 1554 break;
michael@0 1555
michael@0 1556 case 16:
michael@0 1557
michael@0 1558 {
michael@0 1559 (yyval) = (yyvsp[(1) - (3)]) << (yyvsp[(3) - (3)]);
michael@0 1560 }
michael@0 1561 break;
michael@0 1562
michael@0 1563 case 17:
michael@0 1564
michael@0 1565 {
michael@0 1566 (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]);
michael@0 1567 }
michael@0 1568 break;
michael@0 1569
michael@0 1570 case 18:
michael@0 1571
michael@0 1572 {
michael@0 1573 (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]);
michael@0 1574 }
michael@0 1575 break;
michael@0 1576
michael@0 1577 case 19:
michael@0 1578
michael@0 1579 {
michael@0 1580 if ((yyvsp[(3) - (3)]) == 0) {
michael@0 1581 std::ostringstream stream;
michael@0 1582 stream << (yyvsp[(1) - (3)]) << " % " << (yyvsp[(3) - (3)]);
michael@0 1583 std::string text = stream.str();
michael@0 1584 context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO,
michael@0 1585 context->token->location,
michael@0 1586 text.c_str());
michael@0 1587 YYABORT;
michael@0 1588 } else {
michael@0 1589 (yyval) = (yyvsp[(1) - (3)]) % (yyvsp[(3) - (3)]);
michael@0 1590 }
michael@0 1591 }
michael@0 1592 break;
michael@0 1593
michael@0 1594 case 20:
michael@0 1595
michael@0 1596 {
michael@0 1597 if ((yyvsp[(3) - (3)]) == 0) {
michael@0 1598 std::ostringstream stream;
michael@0 1599 stream << (yyvsp[(1) - (3)]) << " / " << (yyvsp[(3) - (3)]);
michael@0 1600 std::string text = stream.str();
michael@0 1601 context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO,
michael@0 1602 context->token->location,
michael@0 1603 text.c_str());
michael@0 1604 YYABORT;
michael@0 1605 } else {
michael@0 1606 (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]);
michael@0 1607 }
michael@0 1608 }
michael@0 1609 break;
michael@0 1610
michael@0 1611 case 21:
michael@0 1612
michael@0 1613 {
michael@0 1614 (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]);
michael@0 1615 }
michael@0 1616 break;
michael@0 1617
michael@0 1618 case 22:
michael@0 1619
michael@0 1620 {
michael@0 1621 (yyval) = ! (yyvsp[(2) - (2)]);
michael@0 1622 }
michael@0 1623 break;
michael@0 1624
michael@0 1625 case 23:
michael@0 1626
michael@0 1627 {
michael@0 1628 (yyval) = ~ (yyvsp[(2) - (2)]);
michael@0 1629 }
michael@0 1630 break;
michael@0 1631
michael@0 1632 case 24:
michael@0 1633
michael@0 1634 {
michael@0 1635 (yyval) = - (yyvsp[(2) - (2)]);
michael@0 1636 }
michael@0 1637 break;
michael@0 1638
michael@0 1639 case 25:
michael@0 1640
michael@0 1641 {
michael@0 1642 (yyval) = + (yyvsp[(2) - (2)]);
michael@0 1643 }
michael@0 1644 break;
michael@0 1645
michael@0 1646 case 26:
michael@0 1647
michael@0 1648 {
michael@0 1649 (yyval) = (yyvsp[(2) - (3)]);
michael@0 1650 }
michael@0 1651 break;
michael@0 1652
michael@0 1653
michael@0 1654
michael@0 1655 default: break;
michael@0 1656 }
michael@0 1657 /* User semantic actions sometimes alter yychar, and that requires
michael@0 1658 that yytoken be updated with the new translation. We take the
michael@0 1659 approach of translating immediately before every use of yytoken.
michael@0 1660 One alternative is translating here after every semantic action,
michael@0 1661 but that translation would be missed if the semantic action invokes
michael@0 1662 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
michael@0 1663 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
michael@0 1664 incorrect destructor might then be invoked immediately. In the
michael@0 1665 case of YYERROR or YYBACKUP, subsequent parser actions might lead
michael@0 1666 to an incorrect destructor call or verbose syntax error message
michael@0 1667 before the lookahead is translated. */
michael@0 1668 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
michael@0 1669
michael@0 1670 YYPOPSTACK (yylen);
michael@0 1671 yylen = 0;
michael@0 1672 YY_STACK_PRINT (yyss, yyssp);
michael@0 1673
michael@0 1674 *++yyvsp = yyval;
michael@0 1675
michael@0 1676 /* Now `shift' the result of the reduction. Determine what state
michael@0 1677 that goes to, based on the state we popped back to and the rule
michael@0 1678 number reduced by. */
michael@0 1679
michael@0 1680 yyn = yyr1[yyn];
michael@0 1681
michael@0 1682 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
michael@0 1683 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
michael@0 1684 yystate = yytable[yystate];
michael@0 1685 else
michael@0 1686 yystate = yydefgoto[yyn - YYNTOKENS];
michael@0 1687
michael@0 1688 goto yynewstate;
michael@0 1689
michael@0 1690
michael@0 1691 /*------------------------------------.
michael@0 1692 | yyerrlab -- here on detecting error |
michael@0 1693 `------------------------------------*/
michael@0 1694 yyerrlab:
michael@0 1695 /* Make sure we have latest lookahead translation. See comments at
michael@0 1696 user semantic actions for why this is necessary. */
michael@0 1697 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
michael@0 1698
michael@0 1699 /* If not already recovering from an error, report this error. */
michael@0 1700 if (!yyerrstatus)
michael@0 1701 {
michael@0 1702 ++yynerrs;
michael@0 1703 #if ! YYERROR_VERBOSE
michael@0 1704 yyerror (context, YY_("syntax error"));
michael@0 1705 #else
michael@0 1706 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
michael@0 1707 yyssp, yytoken)
michael@0 1708 {
michael@0 1709 char const *yymsgp = YY_("syntax error");
michael@0 1710 int yysyntax_error_status;
michael@0 1711 yysyntax_error_status = YYSYNTAX_ERROR;
michael@0 1712 if (yysyntax_error_status == 0)
michael@0 1713 yymsgp = yymsg;
michael@0 1714 else if (yysyntax_error_status == 1)
michael@0 1715 {
michael@0 1716 if (yymsg != yymsgbuf)
michael@0 1717 YYSTACK_FREE (yymsg);
michael@0 1718 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
michael@0 1719 if (!yymsg)
michael@0 1720 {
michael@0 1721 yymsg = yymsgbuf;
michael@0 1722 yymsg_alloc = sizeof yymsgbuf;
michael@0 1723 yysyntax_error_status = 2;
michael@0 1724 }
michael@0 1725 else
michael@0 1726 {
michael@0 1727 yysyntax_error_status = YYSYNTAX_ERROR;
michael@0 1728 yymsgp = yymsg;
michael@0 1729 }
michael@0 1730 }
michael@0 1731 yyerror (context, yymsgp);
michael@0 1732 if (yysyntax_error_status == 2)
michael@0 1733 goto yyexhaustedlab;
michael@0 1734 }
michael@0 1735 # undef YYSYNTAX_ERROR
michael@0 1736 #endif
michael@0 1737 }
michael@0 1738
michael@0 1739
michael@0 1740
michael@0 1741 if (yyerrstatus == 3)
michael@0 1742 {
michael@0 1743 /* If just tried and failed to reuse lookahead token after an
michael@0 1744 error, discard it. */
michael@0 1745
michael@0 1746 if (yychar <= YYEOF)
michael@0 1747 {
michael@0 1748 /* Return failure if at end of input. */
michael@0 1749 if (yychar == YYEOF)
michael@0 1750 YYABORT;
michael@0 1751 }
michael@0 1752 else
michael@0 1753 {
michael@0 1754 yydestruct ("Error: discarding",
michael@0 1755 yytoken, &yylval, context);
michael@0 1756 yychar = YYEMPTY;
michael@0 1757 }
michael@0 1758 }
michael@0 1759
michael@0 1760 /* Else will try to reuse lookahead token after shifting the error
michael@0 1761 token. */
michael@0 1762 goto yyerrlab1;
michael@0 1763
michael@0 1764
michael@0 1765 /*---------------------------------------------------.
michael@0 1766 | yyerrorlab -- error raised explicitly by YYERROR. |
michael@0 1767 `---------------------------------------------------*/
michael@0 1768 yyerrorlab:
michael@0 1769
michael@0 1770 /* Pacify compilers like GCC when the user code never invokes
michael@0 1771 YYERROR and the label yyerrorlab therefore never appears in user
michael@0 1772 code. */
michael@0 1773 if (/*CONSTCOND*/ 0)
michael@0 1774 goto yyerrorlab;
michael@0 1775
michael@0 1776 /* Do not reclaim the symbols of the rule which action triggered
michael@0 1777 this YYERROR. */
michael@0 1778 YYPOPSTACK (yylen);
michael@0 1779 yylen = 0;
michael@0 1780 YY_STACK_PRINT (yyss, yyssp);
michael@0 1781 yystate = *yyssp;
michael@0 1782 goto yyerrlab1;
michael@0 1783
michael@0 1784
michael@0 1785 /*-------------------------------------------------------------.
michael@0 1786 | yyerrlab1 -- common code for both syntax error and YYERROR. |
michael@0 1787 `-------------------------------------------------------------*/
michael@0 1788 yyerrlab1:
michael@0 1789 yyerrstatus = 3; /* Each real token shifted decrements this. */
michael@0 1790
michael@0 1791 for (;;)
michael@0 1792 {
michael@0 1793 yyn = yypact[yystate];
michael@0 1794 if (!yypact_value_is_default (yyn))
michael@0 1795 {
michael@0 1796 yyn += YYTERROR;
michael@0 1797 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
michael@0 1798 {
michael@0 1799 yyn = yytable[yyn];
michael@0 1800 if (0 < yyn)
michael@0 1801 break;
michael@0 1802 }
michael@0 1803 }
michael@0 1804
michael@0 1805 /* Pop the current state because it cannot handle the error token. */
michael@0 1806 if (yyssp == yyss)
michael@0 1807 YYABORT;
michael@0 1808
michael@0 1809
michael@0 1810 yydestruct ("Error: popping",
michael@0 1811 yystos[yystate], yyvsp, context);
michael@0 1812 YYPOPSTACK (1);
michael@0 1813 yystate = *yyssp;
michael@0 1814 YY_STACK_PRINT (yyss, yyssp);
michael@0 1815 }
michael@0 1816
michael@0 1817 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
michael@0 1818 *++yyvsp = yylval;
michael@0 1819 YY_IGNORE_MAYBE_UNINITIALIZED_END
michael@0 1820
michael@0 1821
michael@0 1822 /* Shift the error token. */
michael@0 1823 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
michael@0 1824
michael@0 1825 yystate = yyn;
michael@0 1826 goto yynewstate;
michael@0 1827
michael@0 1828
michael@0 1829 /*-------------------------------------.
michael@0 1830 | yyacceptlab -- YYACCEPT comes here. |
michael@0 1831 `-------------------------------------*/
michael@0 1832 yyacceptlab:
michael@0 1833 yyresult = 0;
michael@0 1834 goto yyreturn;
michael@0 1835
michael@0 1836 /*-----------------------------------.
michael@0 1837 | yyabortlab -- YYABORT comes here. |
michael@0 1838 `-----------------------------------*/
michael@0 1839 yyabortlab:
michael@0 1840 yyresult = 1;
michael@0 1841 goto yyreturn;
michael@0 1842
michael@0 1843 #if !defined yyoverflow || YYERROR_VERBOSE
michael@0 1844 /*-------------------------------------------------.
michael@0 1845 | yyexhaustedlab -- memory exhaustion comes here. |
michael@0 1846 `-------------------------------------------------*/
michael@0 1847 yyexhaustedlab:
michael@0 1848 yyerror (context, YY_("memory exhausted"));
michael@0 1849 yyresult = 2;
michael@0 1850 /* Fall through. */
michael@0 1851 #endif
michael@0 1852
michael@0 1853 yyreturn:
michael@0 1854 if (yychar != YYEMPTY)
michael@0 1855 {
michael@0 1856 /* Make sure we have latest lookahead translation. See comments at
michael@0 1857 user semantic actions for why this is necessary. */
michael@0 1858 yytoken = YYTRANSLATE (yychar);
michael@0 1859 yydestruct ("Cleanup: discarding lookahead",
michael@0 1860 yytoken, &yylval, context);
michael@0 1861 }
michael@0 1862 /* Do not reclaim the symbols of the rule which action triggered
michael@0 1863 this YYABORT or YYACCEPT. */
michael@0 1864 YYPOPSTACK (yylen);
michael@0 1865 YY_STACK_PRINT (yyss, yyssp);
michael@0 1866 while (yyssp != yyss)
michael@0 1867 {
michael@0 1868 yydestruct ("Cleanup: popping",
michael@0 1869 yystos[*yyssp], yyvsp, context);
michael@0 1870 YYPOPSTACK (1);
michael@0 1871 }
michael@0 1872 #ifndef yyoverflow
michael@0 1873 if (yyss != yyssa)
michael@0 1874 YYSTACK_FREE (yyss);
michael@0 1875 #endif
michael@0 1876 #if YYERROR_VERBOSE
michael@0 1877 if (yymsg != yymsgbuf)
michael@0 1878 YYSTACK_FREE (yymsg);
michael@0 1879 #endif
michael@0 1880 /* Make sure YYID is used. */
michael@0 1881 return YYID (yyresult);
michael@0 1882 }
michael@0 1883
michael@0 1884
michael@0 1885
michael@0 1886
michael@0 1887
michael@0 1888 int yylex(YYSTYPE* lvalp, Context* context)
michael@0 1889 {
michael@0 1890 int type = 0;
michael@0 1891
michael@0 1892 pp::Token* token = context->token;
michael@0 1893 switch (token->type)
michael@0 1894 {
michael@0 1895 case pp::Token::CONST_INT:
michael@0 1896 {
michael@0 1897 unsigned int val = 0;
michael@0 1898 if (!token->uValue(&val))
michael@0 1899 {
michael@0 1900 context->diagnostics->report(pp::Diagnostics::INTEGER_OVERFLOW,
michael@0 1901 token->location, token->text);
michael@0 1902 }
michael@0 1903 *lvalp = static_cast<YYSTYPE>(val);
michael@0 1904 type = TOK_CONST_INT;
michael@0 1905 break;
michael@0 1906 }
michael@0 1907 case pp::Token::OP_OR: type = TOK_OP_OR; break;
michael@0 1908 case pp::Token::OP_AND: type = TOK_OP_AND; break;
michael@0 1909 case pp::Token::OP_NE: type = TOK_OP_NE; break;
michael@0 1910 case pp::Token::OP_EQ: type = TOK_OP_EQ; break;
michael@0 1911 case pp::Token::OP_GE: type = TOK_OP_GE; break;
michael@0 1912 case pp::Token::OP_LE: type = TOK_OP_LE; break;
michael@0 1913 case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break;
michael@0 1914 case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break;
michael@0 1915 case '|': type = '|'; break;
michael@0 1916 case '^': type = '^'; break;
michael@0 1917 case '&': type = '&'; break;
michael@0 1918 case '>': type = '>'; break;
michael@0 1919 case '<': type = '<'; break;
michael@0 1920 case '-': type = '-'; break;
michael@0 1921 case '+': type = '+'; break;
michael@0 1922 case '%': type = '%'; break;
michael@0 1923 case '/': type = '/'; break;
michael@0 1924 case '*': type = '*'; break;
michael@0 1925 case '!': type = '!'; break;
michael@0 1926 case '~': type = '~'; break;
michael@0 1927 case '(': type = '('; break;
michael@0 1928 case ')': type = ')'; break;
michael@0 1929
michael@0 1930 default: break;
michael@0 1931 }
michael@0 1932
michael@0 1933 // Advance to the next token if the current one is valid.
michael@0 1934 if (type != 0) context->lexer->lex(token);
michael@0 1935
michael@0 1936 return type;
michael@0 1937 }
michael@0 1938
michael@0 1939 void yyerror(Context* context, const char* reason)
michael@0 1940 {
michael@0 1941 context->diagnostics->report(pp::Diagnostics::INVALID_EXPRESSION,
michael@0 1942 context->token->location,
michael@0 1943 reason);
michael@0 1944 }
michael@0 1945
michael@0 1946 namespace pp {
michael@0 1947
michael@0 1948 ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) :
michael@0 1949 mLexer(lexer),
michael@0 1950 mDiagnostics(diagnostics)
michael@0 1951 {
michael@0 1952 }
michael@0 1953
michael@0 1954 bool ExpressionParser::parse(Token* token, int* result)
michael@0 1955 {
michael@0 1956 Context context;
michael@0 1957 context.diagnostics = mDiagnostics;
michael@0 1958 context.lexer = mLexer;
michael@0 1959 context.token = token;
michael@0 1960 context.result = result;
michael@0 1961 int ret = yyparse(&context);
michael@0 1962 switch (ret)
michael@0 1963 {
michael@0 1964 case 0:
michael@0 1965 case 1:
michael@0 1966 break;
michael@0 1967
michael@0 1968 case 2:
michael@0 1969 mDiagnostics->report(Diagnostics::OUT_OF_MEMORY, token->location, "");
michael@0 1970 break;
michael@0 1971
michael@0 1972 default:
michael@0 1973 assert(false);
michael@0 1974 mDiagnostics->report(Diagnostics::INTERNAL_ERROR, token->location, "");
michael@0 1975 break;
michael@0 1976 }
michael@0 1977
michael@0 1978 return ret == 0;
michael@0 1979 }
michael@0 1980
michael@0 1981 } // namespace pp

mercurial