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