]>
Commit | Line | Data |
---|---|---|
1 | -*- C -*- | |
2 | ||
3 | # GLR skeleton for Bison | |
4 | ||
5 | # Copyright (C) 2002-2012 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 | ||
21 | m4_include(b4_pkgdatadir/[c.m4]) | |
22 | ||
23 | ## ---------------- ## | |
24 | ## Default values. ## | |
25 | ## ---------------- ## | |
26 | ||
27 | # Stack parameters. | |
28 | m4_define_default([b4_stack_depth_max], [10000]) | |
29 | m4_define_default([b4_stack_depth_init], [200]) | |
30 | ||
31 | ||
32 | ||
33 | ## ------------------------ ## | |
34 | ## Pure/impure interfaces. ## | |
35 | ## ------------------------ ## | |
36 | ||
37 | b4_define_flag_if([pure]) | |
38 | # If glr.cc is including this file and thus has already set b4_pure_flag, | |
39 | # do not change the value of b4_pure_flag, and do not record a use of api.pure. | |
40 | m4_ifndef([b4_pure_flag], | |
41 | [b4_percent_define_default([[api.pure]], [[false]]) | |
42 | m4_define([b4_pure_flag], | |
43 | [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])]) | |
44 | ||
45 | # b4_user_formals | |
46 | # --------------- | |
47 | # The possible parse-params formal arguments preceded by a comma. | |
48 | # | |
49 | # This is not shared with yacc.c in c.m4 because GLR relies on ISO C | |
50 | # formal argument declarations. | |
51 | m4_define([b4_user_formals], | |
52 | [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) | |
53 | ||
54 | ||
55 | # b4_lex_param | |
56 | # ------------ | |
57 | # Accumule in b4_lex_param all the yylex arguments. | |
58 | # Yes, this is quite ugly... | |
59 | m4_define([b4_lex_param], | |
60 | m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl | |
61 | b4_locations_if([, [[YYLTYPE *], [&yylloc]]])])dnl | |
62 | m4_ifdef([b4_lex_param], [, ]b4_lex_param))) | |
63 | ||
64 | ||
65 | # b4_yyerror_args | |
66 | # --------------- | |
67 | # Optional effective arguments passed to yyerror: user args plus yylloc, and | |
68 | # a trailing comma. | |
69 | m4_define([b4_yyerror_args], | |
70 | [b4_pure_if([b4_locations_if([yylocp, ])])dnl | |
71 | m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) | |
72 | ||
73 | ||
74 | # b4_lyyerror_args | |
75 | # ---------------- | |
76 | # Same as above, but on the lookahead, hence &yylloc instead of yylocp. | |
77 | m4_define([b4_lyyerror_args], | |
78 | [b4_pure_if([b4_locations_if([&yylloc, ])])dnl | |
79 | m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) | |
80 | ||
81 | ||
82 | # b4_pure_args | |
83 | # ------------ | |
84 | # Same as b4_yyerror_args, but with a leading comma. | |
85 | m4_define([b4_pure_args], | |
86 | [b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args]) | |
87 | ||
88 | ||
89 | # b4_lpure_args | |
90 | # ------------- | |
91 | # Same as above, but on the lookahead, hence &yylloc instead of yylocp. | |
92 | m4_define([b4_lpure_args], | |
93 | [b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) | |
94 | ||
95 | ||
96 | ||
97 | # b4_pure_formals | |
98 | # --------------- | |
99 | # Arguments passed to yyerror: user formals plus yylocp with leading comma. | |
100 | m4_define([b4_pure_formals], | |
101 | [b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals]) | |
102 | ||
103 | ||
104 | # b4_locuser_formals(LOC = yylocp) | |
105 | # -------------------------------- | |
106 | m4_define([b4_locuser_formals], | |
107 | [b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals]) | |
108 | ||
109 | ||
110 | # b4_locuser_args(LOC = yylocp) | |
111 | # ----------------------------- | |
112 | m4_define([b4_locuser_args], | |
113 | [b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args]) | |
114 | ||
115 | ||
116 | ||
117 | ## ----------------- ## | |
118 | ## Semantic Values. ## | |
119 | ## ----------------- ## | |
120 | ||
121 | ||
122 | # b4_lhs_value([TYPE]) | |
123 | # -------------------- | |
124 | # Expansion of $<TYPE>$. | |
125 | m4_define([b4_lhs_value], | |
126 | [b4_symbol_value([(*yyvalp)], [$1])]) | |
127 | ||
128 | ||
129 | # b4_rhs_data(RULE-LENGTH, NUM) | |
130 | # ----------------------------- | |
131 | # Expand to the semantic stack place that contains value and location | |
132 | # of symbol number NUM in a rule of length RULE-LENGTH. | |
133 | m4_define([b4_rhs_data], | |
134 | [((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) | |
135 | ||
136 | ||
137 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
138 | # -------------------------------------- | |
139 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
140 | # symbols on RHS. | |
141 | m4_define([b4_rhs_value], | |
142 | [b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])]) | |
143 | ||
144 | ||
145 | ||
146 | ## ----------- ## | |
147 | ## Locations. ## | |
148 | ## ----------- ## | |
149 | ||
150 | # b4_lhs_location() | |
151 | # ----------------- | |
152 | # Expansion of @$. | |
153 | m4_define([b4_lhs_location], | |
154 | [(*yylocp)]) | |
155 | ||
156 | ||
157 | # b4_rhs_location(RULE-LENGTH, NUM) | |
158 | # --------------------------------- | |
159 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
160 | # on RHS. | |
161 | m4_define([b4_rhs_location], | |
162 | [(b4_rhs_data([$1], [$2]).yyloc)]) | |
163 | ||
164 | ||
165 | ## -------------- ## | |
166 | ## Declarations. ## | |
167 | ## -------------- ## | |
168 | ||
169 | # b4_shared_declarations | |
170 | # ---------------------- | |
171 | # Declaration that might either go into the header (if --defines) | |
172 | # or open coded in the parser body. | |
173 | m4_define([b4_shared_declarations], | |
174 | [b4_declare_yydebug[ | |
175 | ]b4_percent_code_get([[requires]])[ | |
176 | ]b4_token_enums(b4_tokens)[ | |
177 | ]b4_declare_yylstype[ | |
178 | ]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[ | |
179 | ]b4_percent_code_get([[provides]])[]dnl | |
180 | ]) | |
181 | ||
182 | ||
183 | ## -------------- ## | |
184 | ## Output files. ## | |
185 | ## -------------- ## | |
186 | ||
187 | # We do want M4 expansion after # for CPP macros. | |
188 | m4_changecom() | |
189 | m4_divert_push(0)dnl | |
190 | @output(b4_parser_file_name@)@ | |
191 | b4_copyright([Skeleton implementation for Bison GLR parsers in C], | |
192 | [2002-2012]) | |
193 | [ | |
194 | /* C GLR parser skeleton written by Paul Hilfinger. */ | |
195 | ||
196 | ]b4_identification | |
197 | ||
198 | b4_percent_code_get([[top]])[ | |
199 | ]m4_if(b4_prefix, [yy], [], | |
200 | [[/* Substitute the variable and function names. */ | |
201 | #define yyparse ]b4_prefix[parse | |
202 | #define yylex ]b4_prefix[lex | |
203 | #define yyerror ]b4_prefix[error | |
204 | #define yylval ]b4_prefix[lval | |
205 | #define yychar ]b4_prefix[char | |
206 | #define yydebug ]b4_prefix[debug | |
207 | #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ | |
208 | #define yylloc ]b4_prefix[lloc]])])[ | |
209 | ||
210 | /* Copy the first part of user declarations. */ | |
211 | ]b4_user_pre_prologue[ | |
212 | ||
213 | ]b4_null_define[ | |
214 | ||
215 | ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], | |
216 | [b4_shared_declarations])[ | |
217 | ||
218 | /* Enabling verbose error messages. */ | |
219 | #ifdef YYERROR_VERBOSE | |
220 | # undef YYERROR_VERBOSE | |
221 | # define YYERROR_VERBOSE 1 | |
222 | #else | |
223 | # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[ | |
224 | #endif | |
225 | ||
226 | /* Enabling the token table. */ | |
227 | #ifndef YYTOKEN_TABLE | |
228 | # define YYTOKEN_TABLE ]b4_token_table[ | |
229 | #endif | |
230 | ||
231 | /* Default (constant) value used for initialization for null | |
232 | right-hand sides. Unlike the standard yacc.c template, | |
233 | here we set the default value of $$ to a zeroed-out value. | |
234 | Since the default value is undefined, this behavior is | |
235 | technically correct. */ | |
236 | static YYSTYPE yyval_default; | |
237 | ||
238 | /* Copy the second part of user declarations. */ | |
239 | ]b4_user_post_prologue | |
240 | b4_percent_code_get[]dnl | |
241 | ||
242 | [#include <stdio.h> | |
243 | #include <stdlib.h> | |
244 | #include <string.h> | |
245 | ||
246 | #ifndef YY_ | |
247 | # if defined YYENABLE_NLS && YYENABLE_NLS | |
248 | # if ENABLE_NLS | |
249 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ | |
250 | # define YY_(msgid) dgettext ("bison-runtime", msgid) | |
251 | # endif | |
252 | # endif | |
253 | # ifndef YY_ | |
254 | # define YY_(msgid) msgid | |
255 | # endif | |
256 | #endif | |
257 | ||
258 | /* Suppress unused-variable warnings by "using" E. */ | |
259 | #if ! defined lint || defined __GNUC__ | |
260 | # define YYUSE(e) ((void) (e)) | |
261 | #else | |
262 | # define YYUSE(e) /* empty */ | |
263 | #endif | |
264 | ||
265 | /* Identity function, used to suppress warnings about constant conditions. */ | |
266 | #ifndef lint | |
267 | # define YYID(n) (n) | |
268 | #else | |
269 | ]b4_c_function_def([YYID], [static int], [[int i], [i]])[ | |
270 | { | |
271 | return i; | |
272 | } | |
273 | #endif | |
274 | ||
275 | #ifndef YYFREE | |
276 | # define YYFREE free | |
277 | #endif | |
278 | #ifndef YYMALLOC | |
279 | # define YYMALLOC malloc | |
280 | #endif | |
281 | #ifndef YYREALLOC | |
282 | # define YYREALLOC realloc | |
283 | #endif | |
284 | ||
285 | #define YYSIZEMAX ((size_t) -1) | |
286 | ||
287 | #ifdef __cplusplus | |
288 | typedef bool yybool; | |
289 | #else | |
290 | typedef unsigned char yybool; | |
291 | #endif | |
292 | #define yytrue 1 | |
293 | #define yyfalse 0 | |
294 | ||
295 | #ifndef YYSETJMP | |
296 | # include <setjmp.h> | |
297 | # define YYJMP_BUF jmp_buf | |
298 | # define YYSETJMP(env) setjmp (env) | |
299 | # define YYLONGJMP(env, val) longjmp (env, val) | |
300 | #endif | |
301 | ||
302 | /*-----------------. | |
303 | | GCC extensions. | | |
304 | `-----------------*/ | |
305 | ||
306 | #ifndef __attribute__ | |
307 | /* This feature is available in gcc versions 2.5 and later. */ | |
308 | # if (! defined __GNUC__ || __GNUC__ < 2 \ | |
309 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) | |
310 | # define __attribute__(Spec) /* empty */ | |
311 | # endif | |
312 | #endif | |
313 | ||
314 | ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[ | |
315 | #ifdef __cplusplus | |
316 | # define YYOPTIONAL_LOC(Name) /* empty */ | |
317 | #else | |
318 | # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__)) | |
319 | #endif])[ | |
320 | ||
321 | #ifndef YYASSERT | |
322 | # define YYASSERT(condition) ((void) ((condition) || (abort (), 0))) | |
323 | #endif | |
324 | ||
325 | /* YYFINAL -- State number of the termination state. */ | |
326 | #define YYFINAL ]b4_final_state_number[ | |
327 | /* YYLAST -- Last index in YYTABLE. */ | |
328 | #define YYLAST ]b4_last[ | |
329 | ||
330 | /* YYNTOKENS -- Number of terminals. */ | |
331 | #define YYNTOKENS ]b4_tokens_number[ | |
332 | /* YYNNTS -- Number of nonterminals. */ | |
333 | #define YYNNTS ]b4_nterms_number[ | |
334 | /* YYNRULES -- Number of rules. */ | |
335 | #define YYNRULES ]b4_rules_number[ | |
336 | /* YYNRULES -- Number of states. */ | |
337 | #define YYNSTATES ]b4_states_number[ | |
338 | /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ | |
339 | #define YYMAXRHS ]b4_r2_max[ | |
340 | /* YYMAXLEFT -- Maximum number of symbols to the left of a handle | |
341 | accessed by $0, $-1, etc., in any rule. */ | |
342 | #define YYMAXLEFT ]b4_max_left_semantic_context[ | |
343 | ||
344 | /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */ | |
345 | #define YYUNDEFTOK ]b4_undef_token_number[ | |
346 | #define YYMAXUTOK ]b4_user_token_number_max[ | |
347 | ||
348 | #define YYTRANSLATE(YYX) \ | |
349 | ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) | |
350 | ||
351 | /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ | |
352 | static const ]b4_int_type_for([b4_translate])[ yytranslate[] = | |
353 | { | |
354 | ]b4_translate[ | |
355 | }; | |
356 | ||
357 | #if YYDEBUG | |
358 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ | |
359 | static const ]b4_int_type_for([b4_rline])[ yyrline[] = | |
360 | { | |
361 | ]b4_rline[ | |
362 | }; | |
363 | #endif | |
364 | ||
365 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE | |
366 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. | |
367 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ | |
368 | static const char *const yytname[] = | |
369 | { | |
370 | ]b4_tname[ | |
371 | }; | |
372 | #endif | |
373 | ||
374 | #define YYPACT_NINF ]b4_pact_ninf[ | |
375 | #define YYTABLE_NINF ]b4_table_ninf[ | |
376 | ||
377 | ]b4_parser_tables_define[ | |
378 | ||
379 | /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ | |
380 | static const ]b4_int_type_for([b4_dprec])[ yydprec[] = | |
381 | { | |
382 | ]b4_dprec[ | |
383 | }; | |
384 | ||
385 | /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ | |
386 | static const ]b4_int_type_for([b4_merger])[ yymerger[] = | |
387 | { | |
388 | ]b4_merger[ | |
389 | }; | |
390 | ||
391 | /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as | |
392 | in the case of predicates. */ | |
393 | static const yybool yyimmediate[] = | |
394 | { | |
395 | ]b4_immediate[ | |
396 | }; | |
397 | ||
398 | /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of | |
399 | list of conflicting reductions corresponding to action entry for | |
400 | state STATE-NUM in yytable. 0 means no conflicts. The list in | |
401 | yyconfl is terminated by a rule number of 0. */ | |
402 | static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = | |
403 | { | |
404 | ]b4_conflict_list_heads[ | |
405 | }; | |
406 | ||
407 | /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by | |
408 | 0, pointed into by YYCONFLP. */ | |
409 | ]dnl Do not use b4_int_type_for here, since there are places where | |
410 | dnl pointers onto yyconfl are taken, which type is "short int *". | |
411 | dnl We probably ought to introduce a type for confl. | |
412 | [static const short int yyconfl[] = | |
413 | { | |
414 | ]b4_conflicting_rules[ | |
415 | }; | |
416 | \f | |
417 | /* Error token number */ | |
418 | #define YYTERROR 1 | |
419 | ||
420 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
421 | If N is 0, then set CURRENT to the empty location which ends | |
422 | the previous symbol: RHS[0] (always defined). */ | |
423 | ||
424 | ]b4_locations_if([[ | |
425 | #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) | |
426 | #ifndef YYLLOC_DEFAULT | |
427 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
428 | do \ | |
429 | if (YYID (N)) \ | |
430 | { \ | |
431 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ | |
432 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ | |
433 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ | |
434 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ | |
435 | } \ | |
436 | else \ | |
437 | { \ | |
438 | (Current).first_line = (Current).last_line = \ | |
439 | YYRHSLOC (Rhs, 0).last_line; \ | |
440 | (Current).first_column = (Current).last_column = \ | |
441 | YYRHSLOC (Rhs, 0).last_column; \ | |
442 | } \ | |
443 | while (YYID (0)) | |
444 | ||
445 | /* YY_LOCATION_PRINT -- Print the location on the stream. | |
446 | This macro was not mandated originally: define only if we know | |
447 | we won't break user code: when these are the locations we know. */ | |
448 | ||
449 | # define YY_LOCATION_PRINT(File, Loc) \ | |
450 | fprintf (File, "%d.%d-%d.%d", \ | |
451 | (Loc).first_line, (Loc).first_column, \ | |
452 | (Loc).last_line, (Loc).last_column) | |
453 | #endif | |
454 | ]],[ | |
455 | #ifndef YYLLOC_DEFAULT | |
456 | # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0) | |
457 | #endif | |
458 | ])[ | |
459 | ||
460 | #ifndef YY_LOCATION_PRINT | |
461 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) | |
462 | #endif | |
463 | ||
464 | ||
465 | /* YYLEX -- calling `yylex' with the right arguments. */ | |
466 | #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[ | |
467 | ||
468 | ]b4_pure_if( | |
469 | [ | |
470 | #undef yynerrs | |
471 | #define yynerrs (yystackp->yyerrcnt) | |
472 | #undef yychar | |
473 | #define yychar (yystackp->yyrawchar) | |
474 | #undef yylval | |
475 | #define yylval (yystackp->yyval) | |
476 | #undef yylloc | |
477 | #define yylloc (yystackp->yyloc) | |
478 | m4_if(b4_prefix[], [yy], [], | |
479 | [#define b4_prefix[]nerrs yynerrs | |
480 | #define b4_prefix[]char yychar | |
481 | #define b4_prefix[]lval yylval | |
482 | #define b4_prefix[]lloc yylloc])], | |
483 | [YYSTYPE yylval;]b4_locations_if([[ | |
484 | YYLTYPE yylloc;]])[ | |
485 | ||
486 | int yynerrs; | |
487 | int yychar;])[ | |
488 | ||
489 | static const int YYEOF = 0; | |
490 | static const int YYEMPTY = -2; | |
491 | ||
492 | typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; | |
493 | ||
494 | #define YYCHK(YYE) \ | |
495 | do { \ | |
496 | YYRESULTTAG yychk_flag = YYE; \ | |
497 | if (yychk_flag != yyok) \ | |
498 | return yychk_flag; \ | |
499 | } while (YYID (0)) | |
500 | ||
501 | #if YYDEBUG | |
502 | ||
503 | # ifndef YYFPRINTF | |
504 | # define YYFPRINTF fprintf | |
505 | # endif | |
506 | ||
507 | # define YYDPRINTF(Args) \ | |
508 | do { \ | |
509 | if (yydebug) \ | |
510 | YYFPRINTF Args; \ | |
511 | } while (YYID (0)) | |
512 | ||
513 | ]b4_yy_symbol_print_generate([b4_c_ansi_function_def])[ | |
514 | ||
515 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ | |
516 | do { \ | |
517 | if (yydebug) \ | |
518 | { \ | |
519 | YYFPRINTF (stderr, "%s ", Title); \ | |
520 | yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \ | |
521 | YYFPRINTF (stderr, "\n"); \ | |
522 | } \ | |
523 | } while (YYID (0)) | |
524 | ||
525 | /* Nonzero means print parse trace. It is left uninitialized so that | |
526 | multiple parsers can coexist. */ | |
527 | int yydebug; | |
528 | ||
529 | #else /* !YYDEBUG */ | |
530 | ||
531 | # define YYDPRINTF(Args) | |
532 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) | |
533 | ||
534 | #endif /* !YYDEBUG */ | |
535 | ||
536 | /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
537 | #ifndef YYINITDEPTH | |
538 | # define YYINITDEPTH ]b4_stack_depth_init[ | |
539 | #endif | |
540 | ||
541 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only | |
542 | if the built-in stack extension method is used). | |
543 | ||
544 | Do not make this value too large; the results are undefined if | |
545 | SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) | |
546 | evaluated with infinite-precision integer arithmetic. */ | |
547 | ||
548 | #ifndef YYMAXDEPTH | |
549 | # define YYMAXDEPTH ]b4_stack_depth_max[ | |
550 | #endif | |
551 | ||
552 | /* Minimum number of free items on the stack allowed after an | |
553 | allocation. This is to allow allocation and initialization | |
554 | to be completed by functions that call yyexpandGLRStack before the | |
555 | stack is expanded, thus insuring that all necessary pointers get | |
556 | properly redirected to new data. */ | |
557 | #define YYHEADROOM 2 | |
558 | ||
559 | #ifndef YYSTACKEXPANDABLE | |
560 | # define YYSTACKEXPANDABLE 1 | |
561 | #endif | |
562 | ||
563 | #if YYSTACKEXPANDABLE | |
564 | # define YY_RESERVE_GLRSTACK(Yystack) \ | |
565 | do { \ | |
566 | if (Yystack->yyspaceLeft < YYHEADROOM) \ | |
567 | yyexpandGLRStack (Yystack); \ | |
568 | } while (YYID (0)) | |
569 | #else | |
570 | # define YY_RESERVE_GLRSTACK(Yystack) \ | |
571 | do { \ | |
572 | if (Yystack->yyspaceLeft < YYHEADROOM) \ | |
573 | yyMemoryExhausted (Yystack); \ | |
574 | } while (YYID (0)) | |
575 | #endif | |
576 | ||
577 | ||
578 | #if YYERROR_VERBOSE | |
579 | ||
580 | # ifndef yystpcpy | |
581 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE | |
582 | # define yystpcpy stpcpy | |
583 | # else | |
584 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in | |
585 | YYDEST. */ | |
586 | static char * | |
587 | yystpcpy (char *yydest, const char *yysrc) | |
588 | { | |
589 | char *yyd = yydest; | |
590 | const char *yys = yysrc; | |
591 | ||
592 | while ((*yyd++ = *yys++) != '\0') | |
593 | continue; | |
594 | ||
595 | return yyd - 1; | |
596 | } | |
597 | # endif | |
598 | # endif | |
599 | ||
600 | # ifndef yytnamerr | |
601 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary | |
602 | quotes and backslashes, so that it's suitable for yyerror. The | |
603 | heuristic is that double-quoting is unnecessary unless the string | |
604 | contains an apostrophe, a comma, or backslash (other than | |
605 | backslash-backslash). YYSTR is taken from yytname. If YYRES is | |
606 | null, do not copy; instead, return the length of what the result | |
607 | would have been. */ | |
608 | static size_t | |
609 | yytnamerr (char *yyres, const char *yystr) | |
610 | { | |
611 | if (*yystr == '"') | |
612 | { | |
613 | size_t yyn = 0; | |
614 | char const *yyp = yystr; | |
615 | ||
616 | for (;;) | |
617 | switch (*++yyp) | |
618 | { | |
619 | case '\'': | |
620 | case ',': | |
621 | goto do_not_strip_quotes; | |
622 | ||
623 | case '\\': | |
624 | if (*++yyp != '\\') | |
625 | goto do_not_strip_quotes; | |
626 | /* Fall through. */ | |
627 | default: | |
628 | if (yyres) | |
629 | yyres[yyn] = *yyp; | |
630 | yyn++; | |
631 | break; | |
632 | ||
633 | case '"': | |
634 | if (yyres) | |
635 | yyres[yyn] = '\0'; | |
636 | return yyn; | |
637 | } | |
638 | do_not_strip_quotes: ; | |
639 | } | |
640 | ||
641 | if (! yyres) | |
642 | return strlen (yystr); | |
643 | ||
644 | return yystpcpy (yyres, yystr) - yyres; | |
645 | } | |
646 | # endif | |
647 | ||
648 | #endif /* !YYERROR_VERBOSE */ | |
649 | ||
650 | /** State numbers, as in LALR(1) machine */ | |
651 | typedef int yyStateNum; | |
652 | ||
653 | /** Rule numbers, as in LALR(1) machine */ | |
654 | typedef int yyRuleNum; | |
655 | ||
656 | /** Grammar symbol */ | |
657 | typedef int yySymbol; | |
658 | ||
659 | /** Item references, as in LALR(1) machine */ | |
660 | typedef short int yyItemNum; | |
661 | ||
662 | typedef struct yyGLRState yyGLRState; | |
663 | typedef struct yyGLRStateSet yyGLRStateSet; | |
664 | typedef struct yySemanticOption yySemanticOption; | |
665 | typedef union yyGLRStackItem yyGLRStackItem; | |
666 | typedef struct yyGLRStack yyGLRStack; | |
667 | ||
668 | struct yyGLRState { | |
669 | /** Type tag: always true. */ | |
670 | yybool yyisState; | |
671 | /** Type tag for yysemantics. If true, yysval applies, otherwise | |
672 | * yyfirstVal applies. */ | |
673 | yybool yyresolved; | |
674 | /** Number of corresponding LALR(1) machine state. */ | |
675 | yyStateNum yylrState; | |
676 | /** Preceding state in this stack */ | |
677 | yyGLRState* yypred; | |
678 | /** Source position of the last token produced by my symbol */ | |
679 | size_t yyposn; | |
680 | union { | |
681 | /** First in a chain of alternative reductions producing the | |
682 | * non-terminal corresponding to this state, threaded through | |
683 | * yynext. */ | |
684 | yySemanticOption* yyfirstVal; | |
685 | /** Semantic value for this state. */ | |
686 | YYSTYPE yysval; | |
687 | } yysemantics;]b4_locations_if([[ | |
688 | /** Source location for this state. */ | |
689 | YYLTYPE yyloc;]])[ | |
690 | }; | |
691 | ||
692 | struct yyGLRStateSet { | |
693 | yyGLRState** yystates; | |
694 | /** During nondeterministic operation, yylookaheadNeeds tracks which | |
695 | * stacks have actually needed the current lookahead. During deterministic | |
696 | * operation, yylookaheadNeeds[0] is not maintained since it would merely | |
697 | * duplicate yychar != YYEMPTY. */ | |
698 | yybool* yylookaheadNeeds; | |
699 | size_t yysize, yycapacity; | |
700 | }; | |
701 | ||
702 | struct yySemanticOption { | |
703 | /** Type tag: always false. */ | |
704 | yybool yyisState; | |
705 | /** Rule number for this reduction */ | |
706 | yyRuleNum yyrule; | |
707 | /** The last RHS state in the list of states to be reduced. */ | |
708 | yyGLRState* yystate; | |
709 | /** The lookahead for this reduction. */ | |
710 | int yyrawchar; | |
711 | YYSTYPE yyval;]b4_locations_if([[ | |
712 | YYLTYPE yyloc;]])[ | |
713 | /** Next sibling in chain of options. To facilitate merging, | |
714 | * options are chained in decreasing order by address. */ | |
715 | yySemanticOption* yynext; | |
716 | }; | |
717 | ||
718 | /** Type of the items in the GLR stack. The yyisState field | |
719 | * indicates which item of the union is valid. */ | |
720 | union yyGLRStackItem { | |
721 | yyGLRState yystate; | |
722 | yySemanticOption yyoption; | |
723 | }; | |
724 | ||
725 | struct yyGLRStack { | |
726 | int yyerrState; | |
727 | ]b4_locations_if([[ /* To compute the location of the error token. */ | |
728 | yyGLRStackItem yyerror_range[3];]])[ | |
729 | ]b4_pure_if( | |
730 | [ | |
731 | int yyerrcnt; | |
732 | int yyrawchar; | |
733 | YYSTYPE yyval;]b4_locations_if([[ | |
734 | YYLTYPE yyloc;]])[ | |
735 | ])[ | |
736 | YYJMP_BUF yyexception_buffer; | |
737 | yyGLRStackItem* yyitems; | |
738 | yyGLRStackItem* yynextFree; | |
739 | size_t yyspaceLeft; | |
740 | yyGLRState* yysplitPoint; | |
741 | yyGLRState* yylastDeleted; | |
742 | yyGLRStateSet yytops; | |
743 | }; | |
744 | ||
745 | #if YYSTACKEXPANDABLE | |
746 | static void yyexpandGLRStack (yyGLRStack* yystackp); | |
747 | #endif | |
748 | ||
749 | static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) | |
750 | __attribute__ ((__noreturn__)); | |
751 | static void | |
752 | yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) | |
753 | { | |
754 | if (yymsg != YY_NULL) | |
755 | yyerror (]b4_yyerror_args[yymsg); | |
756 | YYLONGJMP (yystackp->yyexception_buffer, 1); | |
757 | } | |
758 | ||
759 | static void yyMemoryExhausted (yyGLRStack* yystackp) | |
760 | __attribute__ ((__noreturn__)); | |
761 | static void | |
762 | yyMemoryExhausted (yyGLRStack* yystackp) | |
763 | { | |
764 | YYLONGJMP (yystackp->yyexception_buffer, 2); | |
765 | } | |
766 | ||
767 | #if YYDEBUG || YYERROR_VERBOSE | |
768 | /** A printable representation of TOKEN. */ | |
769 | static inline const char* | |
770 | yytokenName (yySymbol yytoken) | |
771 | { | |
772 | if (yytoken == YYEMPTY) | |
773 | return ""; | |
774 | ||
775 | return yytname[yytoken]; | |
776 | } | |
777 | #endif | |
778 | ||
779 | /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting | |
780 | * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred | |
781 | * containing the pointer to the next state in the chain. */ | |
782 | static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__)); | |
783 | static void | |
784 | yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) | |
785 | { | |
786 | int i; | |
787 | yyGLRState *s = yyvsp[yylow0].yystate.yypred; | |
788 | for (i = yylow0-1; i >= yylow1; i -= 1) | |
789 | { | |
790 | #if YYDEBUG | |
791 | yyvsp[i].yystate.yylrState = s->yylrState; | |
792 | #endif | |
793 | yyvsp[i].yystate.yyresolved = s->yyresolved; | |
794 | if (s->yyresolved) | |
795 | yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval; | |
796 | else | |
797 | /* The effect of using yysval or yyloc (in an immediate rule) is | |
798 | * undefined. */ | |
799 | yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULL;]b4_locations_if([[ | |
800 | yyvsp[i].yystate.yyloc = s->yyloc;]])[ | |
801 | s = yyvsp[i].yystate.yypred = s->yypred; | |
802 | } | |
803 | } | |
804 | ||
805 | /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in | |
806 | * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. | |
807 | * For convenience, always return YYLOW1. */ | |
808 | static inline int yyfill (yyGLRStackItem *, int *, int, yybool) | |
809 | __attribute__ ((__unused__)); | |
810 | static inline int | |
811 | yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) | |
812 | { | |
813 | if (!yynormal && yylow1 < *yylow) | |
814 | { | |
815 | yyfillin (yyvsp, *yylow, yylow1); | |
816 | *yylow = yylow1; | |
817 | } | |
818 | return yylow1; | |
819 | } | |
820 | ||
821 | /** Perform user action for rule number YYN, with RHS length YYRHSLEN, | |
822 | * and top stack item YYVSP. YYLVALP points to place to put semantic | |
823 | * value ($$), and yylocp points to place for location information | |
824 | * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, | |
825 | * yyerr for YYERROR, yyabort for YYABORT. */ | |
826 | /*ARGSUSED*/ static YYRESULTTAG | |
827 | yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, | |
828 | yyGLRStack* yystackp, | |
829 | YYSTYPE* yyvalp]b4_locuser_formals[) | |
830 | { | |
831 | yybool yynormal __attribute__ ((__unused__)) = | |
832 | (yystackp->yysplitPoint == YY_NULL); | |
833 | int yylow; | |
834 | ]b4_parse_param_use([yyvalp], [yylocp])dnl | |
835 | [# undef yyerrok | |
836 | # define yyerrok (yystackp->yyerrState = 0) | |
837 | # undef YYACCEPT | |
838 | # define YYACCEPT return yyaccept | |
839 | # undef YYABORT | |
840 | # define YYABORT return yyabort | |
841 | # undef YYERROR | |
842 | # define YYERROR return yyerrok, yyerr | |
843 | # undef YYRECOVERING | |
844 | # define YYRECOVERING() (yystackp->yyerrState != 0) | |
845 | # undef yyclearin | |
846 | # define yyclearin (yychar = YYEMPTY) | |
847 | # undef YYFILL | |
848 | # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal) | |
849 | # undef YYBACKUP | |
850 | # define YYBACKUP(Token, Value) \ | |
851 | return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ | |
852 | yyerrok, yyerr | |
853 | ||
854 | yylow = 1; | |
855 | if (yyrhslen == 0) | |
856 | *yyvalp = yyval_default; | |
857 | else | |
858 | *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[ | |
859 | YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); | |
860 | yystackp->yyerror_range[1].yystate.yyloc = *yylocp; | |
861 | ]])[ | |
862 | switch (yyn) | |
863 | { | |
864 | ]b4_user_actions[ | |
865 | default: break; | |
866 | } | |
867 | ||
868 | return yyok; | |
869 | # undef yyerrok | |
870 | # undef YYABORT | |
871 | # undef YYACCEPT | |
872 | # undef YYERROR | |
873 | # undef YYBACKUP | |
874 | # undef yyclearin | |
875 | # undef YYRECOVERING | |
876 | } | |
877 | \f | |
878 | ||
879 | /*ARGSUSED*/ static void | |
880 | yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) | |
881 | { | |
882 | YYUSE (yy0); | |
883 | YYUSE (yy1); | |
884 | ||
885 | switch (yyn) | |
886 | { | |
887 | ]b4_mergers[ | |
888 | default: break; | |
889 | } | |
890 | } | |
891 | ||
892 | /* Bison grammar-table manipulation. */ | |
893 | ||
894 | ]b4_yydestruct_generate([b4_c_ansi_function_def])[ | |
895 | ||
896 | /** Number of symbols composing the right hand side of rule #RULE. */ | |
897 | static inline int | |
898 | yyrhsLength (yyRuleNum yyrule) | |
899 | { | |
900 | return yyr2[yyrule]; | |
901 | } | |
902 | ||
903 | static void | |
904 | yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) | |
905 | { | |
906 | if (yys->yyresolved) | |
907 | yydestruct (yymsg, yystos[yys->yylrState], | |
908 | &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[); | |
909 | else | |
910 | { | |
911 | #if YYDEBUG | |
912 | if (yydebug) | |
913 | { | |
914 | if (yys->yysemantics.yyfirstVal) | |
915 | YYFPRINTF (stderr, "%s unresolved ", yymsg); | |
916 | else | |
917 | YYFPRINTF (stderr, "%s incomplete ", yymsg); | |
918 | yy_symbol_print (stderr, yystos[yys->yylrState], | |
919 | YY_NULL]b4_locuser_args([&yys->yyloc])[); | |
920 | YYFPRINTF (stderr, "\n"); | |
921 | } | |
922 | #endif | |
923 | ||
924 | if (yys->yysemantics.yyfirstVal) | |
925 | { | |
926 | yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; | |
927 | yyGLRState *yyrh; | |
928 | int yyn; | |
929 | for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); | |
930 | yyn > 0; | |
931 | yyrh = yyrh->yypred, yyn -= 1) | |
932 | yydestroyGLRState (yymsg, yyrh]b4_user_args[); | |
933 | } | |
934 | } | |
935 | } | |
936 | ||
937 | /** Left-hand-side symbol for rule #YYRULE. */ | |
938 | static inline yySymbol | |
939 | yylhsNonterm (yyRuleNum yyrule) | |
940 | { | |
941 | return yyr1[yyrule]; | |
942 | } | |
943 | ||
944 | #define yypact_value_is_default(yystate) \ | |
945 | ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[ | |
946 | ||
947 | /** True iff LR state YYSTATE has only a default reduction (regardless | |
948 | * of token). */ | |
949 | static inline yybool | |
950 | yyisDefaultedState (yyStateNum yystate) | |
951 | { | |
952 | return yypact_value_is_default (yypact[yystate]); | |
953 | } | |
954 | ||
955 | /** The default reduction for YYSTATE, assuming it has one. */ | |
956 | static inline yyRuleNum | |
957 | yydefaultAction (yyStateNum yystate) | |
958 | { | |
959 | return yydefact[yystate]; | |
960 | } | |
961 | ||
962 | #define yytable_value_is_error(yytable_value) \ | |
963 | ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[ | |
964 | ||
965 | /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. | |
966 | * Result R means | |
967 | * R < 0: Reduce on rule -R. | |
968 | * R = 0: Error. | |
969 | * R > 0: Shift to state R. | |
970 | * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list | |
971 | * of conflicting reductions. | |
972 | */ | |
973 | static inline void | |
974 | yygetLRActions (yyStateNum yystate, int yytoken, | |
975 | int* yyaction, const short int** yyconflicts) | |
976 | { | |
977 | int yyindex = yypact[yystate] + yytoken; | |
978 | if (yypact_value_is_default (yypact[yystate]) | |
979 | || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) | |
980 | { | |
981 | *yyaction = -yydefact[yystate]; | |
982 | *yyconflicts = yyconfl; | |
983 | } | |
984 | else if (! yytable_value_is_error (yytable[yyindex])) | |
985 | { | |
986 | *yyaction = yytable[yyindex]; | |
987 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
988 | } | |
989 | else | |
990 | { | |
991 | *yyaction = 0; | |
992 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
993 | } | |
994 | } | |
995 | ||
996 | static inline yyStateNum | |
997 | yyLRgotoState (yyStateNum yystate, yySymbol yylhs) | |
998 | { | |
999 | int yyr = yypgoto[yylhs - YYNTOKENS] + yystate; | |
1000 | if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) | |
1001 | return yytable[yyr]; | |
1002 | else | |
1003 | return yydefgoto[yylhs - YYNTOKENS]; | |
1004 | } | |
1005 | ||
1006 | static inline yybool | |
1007 | yyisShiftAction (int yyaction) | |
1008 | { | |
1009 | return 0 < yyaction; | |
1010 | } | |
1011 | ||
1012 | static inline yybool | |
1013 | yyisErrorAction (int yyaction) | |
1014 | { | |
1015 | return yyaction == 0; | |
1016 | } | |
1017 | ||
1018 | /* GLRStates */ | |
1019 | ||
1020 | /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state | |
1021 | * if YYISSTATE, and otherwise a semantic option. Callers should call | |
1022 | * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient | |
1023 | * headroom. */ | |
1024 | ||
1025 | static inline yyGLRStackItem* | |
1026 | yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState) | |
1027 | { | |
1028 | yyGLRStackItem* yynewItem = yystackp->yynextFree; | |
1029 | yystackp->yyspaceLeft -= 1; | |
1030 | yystackp->yynextFree += 1; | |
1031 | yynewItem->yystate.yyisState = yyisState; | |
1032 | return yynewItem; | |
1033 | } | |
1034 | ||
1035 | /** Add a new semantic action that will execute the action for rule | |
1036 | * YYRULE on the semantic values in YYRHS to the list of | |
1037 | * alternative actions for YYSTATE. Assumes that YYRHS comes from | |
1038 | * stack #YYK of *YYSTACKP. */ | |
1039 | static void | |
1040 | yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate, | |
1041 | yyGLRState* yyrhs, yyRuleNum yyrule) | |
1042 | { | |
1043 | yySemanticOption* yynewOption = | |
1044 | &yynewGLRStackItem (yystackp, yyfalse)->yyoption; | |
1045 | yynewOption->yystate = yyrhs; | |
1046 | yynewOption->yyrule = yyrule; | |
1047 | if (yystackp->yytops.yylookaheadNeeds[yyk]) | |
1048 | { | |
1049 | yynewOption->yyrawchar = yychar; | |
1050 | yynewOption->yyval = yylval;]b4_locations_if([ | |
1051 | yynewOption->yyloc = yylloc;])[ | |
1052 | } | |
1053 | else | |
1054 | yynewOption->yyrawchar = YYEMPTY; | |
1055 | yynewOption->yynext = yystate->yysemantics.yyfirstVal; | |
1056 | yystate->yysemantics.yyfirstVal = yynewOption; | |
1057 | ||
1058 | YY_RESERVE_GLRSTACK (yystackp); | |
1059 | } | |
1060 | ||
1061 | /* GLRStacks */ | |
1062 | ||
1063 | /** Initialize YYSET to a singleton set containing an empty stack. */ | |
1064 | static yybool | |
1065 | yyinitStateSet (yyGLRStateSet* yyset) | |
1066 | { | |
1067 | yyset->yysize = 1; | |
1068 | yyset->yycapacity = 16; | |
1069 | yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]); | |
1070 | if (! yyset->yystates) | |
1071 | return yyfalse; | |
1072 | yyset->yystates[0] = YY_NULL; | |
1073 | yyset->yylookaheadNeeds = | |
1074 | (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]); | |
1075 | if (! yyset->yylookaheadNeeds) | |
1076 | { | |
1077 | YYFREE (yyset->yystates); | |
1078 | return yyfalse; | |
1079 | } | |
1080 | return yytrue; | |
1081 | } | |
1082 | ||
1083 | static void yyfreeStateSet (yyGLRStateSet* yyset) | |
1084 | { | |
1085 | YYFREE (yyset->yystates); | |
1086 | YYFREE (yyset->yylookaheadNeeds); | |
1087 | } | |
1088 | ||
1089 | /** Initialize *YYSTACKP to a single empty stack, with total maximum | |
1090 | * capacity for all stacks of YYSIZE. */ | |
1091 | static yybool | |
1092 | yyinitGLRStack (yyGLRStack* yystackp, size_t yysize) | |
1093 | { | |
1094 | yystackp->yyerrState = 0; | |
1095 | yynerrs = 0; | |
1096 | yystackp->yyspaceLeft = yysize; | |
1097 | yystackp->yyitems = | |
1098 | (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]); | |
1099 | if (!yystackp->yyitems) | |
1100 | return yyfalse; | |
1101 | yystackp->yynextFree = yystackp->yyitems; | |
1102 | yystackp->yysplitPoint = YY_NULL; | |
1103 | yystackp->yylastDeleted = YY_NULL; | |
1104 | return yyinitStateSet (&yystackp->yytops); | |
1105 | } | |
1106 | ||
1107 | ||
1108 | #if YYSTACKEXPANDABLE | |
1109 | # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ | |
1110 | &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE | |
1111 | ||
1112 | /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the | |
1113 | stack from outside should be considered invalid after this call. | |
1114 | We always expand when there are 1 or fewer items left AFTER an | |
1115 | allocation, so that we can avoid having external pointers exist | |
1116 | across an allocation. */ | |
1117 | static void | |
1118 | yyexpandGLRStack (yyGLRStack* yystackp) | |
1119 | { | |
1120 | yyGLRStackItem* yynewItems; | |
1121 | yyGLRStackItem* yyp0, *yyp1; | |
1122 | size_t yynewSize; | |
1123 | size_t yyn; | |
1124 | size_t yysize = yystackp->yynextFree - yystackp->yyitems; | |
1125 | if (YYMAXDEPTH - YYHEADROOM < yysize) | |
1126 | yyMemoryExhausted (yystackp); | |
1127 | yynewSize = 2*yysize; | |
1128 | if (YYMAXDEPTH < yynewSize) | |
1129 | yynewSize = YYMAXDEPTH; | |
1130 | yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]); | |
1131 | if (! yynewItems) | |
1132 | yyMemoryExhausted (yystackp); | |
1133 | for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize; | |
1134 | 0 < yyn; | |
1135 | yyn -= 1, yyp0 += 1, yyp1 += 1) | |
1136 | { | |
1137 | *yyp1 = *yyp0; | |
1138 | if (*(yybool *) yyp0) | |
1139 | { | |
1140 | yyGLRState* yys0 = &yyp0->yystate; | |
1141 | yyGLRState* yys1 = &yyp1->yystate; | |
1142 | if (yys0->yypred != YY_NULL) | |
1143 | yys1->yypred = | |
1144 | YYRELOC (yyp0, yyp1, yys0->yypred, yystate); | |
1145 | if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL) | |
1146 | yys1->yysemantics.yyfirstVal = | |
1147 | YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); | |
1148 | } | |
1149 | else | |
1150 | { | |
1151 | yySemanticOption* yyv0 = &yyp0->yyoption; | |
1152 | yySemanticOption* yyv1 = &yyp1->yyoption; | |
1153 | if (yyv0->yystate != YY_NULL) | |
1154 | yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); | |
1155 | if (yyv0->yynext != YY_NULL) | |
1156 | yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); | |
1157 | } | |
1158 | } | |
1159 | if (yystackp->yysplitPoint != YY_NULL) | |
1160 | yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems, | |
1161 | yystackp->yysplitPoint, yystate); | |
1162 | ||
1163 | for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1) | |
1164 | if (yystackp->yytops.yystates[yyn] != YY_NULL) | |
1165 | yystackp->yytops.yystates[yyn] = | |
1166 | YYRELOC (yystackp->yyitems, yynewItems, | |
1167 | yystackp->yytops.yystates[yyn], yystate); | |
1168 | YYFREE (yystackp->yyitems); | |
1169 | yystackp->yyitems = yynewItems; | |
1170 | yystackp->yynextFree = yynewItems + yysize; | |
1171 | yystackp->yyspaceLeft = yynewSize - yysize; | |
1172 | } | |
1173 | #endif | |
1174 | ||
1175 | static void | |
1176 | yyfreeGLRStack (yyGLRStack* yystackp) | |
1177 | { | |
1178 | YYFREE (yystackp->yyitems); | |
1179 | yyfreeStateSet (&yystackp->yytops); | |
1180 | } | |
1181 | ||
1182 | /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the | |
1183 | * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as | |
1184 | * YYS. */ | |
1185 | static inline void | |
1186 | yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys) | |
1187 | { | |
1188 | if (yystackp->yysplitPoint != YY_NULL && yystackp->yysplitPoint > yys) | |
1189 | yystackp->yysplitPoint = yys; | |
1190 | } | |
1191 | ||
1192 | /** Invalidate stack #YYK in *YYSTACKP. */ | |
1193 | static inline void | |
1194 | yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk) | |
1195 | { | |
1196 | if (yystackp->yytops.yystates[yyk] != YY_NULL) | |
1197 | yystackp->yylastDeleted = yystackp->yytops.yystates[yyk]; | |
1198 | yystackp->yytops.yystates[yyk] = YY_NULL; | |
1199 | } | |
1200 | ||
1201 | /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can | |
1202 | only be done once after a deletion, and only when all other stacks have | |
1203 | been deleted. */ | |
1204 | static void | |
1205 | yyundeleteLastStack (yyGLRStack* yystackp) | |
1206 | { | |
1207 | if (yystackp->yylastDeleted == YY_NULL || yystackp->yytops.yysize != 0) | |
1208 | return; | |
1209 | yystackp->yytops.yystates[0] = yystackp->yylastDeleted; | |
1210 | yystackp->yytops.yysize = 1; | |
1211 | YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); | |
1212 | yystackp->yylastDeleted = YY_NULL; | |
1213 | } | |
1214 | ||
1215 | static inline void | |
1216 | yyremoveDeletes (yyGLRStack* yystackp) | |
1217 | { | |
1218 | size_t yyi, yyj; | |
1219 | yyi = yyj = 0; | |
1220 | while (yyj < yystackp->yytops.yysize) | |
1221 | { | |
1222 | if (yystackp->yytops.yystates[yyi] == YY_NULL) | |
1223 | { | |
1224 | if (yyi == yyj) | |
1225 | { | |
1226 | YYDPRINTF ((stderr, "Removing dead stacks.\n")); | |
1227 | } | |
1228 | yystackp->yytops.yysize -= 1; | |
1229 | } | |
1230 | else | |
1231 | { | |
1232 | yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi]; | |
1233 | /* In the current implementation, it's unnecessary to copy | |
1234 | yystackp->yytops.yylookaheadNeeds[yyi] since, after | |
1235 | yyremoveDeletes returns, the parser immediately either enters | |
1236 | deterministic operation or shifts a token. However, it doesn't | |
1237 | hurt, and the code might evolve to need it. */ | |
1238 | yystackp->yytops.yylookaheadNeeds[yyj] = | |
1239 | yystackp->yytops.yylookaheadNeeds[yyi]; | |
1240 | if (yyj != yyi) | |
1241 | { | |
1242 | YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n", | |
1243 | (unsigned long int) yyi, (unsigned long int) yyj)); | |
1244 | } | |
1245 | yyj += 1; | |
1246 | } | |
1247 | yyi += 1; | |
1248 | } | |
1249 | } | |
1250 | ||
1251 | /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR | |
1252 | * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic | |
1253 | * value *YYVALP and source location *YYLOCP. */ | |
1254 | static inline void | |
1255 | yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, | |
1256 | size_t yyposn, | |
1257 | YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[) | |
1258 | { | |
1259 | yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; | |
1260 | ||
1261 | yynewState->yylrState = yylrState; | |
1262 | yynewState->yyposn = yyposn; | |
1263 | yynewState->yyresolved = yytrue; | |
1264 | yynewState->yypred = yystackp->yytops.yystates[yyk]; | |
1265 | yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([ | |
1266 | yynewState->yyloc = *yylocp;])[ | |
1267 | yystackp->yytops.yystates[yyk] = yynewState; | |
1268 | ||
1269 | YY_RESERVE_GLRSTACK (yystackp); | |
1270 | } | |
1271 | ||
1272 | /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR | |
1273 | * state YYLRSTATE, at input position YYPOSN, with the (unresolved) | |
1274 | * semantic value of YYRHS under the action for YYRULE. */ | |
1275 | static inline void | |
1276 | yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, | |
1277 | size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule) | |
1278 | { | |
1279 | yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; | |
1280 | ||
1281 | yynewState->yylrState = yylrState; | |
1282 | yynewState->yyposn = yyposn; | |
1283 | yynewState->yyresolved = yyfalse; | |
1284 | yynewState->yypred = yystackp->yytops.yystates[yyk]; | |
1285 | yynewState->yysemantics.yyfirstVal = YY_NULL; | |
1286 | yystackp->yytops.yystates[yyk] = yynewState; | |
1287 | ||
1288 | /* Invokes YY_RESERVE_GLRSTACK. */ | |
1289 | yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule); | |
1290 | } | |
1291 | ||
1292 | #if !YYDEBUG | |
1293 | # define YY_REDUCE_PRINT(Args) | |
1294 | #else | |
1295 | # define YY_REDUCE_PRINT(Args) \ | |
1296 | do { \ | |
1297 | if (yydebug) \ | |
1298 | yy_reduce_print Args; \ | |
1299 | } while (YYID (0)) | |
1300 | ||
1301 | /*----------------------------------------------------------------------. | |
1302 | | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | | |
1303 | `----------------------------------------------------------------------*/ | |
1304 | ||
1305 | /*ARGSUSED*/ static inline void | |
1306 | yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk, | |
1307 | yyRuleNum yyrule]b4_user_formals[) | |
1308 | { | |
1309 | int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ | |
1310 | int yylow = 1;])[ | |
1311 | int yyi; | |
1312 | YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n", | |
1313 | (unsigned long int) yyk, yyrule - 1, | |
1314 | (unsigned long int) yyrline[yyrule]); | |
1315 | if (! yynormal) | |
1316 | yyfillin (yyvsp, 1, -yynrhs); | |
1317 | /* The symbols being reduced. */ | |
1318 | for (yyi = 0; yyi < yynrhs; yyi++) | |
1319 | { | |
1320 | YYFPRINTF (stderr, " $%d = ", yyi + 1); | |
1321 | yy_symbol_print (stderr, | |
1322 | yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState], | |
1323 | &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval | |
1324 | ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl | |
1325 | b4_user_args[); | |
1326 | if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved) | |
1327 | YYFPRINTF (stderr, " (unresolved)"); | |
1328 | YYFPRINTF (stderr, "\n"); | |
1329 | } | |
1330 | } | |
1331 | #endif | |
1332 | ||
1333 | /** Pop the symbols consumed by reduction #YYRULE from the top of stack | |
1334 | * #YYK of *YYSTACKP, and perform the appropriate semantic action on their | |
1335 | * semantic values. Assumes that all ambiguities in semantic values | |
1336 | * have been previously resolved. Set *YYVALP to the resulting value, | |
1337 | * and *YYLOCP to the computed location (if any). Return value is as | |
1338 | * for userAction. */ | |
1339 | static inline YYRESULTTAG | |
1340 | yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, | |
1341 | YYSTYPE* yyvalp]b4_locuser_formals[) | |
1342 | { | |
1343 | int yynrhs = yyrhsLength (yyrule); | |
1344 | ||
1345 | if (yystackp->yysplitPoint == YY_NULL) | |
1346 | { | |
1347 | /* Standard special case: single stack. */ | |
1348 | yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; | |
1349 | YYASSERT (yyk == 0); | |
1350 | yystackp->yynextFree -= yynrhs; | |
1351 | yystackp->yyspaceLeft += yynrhs; | |
1352 | yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; | |
1353 | YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[)); | |
1354 | return yyuserAction (yyrule, yynrhs, yyrhs, yystackp, | |
1355 | yyvalp]b4_locuser_args[); | |
1356 | } | |
1357 | else | |
1358 | { | |
1359 | int yyi; | |
1360 | yyGLRState* yys; | |
1361 | yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; | |
1362 | yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred | |
1363 | = yystackp->yytops.yystates[yyk];]b4_locations_if([[ | |
1364 | if (yynrhs == 0) | |
1365 | /* Set default location. */ | |
1366 | yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[ | |
1367 | for (yyi = 0; yyi < yynrhs; yyi += 1) | |
1368 | { | |
1369 | yys = yys->yypred; | |
1370 | YYASSERT (yys); | |
1371 | } | |
1372 | yyupdateSplit (yystackp, yys); | |
1373 | yystackp->yytops.yystates[yyk] = yys; | |
1374 | YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[)); | |
1375 | return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, | |
1376 | yystackp, yyvalp]b4_locuser_args[); | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, | |
1381 | * and push back on the resulting nonterminal symbol. Perform the | |
1382 | * semantic action associated with YYRULE and store its value with the | |
1383 | * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently | |
1384 | * unambiguous. Otherwise, store the deferred semantic action with | |
1385 | * the new state. If the new state would have an identical input | |
1386 | * position, LR state, and predecessor to an existing state on the stack, | |
1387 | * it is identified with that existing state, eliminating stack #YYK from | |
1388 | * *YYSTACKP. In this case, the semantic value is | |
1389 | * added to the options for the existing state's semantic value. | |
1390 | */ | |
1391 | static inline YYRESULTTAG | |
1392 | yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, | |
1393 | yybool yyforceEval]b4_user_formals[) | |
1394 | { | |
1395 | size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn; | |
1396 | ||
1397 | if (yyforceEval || yystackp->yysplitPoint == YY_NULL) | |
1398 | { | |
1399 | YYRESULTTAG yyflag; | |
1400 | YYSTYPE yysval;]b4_locations_if([ | |
1401 | YYLTYPE yyloc;])[ | |
1402 | ||
1403 | yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[); | |
1404 | if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULL) | |
1405 | { | |
1406 | YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n", | |
1407 | (unsigned long int) yyk, yyrule - 1)); | |
1408 | } | |
1409 | if (yyflag != yyok) | |
1410 | return yyflag; | |
1411 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc); | |
1412 | yyglrShift (yystackp, yyk, | |
1413 | yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState, | |
1414 | yylhsNonterm (yyrule)), | |
1415 | yyposn, &yysval]b4_locations_if([, &yyloc])[); | |
1416 | } | |
1417 | else | |
1418 | { | |
1419 | size_t yyi; | |
1420 | int yyn; | |
1421 | yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk]; | |
1422 | yyStateNum yynewLRState; | |
1423 | ||
1424 | for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); | |
1425 | 0 < yyn; yyn -= 1) | |
1426 | { | |
1427 | yys = yys->yypred; | |
1428 | YYASSERT (yys); | |
1429 | } | |
1430 | yyupdateSplit (yystackp, yys); | |
1431 | yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); | |
1432 | YYDPRINTF ((stderr, | |
1433 | "Reduced stack %lu by rule #%d; action deferred. " | |
1434 | "Now in state %d.\n", | |
1435 | (unsigned long int) yyk, yyrule - 1, yynewLRState)); | |
1436 | for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) | |
1437 | if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL) | |
1438 | { | |
1439 | yyGLRState *yysplit = yystackp->yysplitPoint; | |
1440 | yyGLRState *yyp = yystackp->yytops.yystates[yyi]; | |
1441 | while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) | |
1442 | { | |
1443 | if (yyp->yylrState == yynewLRState && yyp->yypred == yys) | |
1444 | { | |
1445 | yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule); | |
1446 | yymarkStackDeleted (yystackp, yyk); | |
1447 | YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n", | |
1448 | (unsigned long int) yyk, | |
1449 | (unsigned long int) yyi)); | |
1450 | return yyok; | |
1451 | } | |
1452 | yyp = yyp->yypred; | |
1453 | } | |
1454 | } | |
1455 | yystackp->yytops.yystates[yyk] = yys; | |
1456 | yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule); | |
1457 | } | |
1458 | return yyok; | |
1459 | } | |
1460 | ||
1461 | static size_t | |
1462 | yysplitStack (yyGLRStack* yystackp, size_t yyk) | |
1463 | { | |
1464 | if (yystackp->yysplitPoint == YY_NULL) | |
1465 | { | |
1466 | YYASSERT (yyk == 0); | |
1467 | yystackp->yysplitPoint = yystackp->yytops.yystates[yyk]; | |
1468 | } | |
1469 | if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity) | |
1470 | { | |
1471 | yyGLRState** yynewStates; | |
1472 | yybool* yynewLookaheadNeeds; | |
1473 | ||
1474 | yynewStates = YY_NULL; | |
1475 | ||
1476 | if (yystackp->yytops.yycapacity | |
1477 | > (YYSIZEMAX / (2 * sizeof yynewStates[0]))) | |
1478 | yyMemoryExhausted (yystackp); | |
1479 | yystackp->yytops.yycapacity *= 2; | |
1480 | ||
1481 | yynewStates = | |
1482 | (yyGLRState**) YYREALLOC (yystackp->yytops.yystates, | |
1483 | (yystackp->yytops.yycapacity | |
1484 | * sizeof yynewStates[0])); | |
1485 | if (yynewStates == YY_NULL) | |
1486 | yyMemoryExhausted (yystackp); | |
1487 | yystackp->yytops.yystates = yynewStates; | |
1488 | ||
1489 | yynewLookaheadNeeds = | |
1490 | (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds, | |
1491 | (yystackp->yytops.yycapacity | |
1492 | * sizeof yynewLookaheadNeeds[0])); | |
1493 | if (yynewLookaheadNeeds == YY_NULL) | |
1494 | yyMemoryExhausted (yystackp); | |
1495 | yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds; | |
1496 | } | |
1497 | yystackp->yytops.yystates[yystackp->yytops.yysize] | |
1498 | = yystackp->yytops.yystates[yyk]; | |
1499 | yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize] | |
1500 | = yystackp->yytops.yylookaheadNeeds[yyk]; | |
1501 | yystackp->yytops.yysize += 1; | |
1502 | return yystackp->yytops.yysize-1; | |
1503 | } | |
1504 | ||
1505 | /** True iff YYY0 and YYY1 represent identical options at the top level. | |
1506 | * That is, they represent the same rule applied to RHS symbols | |
1507 | * that produce the same terminal symbols. */ | |
1508 | static yybool | |
1509 | yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) | |
1510 | { | |
1511 | if (yyy0->yyrule == yyy1->yyrule) | |
1512 | { | |
1513 | yyGLRState *yys0, *yys1; | |
1514 | int yyn; | |
1515 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, | |
1516 | yyn = yyrhsLength (yyy0->yyrule); | |
1517 | yyn > 0; | |
1518 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1519 | if (yys0->yyposn != yys1->yyposn) | |
1520 | return yyfalse; | |
1521 | return yytrue; | |
1522 | } | |
1523 | else | |
1524 | return yyfalse; | |
1525 | } | |
1526 | ||
1527 | /** Assuming identicalOptions (YYY0,YYY1), destructively merge the | |
1528 | * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ | |
1529 | static void | |
1530 | yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) | |
1531 | { | |
1532 | yyGLRState *yys0, *yys1; | |
1533 | int yyn; | |
1534 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, | |
1535 | yyn = yyrhsLength (yyy0->yyrule); | |
1536 | yyn > 0; | |
1537 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1538 | { | |
1539 | if (yys0 == yys1) | |
1540 | break; | |
1541 | else if (yys0->yyresolved) | |
1542 | { | |
1543 | yys1->yyresolved = yytrue; | |
1544 | yys1->yysemantics.yysval = yys0->yysemantics.yysval; | |
1545 | } | |
1546 | else if (yys1->yyresolved) | |
1547 | { | |
1548 | yys0->yyresolved = yytrue; | |
1549 | yys0->yysemantics.yysval = yys1->yysemantics.yysval; | |
1550 | } | |
1551 | else | |
1552 | { | |
1553 | yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal; | |
1554 | yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal; | |
1555 | while (YYID (yytrue)) | |
1556 | { | |
1557 | if (yyz1 == *yyz0p || yyz1 == YY_NULL) | |
1558 | break; | |
1559 | else if (*yyz0p == YY_NULL) | |
1560 | { | |
1561 | *yyz0p = yyz1; | |
1562 | break; | |
1563 | } | |
1564 | else if (*yyz0p < yyz1) | |
1565 | { | |
1566 | yySemanticOption* yyz = *yyz0p; | |
1567 | *yyz0p = yyz1; | |
1568 | yyz1 = yyz1->yynext; | |
1569 | (*yyz0p)->yynext = yyz; | |
1570 | } | |
1571 | yyz0p = &(*yyz0p)->yynext; | |
1572 | } | |
1573 | yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal; | |
1574 | } | |
1575 | } | |
1576 | } | |
1577 | ||
1578 | /** Y0 and Y1 represent two possible actions to take in a given | |
1579 | * parsing state; return 0 if no combination is possible, | |
1580 | * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ | |
1581 | static int | |
1582 | yypreference (yySemanticOption* y0, yySemanticOption* y1) | |
1583 | { | |
1584 | yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; | |
1585 | int p0 = yydprec[r0], p1 = yydprec[r1]; | |
1586 | ||
1587 | if (p0 == p1) | |
1588 | { | |
1589 | if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) | |
1590 | return 0; | |
1591 | else | |
1592 | return 1; | |
1593 | } | |
1594 | if (p0 == 0 || p1 == 0) | |
1595 | return 0; | |
1596 | if (p0 < p1) | |
1597 | return 3; | |
1598 | if (p1 < p0) | |
1599 | return 2; | |
1600 | return 0; | |
1601 | } | |
1602 | ||
1603 | static YYRESULTTAG yyresolveValue (yyGLRState* yys, | |
1604 | yyGLRStack* yystackp]b4_user_formals[); | |
1605 | ||
1606 | ||
1607 | /** Resolve the previous YYN states starting at and including state YYS | |
1608 | * on *YYSTACKP. If result != yyok, some states may have been left | |
1609 | * unresolved possibly with empty semantic option chains. Regardless | |
1610 | * of whether result = yyok, each state has been left with consistent | |
1611 | * data so that yydestroyGLRState can be invoked if necessary. */ | |
1612 | static YYRESULTTAG | |
1613 | yyresolveStates (yyGLRState* yys, int yyn, | |
1614 | yyGLRStack* yystackp]b4_user_formals[) | |
1615 | { | |
1616 | if (0 < yyn) | |
1617 | { | |
1618 | YYASSERT (yys->yypred); | |
1619 | YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[)); | |
1620 | if (! yys->yyresolved) | |
1621 | YYCHK (yyresolveValue (yys, yystackp]b4_user_args[)); | |
1622 | } | |
1623 | return yyok; | |
1624 | } | |
1625 | ||
1626 | /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its | |
1627 | * user action, and return the semantic value and location in *YYVALP | |
1628 | * and *YYLOCP. Regardless of whether result = yyok, all RHS states | |
1629 | * have been destroyed (assuming the user action destroys all RHS | |
1630 | * semantic values if invoked). */ | |
1631 | static YYRESULTTAG | |
1632 | yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp, | |
1633 | YYSTYPE* yyvalp]b4_locuser_formals[) | |
1634 | { | |
1635 | yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; | |
1636 | int yynrhs = yyrhsLength (yyopt->yyrule); | |
1637 | YYRESULTTAG yyflag = | |
1638 | yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[); | |
1639 | if (yyflag != yyok) | |
1640 | { | |
1641 | yyGLRState *yys; | |
1642 | for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1) | |
1643 | yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); | |
1644 | return yyflag; | |
1645 | } | |
1646 | ||
1647 | yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[ | |
1648 | if (yynrhs == 0) | |
1649 | /* Set default location. */ | |
1650 | yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[ | |
1651 | { | |
1652 | int yychar_current = yychar; | |
1653 | YYSTYPE yylval_current = yylval;]b4_locations_if([ | |
1654 | YYLTYPE yylloc_current = yylloc;])[ | |
1655 | yychar = yyopt->yyrawchar; | |
1656 | yylval = yyopt->yyval;]b4_locations_if([ | |
1657 | yylloc = yyopt->yyloc;])[ | |
1658 | yyflag = yyuserAction (yyopt->yyrule, yynrhs, | |
1659 | yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, | |
1660 | yystackp, yyvalp]b4_locuser_args[); | |
1661 | yychar = yychar_current; | |
1662 | yylval = yylval_current;]b4_locations_if([ | |
1663 | yylloc = yylloc_current;])[ | |
1664 | } | |
1665 | return yyflag; | |
1666 | } | |
1667 | ||
1668 | #if YYDEBUG | |
1669 | static void | |
1670 | yyreportTree (yySemanticOption* yyx, int yyindent) | |
1671 | { | |
1672 | int yynrhs = yyrhsLength (yyx->yyrule); | |
1673 | int yyi; | |
1674 | yyGLRState* yys; | |
1675 | yyGLRState* yystates[1 + YYMAXRHS]; | |
1676 | yyGLRState yyleftmost_state; | |
1677 | ||
1678 | for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) | |
1679 | yystates[yyi] = yys; | |
1680 | if (yys == YY_NULL) | |
1681 | { | |
1682 | yyleftmost_state.yyposn = 0; | |
1683 | yystates[0] = &yyleftmost_state; | |
1684 | } | |
1685 | else | |
1686 | yystates[0] = yys; | |
1687 | ||
1688 | if (yyx->yystate->yyposn < yys->yyposn + 1) | |
1689 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n", | |
1690 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), | |
1691 | yyx->yyrule - 1); | |
1692 | else | |
1693 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n", | |
1694 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), | |
1695 | yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1), | |
1696 | (unsigned long int) yyx->yystate->yyposn); | |
1697 | for (yyi = 1; yyi <= yynrhs; yyi += 1) | |
1698 | { | |
1699 | if (yystates[yyi]->yyresolved) | |
1700 | { | |
1701 | if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) | |
1702 | YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "", | |
1703 | yytokenName (yystos[yystates[yyi]->yylrState])); | |
1704 | else | |
1705 | YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "", | |
1706 | yytokenName (yystos[yystates[yyi]->yylrState]), | |
1707 | (unsigned long int) (yystates[yyi-1]->yyposn + 1), | |
1708 | (unsigned long int) yystates[yyi]->yyposn); | |
1709 | } | |
1710 | else | |
1711 | yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); | |
1712 | } | |
1713 | } | |
1714 | #endif | |
1715 | ||
1716 | /*ARGSUSED*/ static YYRESULTTAG | |
1717 | yyreportAmbiguity (yySemanticOption* yyx0, | |
1718 | yySemanticOption* yyx1]b4_pure_formals[) | |
1719 | { | |
1720 | YYUSE (yyx0); | |
1721 | YYUSE (yyx1); | |
1722 | ||
1723 | #if YYDEBUG | |
1724 | YYFPRINTF (stderr, "Ambiguity detected.\n"); | |
1725 | YYFPRINTF (stderr, "Option 1,\n"); | |
1726 | yyreportTree (yyx0, 2); | |
1727 | YYFPRINTF (stderr, "\nOption 2,\n"); | |
1728 | yyreportTree (yyx1, 2); | |
1729 | YYFPRINTF (stderr, "\n"); | |
1730 | #endif | |
1731 | ||
1732 | yyerror (]b4_yyerror_args[YY_("syntax is ambiguous")); | |
1733 | return yyabort; | |
1734 | }]b4_locations_if([[ | |
1735 | ||
1736 | /** Resolve the locations for each of the YYN1 states in *YYSTACKP, | |
1737 | * ending at YYS1. Has no effect on previously resolved states. | |
1738 | * The first semantic option of a state is always chosen. */ | |
1739 | static void | |
1740 | yyresolveLocations (yyGLRState* yys1, int yyn1, | |
1741 | yyGLRStack *yystackp]b4_user_formals[) | |
1742 | { | |
1743 | if (0 < yyn1) | |
1744 | { | |
1745 | yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[); | |
1746 | if (!yys1->yyresolved) | |
1747 | { | |
1748 | yyGLRStackItem yyrhsloc[1 + YYMAXRHS]; | |
1749 | int yynrhs; | |
1750 | yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal; | |
1751 | YYASSERT (yyoption != YY_NULL); | |
1752 | yynrhs = yyrhsLength (yyoption->yyrule); | |
1753 | if (yynrhs > 0) | |
1754 | { | |
1755 | yyGLRState *yys; | |
1756 | int yyn; | |
1757 | yyresolveLocations (yyoption->yystate, yynrhs, | |
1758 | yystackp]b4_user_args[); | |
1759 | for (yys = yyoption->yystate, yyn = yynrhs; | |
1760 | yyn > 0; | |
1761 | yys = yys->yypred, yyn -= 1) | |
1762 | yyrhsloc[yyn].yystate.yyloc = yys->yyloc; | |
1763 | } | |
1764 | else | |
1765 | { | |
1766 | /* Both yyresolveAction and yyresolveLocations traverse the GSS | |
1767 | in reverse rightmost order. It is only necessary to invoke | |
1768 | yyresolveLocations on a subforest for which yyresolveAction | |
1769 | would have been invoked next had an ambiguity not been | |
1770 | detected. Thus the location of the previous state (but not | |
1771 | necessarily the previous state itself) is guaranteed to be | |
1772 | resolved already. */ | |
1773 | yyGLRState *yyprevious = yyoption->yystate; | |
1774 | yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; | |
1775 | } | |
1776 | { | |
1777 | int yychar_current = yychar; | |
1778 | YYSTYPE yylval_current = yylval; | |
1779 | YYLTYPE yylloc_current = yylloc; | |
1780 | yychar = yyoption->yyrawchar; | |
1781 | yylval = yyoption->yyval; | |
1782 | yylloc = yyoption->yyloc; | |
1783 | YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs); | |
1784 | yychar = yychar_current; | |
1785 | yylval = yylval_current; | |
1786 | yylloc = yylloc_current; | |
1787 | } | |
1788 | } | |
1789 | } | |
1790 | }]])[ | |
1791 | ||
1792 | /** Resolve the ambiguity represented in state YYS in *YYSTACKP, | |
1793 | * perform the indicated actions, and set the semantic value of YYS. | |
1794 | * If result != yyok, the chain of semantic options in YYS has been | |
1795 | * cleared instead or it has been left unmodified except that | |
1796 | * redundant options may have been removed. Regardless of whether | |
1797 | * result = yyok, YYS has been left with consistent data so that | |
1798 | * yydestroyGLRState can be invoked if necessary. */ | |
1799 | static YYRESULTTAG | |
1800 | yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[) | |
1801 | { | |
1802 | yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal; | |
1803 | yySemanticOption* yybest = yyoptionList; | |
1804 | yySemanticOption** yypp; | |
1805 | yybool yymerge = yyfalse; | |
1806 | YYSTYPE yysval; | |
1807 | YYRESULTTAG yyflag;]b4_locations_if([ | |
1808 | YYLTYPE *yylocp = &yys->yyloc;])[ | |
1809 | ||
1810 | for (yypp = &yyoptionList->yynext; *yypp != YY_NULL; ) | |
1811 | { | |
1812 | yySemanticOption* yyp = *yypp; | |
1813 | ||
1814 | if (yyidenticalOptions (yybest, yyp)) | |
1815 | { | |
1816 | yymergeOptionSets (yybest, yyp); | |
1817 | *yypp = yyp->yynext; | |
1818 | } | |
1819 | else | |
1820 | { | |
1821 | switch (yypreference (yybest, yyp)) | |
1822 | { | |
1823 | case 0:]b4_locations_if([[ | |
1824 | yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[ | |
1825 | return yyreportAmbiguity (yybest, yyp]b4_pure_args[); | |
1826 | break; | |
1827 | case 1: | |
1828 | yymerge = yytrue; | |
1829 | break; | |
1830 | case 2: | |
1831 | break; | |
1832 | case 3: | |
1833 | yybest = yyp; | |
1834 | yymerge = yyfalse; | |
1835 | break; | |
1836 | default: | |
1837 | /* This cannot happen so it is not worth a YYASSERT (yyfalse), | |
1838 | but some compilers complain if the default case is | |
1839 | omitted. */ | |
1840 | break; | |
1841 | } | |
1842 | yypp = &yyp->yynext; | |
1843 | } | |
1844 | } | |
1845 | ||
1846 | if (yymerge) | |
1847 | { | |
1848 | yySemanticOption* yyp; | |
1849 | int yyprec = yydprec[yybest->yyrule]; | |
1850 | yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[); | |
1851 | if (yyflag == yyok) | |
1852 | for (yyp = yybest->yynext; yyp != YY_NULL; yyp = yyp->yynext) | |
1853 | { | |
1854 | if (yyprec == yydprec[yyp->yyrule]) | |
1855 | { | |
1856 | YYSTYPE yysval_other;]b4_locations_if([ | |
1857 | YYLTYPE yydummy;])[ | |
1858 | yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[); | |
1859 | if (yyflag != yyok) | |
1860 | { | |
1861 | yydestruct ("Cleanup: discarding incompletely merged value for", | |
1862 | yystos[yys->yylrState], | |
1863 | &yysval]b4_locuser_args[); | |
1864 | break; | |
1865 | } | |
1866 | yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other); | |
1867 | } | |
1868 | } | |
1869 | } | |
1870 | else | |
1871 | yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[); | |
1872 | ||
1873 | if (yyflag == yyok) | |
1874 | { | |
1875 | yys->yyresolved = yytrue; | |
1876 | yys->yysemantics.yysval = yysval; | |
1877 | } | |
1878 | else | |
1879 | yys->yysemantics.yyfirstVal = YY_NULL; | |
1880 | return yyflag; | |
1881 | } | |
1882 | ||
1883 | static YYRESULTTAG | |
1884 | yyresolveStack (yyGLRStack* yystackp]b4_user_formals[) | |
1885 | { | |
1886 | if (yystackp->yysplitPoint != YY_NULL) | |
1887 | { | |
1888 | yyGLRState* yys; | |
1889 | int yyn; | |
1890 | ||
1891 | for (yyn = 0, yys = yystackp->yytops.yystates[0]; | |
1892 | yys != yystackp->yysplitPoint; | |
1893 | yys = yys->yypred, yyn += 1) | |
1894 | continue; | |
1895 | YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp | |
1896 | ]b4_user_args[)); | |
1897 | } | |
1898 | return yyok; | |
1899 | } | |
1900 | ||
1901 | static void | |
1902 | yycompressStack (yyGLRStack* yystackp) | |
1903 | { | |
1904 | yyGLRState* yyp, *yyq, *yyr; | |
1905 | ||
1906 | if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULL) | |
1907 | return; | |
1908 | ||
1909 | for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULL; | |
1910 | yyp != yystackp->yysplitPoint; | |
1911 | yyr = yyp, yyp = yyq, yyq = yyp->yypred) | |
1912 | yyp->yypred = yyr; | |
1913 | ||
1914 | yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; | |
1915 | yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1; | |
1916 | yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; | |
1917 | yystackp->yysplitPoint = YY_NULL; | |
1918 | yystackp->yylastDeleted = YY_NULL; | |
1919 | ||
1920 | while (yyr != YY_NULL) | |
1921 | { | |
1922 | yystackp->yynextFree->yystate = *yyr; | |
1923 | yyr = yyr->yypred; | |
1924 | yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate; | |
1925 | yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate; | |
1926 | yystackp->yynextFree += 1; | |
1927 | yystackp->yyspaceLeft -= 1; | |
1928 | } | |
1929 | } | |
1930 | ||
1931 | static YYRESULTTAG | |
1932 | yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, | |
1933 | size_t yyposn]b4_pure_formals[) | |
1934 | { | |
1935 | while (yystackp->yytops.yystates[yyk] != YY_NULL) | |
1936 | { | |
1937 | yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState; | |
1938 | YYDPRINTF ((stderr, "Stack %lu Entering state %d\n", | |
1939 | (unsigned long int) yyk, yystate)); | |
1940 | ||
1941 | YYASSERT (yystate != YYFINAL); | |
1942 | ||
1943 | if (yyisDefaultedState (yystate)) | |
1944 | { | |
1945 | YYRESULTTAG yyflag; | |
1946 | yyRuleNum yyrule = yydefaultAction (yystate); | |
1947 | if (yyrule == 0) | |
1948 | { | |
1949 | YYDPRINTF ((stderr, "Stack %lu dies.\n", | |
1950 | (unsigned long int) yyk)); | |
1951 | yymarkStackDeleted (yystackp, yyk); | |
1952 | return yyok; | |
1953 | } | |
1954 | yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[); | |
1955 | if (yyflag == yyerr) | |
1956 | { | |
1957 | YYDPRINTF ((stderr, | |
1958 | "Stack %lu dies " | |
1959 | "(predicate failure or explicit user error).\n", | |
1960 | (unsigned long int) yyk)); | |
1961 | yymarkStackDeleted (yystackp, yyk); | |
1962 | return yyok; | |
1963 | } | |
1964 | if (yyflag != yyok) | |
1965 | return yyflag; | |
1966 | } | |
1967 | else | |
1968 | { | |
1969 | yySymbol yytoken; | |
1970 | int yyaction; | |
1971 | const short int* yyconflicts; | |
1972 | ||
1973 | yystackp->yytops.yylookaheadNeeds[yyk] = yytrue; | |
1974 | if (yychar == YYEMPTY) | |
1975 | { | |
1976 | YYDPRINTF ((stderr, "Reading a token: ")); | |
1977 | yychar = YYLEX; | |
1978 | } | |
1979 | ||
1980 | if (yychar <= YYEOF) | |
1981 | { | |
1982 | yychar = yytoken = YYEOF; | |
1983 | YYDPRINTF ((stderr, "Now at end of input.\n")); | |
1984 | } | |
1985 | else | |
1986 | { | |
1987 | yytoken = YYTRANSLATE (yychar); | |
1988 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
1989 | } | |
1990 | ||
1991 | yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); | |
1992 | ||
1993 | while (*yyconflicts != 0) | |
1994 | { | |
1995 | YYRESULTTAG yyflag; | |
1996 | size_t yynewStack = yysplitStack (yystackp, yyk); | |
1997 | YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n", | |
1998 | (unsigned long int) yynewStack, | |
1999 | (unsigned long int) yyk)); | |
2000 | yyflag = yyglrReduce (yystackp, yynewStack, | |
2001 | *yyconflicts, | |
2002 | yyimmediate[*yyconflicts]]b4_user_args[); | |
2003 | if (yyflag == yyok) | |
2004 | YYCHK (yyprocessOneStack (yystackp, yynewStack, | |
2005 | yyposn]b4_pure_args[)); | |
2006 | else if (yyflag == yyerr) | |
2007 | { | |
2008 | YYDPRINTF ((stderr, "Stack %lu dies.\n", | |
2009 | (unsigned long int) yynewStack)); | |
2010 | yymarkStackDeleted (yystackp, yynewStack); | |
2011 | } | |
2012 | else | |
2013 | return yyflag; | |
2014 | yyconflicts += 1; | |
2015 | } | |
2016 | ||
2017 | if (yyisShiftAction (yyaction)) | |
2018 | break; | |
2019 | else if (yyisErrorAction (yyaction)) | |
2020 | { | |
2021 | YYDPRINTF ((stderr, "Stack %lu dies.\n", | |
2022 | (unsigned long int) yyk)); | |
2023 | yymarkStackDeleted (yystackp, yyk); | |
2024 | break; | |
2025 | } | |
2026 | else | |
2027 | { | |
2028 | YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction, | |
2029 | yyimmediate[-yyaction]]b4_user_args[); | |
2030 | if (yyflag == yyerr) | |
2031 | { | |
2032 | YYDPRINTF ((stderr, | |
2033 | "Stack %lu dies " | |
2034 | "(predicate failure or explicit user error).\n", | |
2035 | (unsigned long int) yyk)); | |
2036 | yymarkStackDeleted (yystackp, yyk); | |
2037 | break; | |
2038 | } | |
2039 | else if (yyflag != yyok) | |
2040 | return yyflag; | |
2041 | } | |
2042 | } | |
2043 | } | |
2044 | return yyok; | |
2045 | } | |
2046 | ||
2047 | /*ARGSUSED*/ static void | |
2048 | yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) | |
2049 | { | |
2050 | if (yystackp->yyerrState != 0) | |
2051 | return; | |
2052 | #if ! YYERROR_VERBOSE | |
2053 | yyerror (]b4_lyyerror_args[YY_("syntax error")); | |
2054 | #else | |
2055 | yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); | |
2056 | size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken)); | |
2057 | size_t yysize = yysize0; | |
2058 | size_t yysize1; | |
2059 | yybool yysize_overflow = yyfalse; | |
2060 | char* yymsg = YY_NULL; | |
2061 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; | |
2062 | /* Internationalized format string. */ | |
2063 | const char *yyformat = YY_NULL; | |
2064 | /* Arguments of yyformat. */ | |
2065 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; | |
2066 | /* Number of reported tokens (one for the "unexpected", one per | |
2067 | "expected"). */ | |
2068 | int yycount = 0; | |
2069 | ||
2070 | /* There are many possibilities here to consider: | |
2071 | - If this state is a consistent state with a default action, then | |
2072 | the only way this function was invoked is if the default action | |
2073 | is an error action. In that case, don't check for expected | |
2074 | tokens because there are none. | |
2075 | - The only way there can be no lookahead present (in yychar) is if | |
2076 | this state is a consistent state with a default action. Thus, | |
2077 | detecting the absence of a lookahead is sufficient to determine | |
2078 | that there is no unexpected or expected token to report. In that | |
2079 | case, just report a simple "syntax error". | |
2080 | - Don't assume there isn't a lookahead just because this state is a | |
2081 | consistent state with a default action. There might have been a | |
2082 | previous inconsistent state, consistent state with a non-default | |
2083 | action, or user semantic action that manipulated yychar. | |
2084 | - Of course, the expected token list depends on states to have | |
2085 | correct lookahead information, and it depends on the parser not | |
2086 | to perform extra reductions after fetching a lookahead from the | |
2087 | scanner and before detecting a syntax error. Thus, state merging | |
2088 | (from LALR or IELR) and default reductions corrupt the expected | |
2089 | token list. However, the list is correct for canonical LR with | |
2090 | one exception: it will still contain any token that will not be | |
2091 | accepted due to an error action in a later state. | |
2092 | */ | |
2093 | if (yytoken != YYEMPTY) | |
2094 | { | |
2095 | int yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; | |
2096 | yyarg[yycount++] = yytokenName (yytoken); | |
2097 | if (!yypact_value_is_default (yyn)) | |
2098 | { | |
2099 | /* Start YYX at -YYN if negative to avoid negative indexes in | |
2100 | YYCHECK. In other words, skip the first -YYN actions for this | |
2101 | state because they are default actions. */ | |
2102 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
2103 | /* Stay within bounds of both yycheck and yytname. */ | |
2104 | int yychecklim = YYLAST - yyn + 1; | |
2105 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; | |
2106 | int yyx; | |
2107 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) | |
2108 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR | |
2109 | && !yytable_value_is_error (yytable[yyx + yyn])) | |
2110 | { | |
2111 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) | |
2112 | { | |
2113 | yycount = 1; | |
2114 | yysize = yysize0; | |
2115 | break; | |
2116 | } | |
2117 | yyarg[yycount++] = yytokenName (yyx); | |
2118 | yysize1 = yysize + yytnamerr (YY_NULL, yytokenName (yyx)); | |
2119 | yysize_overflow |= yysize1 < yysize; | |
2120 | yysize = yysize1; | |
2121 | } | |
2122 | } | |
2123 | } | |
2124 | ||
2125 | switch (yycount) | |
2126 | { | |
2127 | #define YYCASE_(N, S) \ | |
2128 | case N: \ | |
2129 | yyformat = S; \ | |
2130 | break | |
2131 | YYCASE_(0, YY_("syntax error")); | |
2132 | YYCASE_(1, YY_("syntax error, unexpected %s")); | |
2133 | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); | |
2134 | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); | |
2135 | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); | |
2136 | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); | |
2137 | #undef YYCASE_ | |
2138 | } | |
2139 | ||
2140 | yysize1 = yysize + strlen (yyformat); | |
2141 | yysize_overflow |= yysize1 < yysize; | |
2142 | yysize = yysize1; | |
2143 | ||
2144 | if (!yysize_overflow) | |
2145 | yymsg = (char *) YYMALLOC (yysize); | |
2146 | ||
2147 | if (yymsg) | |
2148 | { | |
2149 | char *yyp = yymsg; | |
2150 | int yyi = 0; | |
2151 | while ((*yyp = *yyformat)) | |
2152 | { | |
2153 | if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) | |
2154 | { | |
2155 | yyp += yytnamerr (yyp, yyarg[yyi++]); | |
2156 | yyformat += 2; | |
2157 | } | |
2158 | else | |
2159 | { | |
2160 | yyp++; | |
2161 | yyformat++; | |
2162 | } | |
2163 | } | |
2164 | yyerror (]b4_lyyerror_args[yymsg); | |
2165 | YYFREE (yymsg); | |
2166 | } | |
2167 | else | |
2168 | { | |
2169 | yyerror (]b4_lyyerror_args[YY_("syntax error")); | |
2170 | yyMemoryExhausted (yystackp); | |
2171 | } | |
2172 | #endif /* YYERROR_VERBOSE */ | |
2173 | yynerrs += 1; | |
2174 | } | |
2175 | ||
2176 | /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, | |
2177 | yylval, and yylloc are the syntactic category, semantic value, and location | |
2178 | of the lookahead. */ | |
2179 | /*ARGSUSED*/ static void | |
2180 | yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) | |
2181 | { | |
2182 | size_t yyk; | |
2183 | int yyj; | |
2184 | ||
2185 | if (yystackp->yyerrState == 3) | |
2186 | /* We just shifted the error token and (perhaps) took some | |
2187 | reductions. Skip tokens until we can proceed. */ | |
2188 | while (YYID (yytrue)) | |
2189 | { | |
2190 | yySymbol yytoken; | |
2191 | if (yychar == YYEOF) | |
2192 | yyFail (yystackp][]b4_lpure_args[, YY_NULL); | |
2193 | if (yychar != YYEMPTY) | |
2194 | {]b4_locations_if([[ | |
2195 | /* We throw away the lookahead, but the error range | |
2196 | of the shifted error token must take it into account. */ | |
2197 | yyGLRState *yys = yystackp->yytops.yystates[0]; | |
2198 | yyGLRStackItem yyerror_range[3]; | |
2199 | yyerror_range[1].yystate.yyloc = yys->yyloc; | |
2200 | yyerror_range[2].yystate.yyloc = yylloc; | |
2201 | YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ | |
2202 | yytoken = YYTRANSLATE (yychar); | |
2203 | yydestruct ("Error: discarding", | |
2204 | yytoken, &yylval]b4_locuser_args([&yylloc])[); | |
2205 | } | |
2206 | YYDPRINTF ((stderr, "Reading a token: ")); | |
2207 | yychar = YYLEX; | |
2208 | if (yychar <= YYEOF) | |
2209 | { | |
2210 | yychar = yytoken = YYEOF; | |
2211 | YYDPRINTF ((stderr, "Now at end of input.\n")); | |
2212 | } | |
2213 | else | |
2214 | { | |
2215 | yytoken = YYTRANSLATE (yychar); | |
2216 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
2217 | } | |
2218 | yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; | |
2219 | if (yypact_value_is_default (yyj)) | |
2220 | return; | |
2221 | yyj += yytoken; | |
2222 | if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken) | |
2223 | { | |
2224 | if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0) | |
2225 | return; | |
2226 | } | |
2227 | else if (! yytable_value_is_error (yytable[yyj])) | |
2228 | return; | |
2229 | } | |
2230 | ||
2231 | /* Reduce to one stack. */ | |
2232 | for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) | |
2233 | if (yystackp->yytops.yystates[yyk] != YY_NULL) | |
2234 | break; | |
2235 | if (yyk >= yystackp->yytops.yysize) | |
2236 | yyFail (yystackp][]b4_lpure_args[, YY_NULL); | |
2237 | for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) | |
2238 | yymarkStackDeleted (yystackp, yyk); | |
2239 | yyremoveDeletes (yystackp); | |
2240 | yycompressStack (yystackp); | |
2241 | ||
2242 | /* Now pop stack until we find a state that shifts the error token. */ | |
2243 | yystackp->yyerrState = 3; | |
2244 | while (yystackp->yytops.yystates[0] != YY_NULL) | |
2245 | { | |
2246 | yyGLRState *yys = yystackp->yytops.yystates[0]; | |
2247 | yyj = yypact[yys->yylrState]; | |
2248 | if (! yypact_value_is_default (yyj)) | |
2249 | { | |
2250 | yyj += YYTERROR; | |
2251 | if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR | |
2252 | && yyisShiftAction (yytable[yyj])) | |
2253 | { | |
2254 | /* Shift the error token. */]b4_locations_if([[ | |
2255 | /* First adjust its location.*/ | |
2256 | YYLTYPE yyerrloc; | |
2257 | yystackp->yyerror_range[2].yystate.yyloc = yylloc; | |
2258 | YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[ | |
2259 | YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]], | |
2260 | &yylval, &yyerrloc); | |
2261 | yyglrShift (yystackp, 0, yytable[yyj], | |
2262 | yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[); | |
2263 | yys = yystackp->yytops.yystates[0]; | |
2264 | break; | |
2265 | } | |
2266 | }]b4_locations_if([[ | |
2267 | yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ | |
2268 | if (yys->yypred != YY_NULL) | |
2269 | yydestroyGLRState ("Error: popping", yys]b4_user_args[); | |
2270 | yystackp->yytops.yystates[0] = yys->yypred; | |
2271 | yystackp->yynextFree -= 1; | |
2272 | yystackp->yyspaceLeft += 1; | |
2273 | } | |
2274 | if (yystackp->yytops.yystates[0] == YY_NULL) | |
2275 | yyFail (yystackp][]b4_lpure_args[, YY_NULL); | |
2276 | } | |
2277 | ||
2278 | #define YYCHK1(YYE) \ | |
2279 | do { \ | |
2280 | switch (YYE) { \ | |
2281 | case yyok: \ | |
2282 | break; \ | |
2283 | case yyabort: \ | |
2284 | goto yyabortlab; \ | |
2285 | case yyaccept: \ | |
2286 | goto yyacceptlab; \ | |
2287 | case yyerr: \ | |
2288 | goto yyuser_error; \ | |
2289 | default: \ | |
2290 | goto yybuglab; \ | |
2291 | } \ | |
2292 | } while (YYID (0)) | |
2293 | ||
2294 | /*----------. | |
2295 | | yyparse. | | |
2296 | `----------*/ | |
2297 | ||
2298 | ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[ | |
2299 | { | |
2300 | int yyresult; | |
2301 | yyGLRStack yystack; | |
2302 | yyGLRStack* const yystackp = &yystack; | |
2303 | size_t yyposn; | |
2304 | ||
2305 | YYDPRINTF ((stderr, "Starting parse\n")); | |
2306 | ||
2307 | yychar = YYEMPTY; | |
2308 | yylval = yyval_default; | |
2309 | ]b4_locations_if([ | |
2310 | #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL | |
2311 | yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[; | |
2312 | yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[; | |
2313 | #endif | |
2314 | ]) | |
2315 | m4_ifdef([b4_initial_action], [ | |
2316 | m4_pushdef([b4_at_dollar], [yylloc])dnl | |
2317 | m4_pushdef([b4_dollar_dollar], [yylval])dnl | |
2318 | /* User initialization code. */ | |
2319 | b4_user_initial_action | |
2320 | m4_popdef([b4_dollar_dollar])dnl | |
2321 | m4_popdef([b4_at_dollar])])dnl | |
2322 | [ | |
2323 | if (! yyinitGLRStack (yystackp, YYINITDEPTH)) | |
2324 | goto yyexhaustedlab; | |
2325 | switch (YYSETJMP (yystack.yyexception_buffer)) | |
2326 | { | |
2327 | case 0: break; | |
2328 | case 1: goto yyabortlab; | |
2329 | case 2: goto yyexhaustedlab; | |
2330 | default: goto yybuglab; | |
2331 | } | |
2332 | yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[); | |
2333 | yyposn = 0; | |
2334 | ||
2335 | while (YYID (yytrue)) | |
2336 | { | |
2337 | /* For efficiency, we have two loops, the first of which is | |
2338 | specialized to deterministic operation (single stack, no | |
2339 | potential ambiguity). */ | |
2340 | /* Standard mode */ | |
2341 | while (YYID (yytrue)) | |
2342 | { | |
2343 | yyRuleNum yyrule; | |
2344 | int yyaction; | |
2345 | const short int* yyconflicts; | |
2346 | ||
2347 | yyStateNum yystate = yystack.yytops.yystates[0]->yylrState; | |
2348 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); | |
2349 | if (yystate == YYFINAL) | |
2350 | goto yyacceptlab; | |
2351 | if (yyisDefaultedState (yystate)) | |
2352 | { | |
2353 | yyrule = yydefaultAction (yystate); | |
2354 | if (yyrule == 0) | |
2355 | { | |
2356 | ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ | |
2357 | yyreportSyntaxError (&yystack]b4_user_args[); | |
2358 | goto yyuser_error; | |
2359 | } | |
2360 | YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[)); | |
2361 | } | |
2362 | else | |
2363 | { | |
2364 | yySymbol yytoken; | |
2365 | if (yychar == YYEMPTY) | |
2366 | { | |
2367 | YYDPRINTF ((stderr, "Reading a token: ")); | |
2368 | yychar = YYLEX; | |
2369 | } | |
2370 | ||
2371 | if (yychar <= YYEOF) | |
2372 | { | |
2373 | yychar = yytoken = YYEOF; | |
2374 | YYDPRINTF ((stderr, "Now at end of input.\n")); | |
2375 | } | |
2376 | else | |
2377 | { | |
2378 | yytoken = YYTRANSLATE (yychar); | |
2379 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
2380 | } | |
2381 | ||
2382 | yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); | |
2383 | if (*yyconflicts != 0) | |
2384 | break; | |
2385 | if (yyisShiftAction (yyaction)) | |
2386 | { | |
2387 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); | |
2388 | yychar = YYEMPTY; | |
2389 | yyposn += 1; | |
2390 | yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[); | |
2391 | if (0 < yystack.yyerrState) | |
2392 | yystack.yyerrState -= 1; | |
2393 | } | |
2394 | else if (yyisErrorAction (yyaction)) | |
2395 | { | |
2396 | ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ | |
2397 | yyreportSyntaxError (&yystack]b4_user_args[); | |
2398 | goto yyuser_error; | |
2399 | } | |
2400 | else | |
2401 | YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[)); | |
2402 | } | |
2403 | } | |
2404 | ||
2405 | while (YYID (yytrue)) | |
2406 | { | |
2407 | yySymbol yytoken_to_shift; | |
2408 | size_t yys; | |
2409 | ||
2410 | for (yys = 0; yys < yystack.yytops.yysize; yys += 1) | |
2411 | yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY; | |
2412 | ||
2413 | /* yyprocessOneStack returns one of three things: | |
2414 | ||
2415 | - An error flag. If the caller is yyprocessOneStack, it | |
2416 | immediately returns as well. When the caller is finally | |
2417 | yyparse, it jumps to an error label via YYCHK1. | |
2418 | ||
2419 | - yyok, but yyprocessOneStack has invoked yymarkStackDeleted | |
2420 | (&yystack, yys), which sets the top state of yys to NULL. Thus, | |
2421 | yyparse's following invocation of yyremoveDeletes will remove | |
2422 | the stack. | |
2423 | ||
2424 | - yyok, when ready to shift a token. | |
2425 | ||
2426 | Except in the first case, yyparse will invoke yyremoveDeletes and | |
2427 | then shift the next token onto all remaining stacks. This | |
2428 | synchronization of the shift (that is, after all preceding | |
2429 | reductions on all stacks) helps prevent double destructor calls | |
2430 | on yylval in the event of memory exhaustion. */ | |
2431 | ||
2432 | for (yys = 0; yys < yystack.yytops.yysize; yys += 1) | |
2433 | YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[)); | |
2434 | yyremoveDeletes (&yystack); | |
2435 | if (yystack.yytops.yysize == 0) | |
2436 | { | |
2437 | yyundeleteLastStack (&yystack); | |
2438 | if (yystack.yytops.yysize == 0) | |
2439 | yyFail (&yystack][]b4_lpure_args[, YY_("syntax error")); | |
2440 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); | |
2441 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); | |
2442 | ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ | |
2443 | yyreportSyntaxError (&yystack]b4_user_args[); | |
2444 | goto yyuser_error; | |
2445 | } | |
2446 | ||
2447 | /* If any yyglrShift call fails, it will fail after shifting. Thus, | |
2448 | a copy of yylval will already be on stack 0 in the event of a | |
2449 | failure in the following loop. Thus, yychar is set to YYEMPTY | |
2450 | before the loop to make sure the user destructor for yylval isn't | |
2451 | called twice. */ | |
2452 | yytoken_to_shift = YYTRANSLATE (yychar); | |
2453 | yychar = YYEMPTY; | |
2454 | yyposn += 1; | |
2455 | for (yys = 0; yys < yystack.yytops.yysize; yys += 1) | |
2456 | { | |
2457 | int yyaction; | |
2458 | const short int* yyconflicts; | |
2459 | yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState; | |
2460 | yygetLRActions (yystate, yytoken_to_shift, &yyaction, | |
2461 | &yyconflicts); | |
2462 | /* Note that yyconflicts were handled by yyprocessOneStack. */ | |
2463 | YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys)); | |
2464 | YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); | |
2465 | yyglrShift (&yystack, yys, yyaction, yyposn, | |
2466 | &yylval]b4_locations_if([, &yylloc])[); | |
2467 | YYDPRINTF ((stderr, "Stack %lu now in state #%d\n", | |
2468 | (unsigned long int) yys, | |
2469 | yystack.yytops.yystates[yys]->yylrState)); | |
2470 | } | |
2471 | ||
2472 | if (yystack.yytops.yysize == 1) | |
2473 | { | |
2474 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); | |
2475 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); | |
2476 | yycompressStack (&yystack); | |
2477 | break; | |
2478 | } | |
2479 | } | |
2480 | continue; | |
2481 | yyuser_error: | |
2482 | yyrecoverSyntaxError (&yystack]b4_user_args[); | |
2483 | yyposn = yystack.yytops.yystates[0]->yyposn; | |
2484 | } | |
2485 | ||
2486 | yyacceptlab: | |
2487 | yyresult = 0; | |
2488 | goto yyreturn; | |
2489 | ||
2490 | yybuglab: | |
2491 | YYASSERT (yyfalse); | |
2492 | goto yyabortlab; | |
2493 | ||
2494 | yyabortlab: | |
2495 | yyresult = 1; | |
2496 | goto yyreturn; | |
2497 | ||
2498 | yyexhaustedlab: | |
2499 | yyerror (]b4_lyyerror_args[YY_("memory exhausted")); | |
2500 | yyresult = 2; | |
2501 | goto yyreturn; | |
2502 | ||
2503 | yyreturn: | |
2504 | if (yychar != YYEMPTY) | |
2505 | yydestruct ("Cleanup: discarding lookahead", | |
2506 | YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[); | |
2507 | ||
2508 | /* If the stack is well-formed, pop the stack until it is empty, | |
2509 | destroying its entries as we go. But free the stack regardless | |
2510 | of whether it is well-formed. */ | |
2511 | if (yystack.yyitems) | |
2512 | { | |
2513 | yyGLRState** yystates = yystack.yytops.yystates; | |
2514 | if (yystates) | |
2515 | { | |
2516 | size_t yysize = yystack.yytops.yysize; | |
2517 | size_t yyk; | |
2518 | for (yyk = 0; yyk < yysize; yyk += 1) | |
2519 | if (yystates[yyk]) | |
2520 | { | |
2521 | while (yystates[yyk]) | |
2522 | { | |
2523 | yyGLRState *yys = yystates[yyk]; | |
2524 | ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] | |
2525 | )[ if (yys->yypred != YY_NULL) | |
2526 | yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); | |
2527 | yystates[yyk] = yys->yypred; | |
2528 | yystack.yynextFree -= 1; | |
2529 | yystack.yyspaceLeft += 1; | |
2530 | } | |
2531 | break; | |
2532 | } | |
2533 | } | |
2534 | yyfreeGLRStack (&yystack); | |
2535 | } | |
2536 | ||
2537 | /* Make sure YYID is used. */ | |
2538 | return YYID (yyresult); | |
2539 | } | |
2540 | ||
2541 | /* DEBUGGING ONLY */ | |
2542 | #if YYDEBUG | |
2543 | static void yypstack (yyGLRStack* yystackp, size_t yyk) | |
2544 | __attribute__ ((__unused__)); | |
2545 | static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__)); | |
2546 | ||
2547 | static void | |
2548 | yy_yypstack (yyGLRState* yys) | |
2549 | { | |
2550 | if (yys->yypred) | |
2551 | { | |
2552 | yy_yypstack (yys->yypred); | |
2553 | YYFPRINTF (stderr, " -> "); | |
2554 | } | |
2555 | YYFPRINTF (stderr, "%d@@%lu", yys->yylrState, | |
2556 | (unsigned long int) yys->yyposn); | |
2557 | } | |
2558 | ||
2559 | static void | |
2560 | yypstates (yyGLRState* yyst) | |
2561 | { | |
2562 | if (yyst == YY_NULL) | |
2563 | YYFPRINTF (stderr, "<null>"); | |
2564 | else | |
2565 | yy_yypstack (yyst); | |
2566 | YYFPRINTF (stderr, "\n"); | |
2567 | } | |
2568 | ||
2569 | static void | |
2570 | yypstack (yyGLRStack* yystackp, size_t yyk) | |
2571 | { | |
2572 | yypstates (yystackp->yytops.yystates[yyk]); | |
2573 | } | |
2574 | ||
2575 | #define YYINDEX(YYX) \ | |
2576 | ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems) | |
2577 | ||
2578 | ||
2579 | static void | |
2580 | yypdumpstack (yyGLRStack* yystackp) | |
2581 | { | |
2582 | yyGLRStackItem* yyp; | |
2583 | size_t yyi; | |
2584 | for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) | |
2585 | { | |
2586 | YYFPRINTF (stderr, "%3lu. ", | |
2587 | (unsigned long int) (yyp - yystackp->yyitems)); | |
2588 | if (*(yybool *) yyp) | |
2589 | { | |
2590 | YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", | |
2591 | yyp->yystate.yyresolved, yyp->yystate.yylrState, | |
2592 | (unsigned long int) yyp->yystate.yyposn, | |
2593 | (long int) YYINDEX (yyp->yystate.yypred)); | |
2594 | if (! yyp->yystate.yyresolved) | |
2595 | YYFPRINTF (stderr, ", firstVal: %ld", | |
2596 | (long int) YYINDEX (yyp->yystate | |
2597 | .yysemantics.yyfirstVal)); | |
2598 | } | |
2599 | else | |
2600 | { | |
2601 | YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld", | |
2602 | yyp->yyoption.yyrule - 1, | |
2603 | (long int) YYINDEX (yyp->yyoption.yystate), | |
2604 | (long int) YYINDEX (yyp->yyoption.yynext)); | |
2605 | } | |
2606 | YYFPRINTF (stderr, "\n"); | |
2607 | } | |
2608 | YYFPRINTF (stderr, "Tops:"); | |
2609 | for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) | |
2610 | YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi, | |
2611 | (long int) YYINDEX (yystackp->yytops.yystates[yyi])); | |
2612 | YYFPRINTF (stderr, "\n"); | |
2613 | } | |
2614 | #endif | |
2615 | ]b4_epilogue[]dnl | |
2616 | dnl | |
2617 | dnl glr.cc produces its own header. | |
2618 | dnl | |
2619 | m4_if(b4_skeleton, ["glr.c"], | |
2620 | [b4_defines_if( | |
2621 | [@output(b4_spec_defines_file@)@ | |
2622 | b4_copyright([Skeleton interface for Bison GLR parsers in C], | |
2623 | [2002-2012])[ | |
2624 | ||
2625 | ]b4_cpp_guard_open([b4_spec_defines_file])[ | |
2626 | ]b4_shared_declarations[ | |
2627 | ]b4_cpp_guard_close([b4_spec_defines_file])[ | |
2628 | ]])]) | |
2629 | m4_divert_pop(0) |