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