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