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