]>
Commit | Line | Data |
---|---|---|
720623af | 1 | m4_divert(-1) -*- C -*- |
01241d47 | 2 | |
fb8135fa AD |
3 | # GLR skeleton for Bison |
4 | # Copyright (C) 2002 Free Software Foundation, Inc. | |
5 | ||
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | ||
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | ||
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
19 | # 02111-1307 USA | |
20 | ||
66d30cd4 AD |
21 | |
22 | ## ---------------- ## | |
23 | ## Default values. ## | |
24 | ## ---------------- ## | |
25 | ||
26 | # Stack parameters. | |
27 | m4_define_default([b4_stack_depth_max], [10000]) | |
28 | m4_define_default([b4_stack_depth_init], [200]) | |
29 | ||
2a8d363a AD |
30 | |
31 | ||
32 | ## ------------------------ ## | |
33 | ## Pure/impure interfaces. ## | |
34 | ## ------------------------ ## | |
35 | ||
36 | ||
37 | # b4_lex_param | |
38 | # ------------ | |
21964f43 AD |
39 | # Accumule in b4_lex_param all the yylex arguments. |
40 | # Yes, this is quite ugly... | |
41 | m4_define([b4_lex_param], | |
42 | m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnl | |
43 | b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl | |
44 | m4_ifdef([b4_lex_param], [, ]b4_lex_param))) | |
45 | ||
2a8d363a AD |
46 | |
47 | # b4_user_formals | |
48 | # --------------- | |
49 | m4_define([b4_user_formals], | |
50 | [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) | |
51 | ||
52 | ||
93724f13 AD |
53 | # b4_yyerror_args |
54 | # --------------- | |
55 | # Arguments passed to yyerror: user args plus yylloc. | |
56 | m4_define([b4_yyerror_args], | |
57 | [b4_pure_if([b4_location_if([yylocp, ])])dnl | |
58 | m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) | |
59 | ||
60 | ||
61 | # b4_lyyerror_args | |
62 | # ---------------- | |
63 | # Same as above, but on the lookahead, hence yyllocp instead of yylocp. | |
64 | m4_define([b4_lyyerror_args], | |
65 | [b4_pure_if([b4_location_if([yyllocp, ])])dnl | |
66 | m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) | |
67 | ||
68 | ||
2a8d363a AD |
69 | # b4_pure_args |
70 | # ------------ | |
93724f13 | 71 | # Arguments needed by yyerror: user args plus yylloc. |
2a8d363a AD |
72 | m4_define([b4_pure_args], |
73 | [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args]) | |
74 | ||
75 | ||
76 | # b4_pure_formals | |
77 | # --------------- | |
78 | # Arguments passed to yyerror: user formals plus yyllocp. | |
79 | m4_define([b4_pure_formals], | |
80 | [b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals]) | |
81 | ||
82 | ||
83 | # b4_lpure_args | |
84 | # ------------- | |
85 | # Same as above, but on the lookahead, hence yyllocp instead of yylocp. | |
86 | m4_define([b4_lpure_args], | |
87 | [b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args]) | |
0245f82d | 88 | |
66d30cd4 | 89 | |
2a8d363a AD |
90 | # b4_lpure_formals |
91 | # ---------------- | |
92 | # Same as above, but on the lookahead, hence yyllocp instead of yylocp. | |
93 | m4_define([b4_lpure_formals], | |
94 | [b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals]) | |
95 | ||
66d30cd4 AD |
96 | |
97 | ## ----------------- ## | |
98 | ## Semantic Values. ## | |
99 | ## ----------------- ## | |
100 | ||
101 | ||
01241d47 PH |
102 | # b4_lhs_value([TYPE]) |
103 | # -------------------- | |
104 | # Expansion of $<TYPE>$. | |
105 | m4_define([b4_lhs_value], | |
106 | [(*yyvalp)[]m4_ifval([$1], [.$1])]) | |
107 | ||
108 | ||
109 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
110 | # -------------------------------------- | |
111 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
112 | # symbols on RHS. | |
113 | m4_define([b4_rhs_value], | |
947427ae | 114 | [yyvsp@{m4_eval([$2 - $1])@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3])]) |
01241d47 PH |
115 | |
116 | ||
117 | ||
118 | ## ----------- ## | |
119 | ## Locations. ## | |
120 | ## ----------- ## | |
121 | ||
01241d47 PH |
122 | # b4_lhs_location() |
123 | # ----------------- | |
124 | # Expansion of @$. | |
125 | m4_define([b4_lhs_location], | |
126 | [(*yylocp)]) | |
127 | ||
128 | ||
129 | # b4_rhs_location(RULE-LENGTH, NUM) | |
130 | # --------------------------------- | |
131 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
132 | # on RHS. | |
133 | m4_define([b4_rhs_location], | |
947427ae | 134 | [yyvsp@{m4_eval([$2 - $1])@}.yystate.yyloc]) |
01241d47 PH |
135 | |
136 | ||
b526ee61 AD |
137 | # We do want M4 expansion after # for CPP macros. |
138 | m4_changecom() | |
01241d47 | 139 | m4_divert(0)dnl |
947427ae | 140 | @output @output_parser_name@ |
fb8135fa AD |
141 | b4_copyright([Skeleton parser for GLR parsing with Bison], [2002]) |
142 | [ | |
01241d47 PH |
143 | /* This is the parser code for GLR (Generalized LR) parser. */ |
144 | ||
cf126971 PE |
145 | #include <stdio.h> |
146 | #include <stdlib.h> | |
147 | #include <string.h> | |
2a8d363a AD |
148 | #include <stdarg.h> |
149 | #include <setjmp.h> | |
01241d47 | 150 | |
2a8d363a AD |
151 | ]b4_identification |
152 | m4_if(b4_prefix[], [yy], [], | |
01241d47 PH |
153 | [/* If NAME_PREFIX is specified substitute the variables and functions |
154 | names. */ | |
155 | #define yyparse b4_prefix[]parse | |
156 | #define yylex b4_prefix[]lex | |
157 | #define yyerror b4_prefix[]error | |
158 | #define yylval b4_prefix[]lval | |
159 | #define yychar b4_prefix[]char | |
160 | #define yydebug b4_prefix[]debug | |
161 | #define yynerrs b4_prefix[]nerrs | |
162 | b4_location_if([#define yylloc b4_prefix[]lloc])]) | |
163 | ||
17acead5 | 164 | b4_token_defines(b4_tokens) |
01241d47 | 165 | |
17acead5 PE |
166 | /* Copy the first part of user declarations. */ |
167 | b4_pre_prologue[ | |
01241d47 PH |
168 | |
169 | /* Enabling traces. */ | |
170 | #ifndef YYDEBUG | |
171 | # define YYDEBUG ]b4_debug[ | |
172 | #endif | |
173 | ||
174 | /* Enabling verbose error messages. */ | |
175 | #ifdef YYERROR_VERBOSE | |
176 | # undef YYERROR_VERBOSE | |
177 | # define YYERROR_VERBOSE 1 | |
178 | #else | |
179 | # define YYERROR_VERBOSE ]b4_error_verbose[ | |
180 | #endif | |
181 | ||
fa8c3ebc | 182 | #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) |
01241d47 | 183 | ]m4_ifdef([b4_stype], |
437c2d80 | 184 | [b4_syncline([b4_stype_line], [b4_filename]) |
fa8c3ebc | 185 | typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE; |
996b1c7e | 186 | /* Line __line__ of glr.c. */ |
947427ae | 187 | b4_syncline([@oline@], [@ofile@])], |
fa8c3ebc PE |
188 | [typedef int YYSTYPE;])[ |
189 | # define YYSTYPE_IS_DECLARED 1 | |
01241d47 PH |
190 | # define YYSTYPE_IS_TRIVIAL 1 |
191 | #endif | |
192 | ||
fa8c3ebc PE |
193 | #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) |
194 | typedef struct YYLTYPE | |
01241d47 | 195 | { |
f50adbbd AD |
196 | int first_line; |
197 | int first_column; | |
198 | int last_line; | |
ffa4c58a | 199 | int last_column; |
fa8c3ebc PE |
200 | } YYLTYPE; |
201 | # define YYLTYPE_IS_DECLARED 1 | |
01241d47 PH |
202 | # define YYLTYPE_IS_TRIVIAL 1 |
203 | #endif | |
204 | ||
205 | /* Default (constant) values used for initialization for null | |
f6abc26e | 206 | right-hand sides. Unlike the standard yacc.c template, |
947427ae | 207 | here we set the default values of $$ and $@@ to zeroed-out |
01241d47 PH |
208 | values. Since the default value of these quantities is undefined, |
209 | this behavior is technically correct. */ | |
210 | static YYSTYPE yyval_default; | |
211 | static YYLTYPE yyloc_default; | |
212 | ||
213 | /* Copy the second part of user declarations. */ | |
214 | ]b4_post_prologue[ | |
215 | ||
996b1c7e | 216 | ]/* Line __line__ of glr.c. */ |
947427ae | 217 | b4_syncline([@oline@], [@ofile@]) |
01241d47 PH |
218 | [ |
219 | #if ! defined (__cplusplus) | |
220 | typedef char bool; | |
221 | # define yytrue 1 | |
222 | # define yyfalse 0 | |
223 | #endif | |
224 | ||
1154cced AD |
225 | /*-----------------. |
226 | | GCC extensions. | | |
227 | `-----------------*/ | |
228 | ||
229 | #ifndef __attribute__ | |
230 | /* This feature is available in gcc versions 2.5 and later. */ | |
231 | # if !defined (__GNUC__) || __GNUC__ < 2 || \ | |
232 | (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ | |
233 | # define __attribute__(Spec) /* empty */ | |
234 | # endif | |
235 | #endif | |
236 | ||
237 | #ifndef ATTRIBUTE_UNUSED | |
238 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
239 | #endif | |
240 | ||
01241d47 | 241 | /* YYFINAL -- State number of the termination state. */ |
7db2ed2d | 242 | #define YYFINAL ]b4_final_state_number[ |
39912f52 | 243 | /* YYLAST -- Last index in YYTABLE. */ |
01241d47 PH |
244 | #define YYLAST ]b4_last[ |
245 | ||
246 | /* YYNTOKENS -- Number of terminals. */ | |
7db2ed2d | 247 | #define YYNTOKENS ]b4_tokens_number[ |
01241d47 | 248 | /* YYNNTS -- Number of nonterminals. */ |
7db2ed2d | 249 | #define YYNNTS ]b4_nterms_number[ |
01241d47 | 250 | /* YYNRULES -- Number of rules. */ |
7db2ed2d | 251 | #define YYNRULES ]b4_rules_number[ |
01241d47 | 252 | /* YYNRULES -- Number of states. */ |
7db2ed2d | 253 | #define YYNSTATES ]b4_states_number[ |
01241d47 PH |
254 | /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ |
255 | #define YYMAXRHS ]b4_r2_max[ | |
256 | ||
257 | /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */ | |
258 | #define YYUNDEFTOK ]b4_undef_token_number[ | |
259 | #define YYMAXUTOK ]b4_user_token_number_max[ | |
260 | ||
b0400cc6 AD |
261 | #define YYTRANSLATE(YYX) \ |
262 | ((YYX <= 0) ? YYEOF : \ | |
263 | (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) | |
01241d47 PH |
264 | |
265 | /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ | |
a762e609 | 266 | static const ]b4_int_type_for([b4_translate])[ yytranslate[] = |
01241d47 PH |
267 | { |
268 | ]b4_translate[ | |
269 | }; | |
270 | ||
271 | #if YYDEBUG | |
272 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in | |
273 | YYRHS. */ | |
a762e609 | 274 | static const ]b4_int_type_for([b4_prhs])[ yyprhs[] = |
01241d47 PH |
275 | { |
276 | ]b4_prhs[ | |
277 | }; | |
278 | ||
279 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ | |
a762e609 | 280 | static const ]b4_int_type_for([b4_rhs])[ yyrhs[] = |
01241d47 PH |
281 | { |
282 | ]b4_rhs[ | |
283 | }; | |
284 | ||
285 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ | |
a762e609 | 286 | static const ]b4_int_type_for([b4_rline])[ yyrline[] = |
01241d47 PH |
287 | { |
288 | ]b4_rline[ | |
289 | }; | |
290 | #endif | |
291 | ||
292 | #if (YYDEBUG) || YYERROR_VERBOSE | |
293 | /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. | |
294 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ | |
295 | static const char *const yytname[] = | |
296 | { | |
297 | ]b4_tname[ | |
298 | }; | |
299 | ||
1154cced | 300 | #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0]))) |
01241d47 PH |
301 | #endif |
302 | ||
303 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ | |
a762e609 | 304 | static const ]b4_int_type_for([b4_r1])[ yyr1[] = |
01241d47 PH |
305 | { |
306 | ]b4_r1[ | |
307 | }; | |
308 | ||
309 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ | |
a762e609 | 310 | static const ]b4_int_type_for([b4_r2])[ yyr2[] = |
01241d47 PH |
311 | { |
312 | ]b4_r2[ | |
313 | }; | |
314 | ||
315 | /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ | |
a762e609 | 316 | static const ]b4_int_type_for([b4_dprec])[ yydprec[] = |
01241d47 PH |
317 | { |
318 | ]b4_dprec[ | |
319 | }; | |
320 | ||
321 | /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ | |
a762e609 | 322 | static const ]b4_int_type_for([b4_merger])[ yymerger[] = |
01241d47 PH |
323 | { |
324 | ]b4_merger[ | |
325 | }; | |
326 | ||
327 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE | |
328 | doesn't specify something else to do. Zero means the default is an | |
329 | error. */ | |
a762e609 | 330 | static const ]b4_int_type_for([b4_defact])[ yydefact[] = |
01241d47 PH |
331 | { |
332 | ]b4_defact[ | |
333 | }; | |
334 | ||
12b0043a | 335 | /* YYPDEFGOTO[NTERM-NUM]. */ |
a762e609 | 336 | static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] = |
01241d47 PH |
337 | { |
338 | ]b4_defgoto[ | |
339 | }; | |
340 | ||
341 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing | |
342 | STATE-NUM. */ | |
12b0043a | 343 | #define YYPACT_NINF ]b4_pact_ninf[ |
a762e609 | 344 | static const ]b4_int_type_for([b4_pact])[ yypact[] = |
01241d47 PH |
345 | { |
346 | ]b4_pact[ | |
347 | }; | |
348 | ||
349 | /* YYPGOTO[NTERM-NUM]. */ | |
a762e609 | 350 | static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] = |
01241d47 PH |
351 | { |
352 | ]b4_pgoto[ | |
353 | }; | |
354 | ||
355 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If | |
356 | positive, shift that token. If negative, reduce the rule which | |
f50adbbd | 357 | number is the opposite. If zero, do what YYDEFACT says. |
6e649e65 | 358 | If YYTABLE_NINF, syntax error. */ |
12b0043a | 359 | #define YYTABLE_NINF ]b4_table_ninf[ |
a762e609 | 360 | static const ]b4_int_type_for([b4_table])[ yytable[] = |
01241d47 PH |
361 | { |
362 | ]b4_table[ | |
363 | }; | |
364 | ||
ea99527d AD |
365 | /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of |
366 | list of conflicting reductions corresponding to action entry for | |
367 | state STATE-NUM in yytable. 0 means no conflicts. The list in | |
368 | yyconfl is terminated by a rule number of 0. */ | |
a762e609 | 369 | static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = |
01241d47 PH |
370 | { |
371 | ]b4_conflict_list_heads[ | |
372 | }; | |
373 | ||
ea99527d AD |
374 | /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by |
375 | 0, pointed into by YYCONFLP. */ | |
a762e609 AD |
376 | ]dnl Do not use b4_int_type_for here, since there are places where |
377 | dnl pointers onto yyconfl are taken, which type is "short *". | |
378 | dnl We probably ought to introduce a type for confl. | |
379 | [static const short yyconfl[] = | |
01241d47 PH |
380 | { |
381 | ]b4_conflicting_rules[ | |
382 | }; | |
383 | ||
a762e609 | 384 | static const ]b4_int_type_for([b4_check])[ yycheck[] = |
01241d47 PH |
385 | { |
386 | ]b4_check[ | |
387 | }; | |
388 | ||
7bd6c77e AD |
389 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
390 | symbol of state STATE-NUM. */ | |
391 | static const ]b4_int_type_for([b4_stos])[ yystos[] = | |
392 | { | |
393 | ]b4_stos[ | |
394 | }; | |
395 | ||
01241d47 | 396 | \f |
0245f82d | 397 | /* Prevent warning if -Wmissing-prototypes. */ |
2a8d363a | 398 | ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[ |
e7cb57c0 | 399 | |
2a8d363a | 400 | /* Error token number */ |
01241d47 PH |
401 | #define YYTERROR 1 |
402 | ||
403 | /* YYLLOC_DEFAULT -- Compute the default location (before the actions | |
404 | are run). */ | |
405 | ||
406 | #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc) | |
407 | ||
408 | #ifndef YYLLOC_DEFAULT | |
12b0043a | 409 | # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \ |
f50adbbd AD |
410 | yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \ |
411 | yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \ | |
412 | yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \ | |
413 | yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column; | |
01241d47 PH |
414 | #endif |
415 | ||
416 | /* YYLEX -- calling `yylex' with the right arguments. */ | |
21964f43 | 417 | #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[ |
01241d47 PH |
418 | |
419 | ]b4_pure_if( | |
420 | [ | |
01241d47 PH |
421 | #undef yynerrs |
422 | #define yynerrs (yystack->yyerrcnt) | |
423 | #undef yychar | |
424 | #define yychar (yystack->yyrawchar)], | |
425 | [YYSTYPE yylval; | |
426 | ||
427 | YYLTYPE yylloc; | |
428 | ||
429 | int yynerrs; | |
430 | int yychar;])[ | |
431 | ||
432 | static const int YYEOF = 0; | |
433 | static const int YYEMPTY = -2; | |
434 | ||
435 | typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; | |
436 | ||
437 | #define YYCHK(YYE) \ | |
438 | do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ | |
439 | while (0) | |
440 | ||
441 | #if YYDEBUG | |
442 | ||
443 | #if ! defined (YYFPRINTF) | |
444 | # define YYFPRINTF fprintf | |
445 | #endif | |
446 | ||
447 | # define YYDPRINTF(Args) \ | |
448 | do { \ | |
449 | if (yydebug) \ | |
450 | YYFPRINTF Args; \ | |
451 | } while (0) | |
7bd6c77e AD |
452 | |
453 | ]b4_yysymprint_generate([b4_c_ansi_function_def])[ | |
454 | ||
455 | # define YYDSYMPRINT(Args) \ | |
456 | do { \ | |
457 | if (yydebug) \ | |
458 | yysymprint Args; \ | |
459 | } while (0) | |
460 | ||
9c1e26bd AD |
461 | # define YYDSYMPRINTF(Title, Token, Value, Location) \ |
462 | do { \ | |
463 | if (yydebug) \ | |
464 | { \ | |
465 | YYFPRINTF (stderr, "%s ", Title); \ | |
466 | yysymprint (stderr, \ | |
467 | Token, Value]b4_location_if([, Location])[); \ | |
468 | YYFPRINTF (stderr, "\n"); \ | |
469 | } \ | |
470 | } while (0) | |
471 | ||
01241d47 PH |
472 | /* Nonzero means print parse trace. It is left uninitialized so that |
473 | multiple parsers can coexist. */ | |
474 | int yydebug; | |
7bd6c77e | 475 | |
01241d47 | 476 | #else /* !YYDEBUG */ |
7bd6c77e | 477 | |
1154cced | 478 | /* Avoid empty `if' bodies. */ |
ee16363f PE |
479 | # define YYDPRINTF(Args) |
480 | # define YYDSYMPRINT(Args) | |
481 | # define YYDSYMPRINTF(Title, Token, Value, Location) | |
7bd6c77e | 482 | |
01241d47 PH |
483 | #endif /* !YYDEBUG */ |
484 | ||
485 | /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
486 | #ifndef YYINITDEPTH | |
66d30cd4 | 487 | # define YYINITDEPTH ]b4_stack_depth_init[ |
01241d47 PH |
488 | #endif |
489 | ||
490 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only | |
491 | if the built-in stack extension method is used). | |
492 | ||
493 | Do not make this value too large; the results are undefined if | |
fb8135fa | 494 | SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) |
01241d47 PH |
495 | evaluated with infinite-precision integer arithmetic. */ |
496 | ||
497 | #if YYMAXDEPTH == 0 | |
498 | # undef YYMAXDEPTH | |
499 | #endif | |
500 | ||
501 | #ifndef YYMAXDEPTH | |
66d30cd4 | 502 | # define YYMAXDEPTH ]b4_stack_depth_max[ |
01241d47 PH |
503 | #endif |
504 | ||
505 | /* Minimum number of free items on the stack allowed after an | |
fb8135fa AD |
506 | allocation. This is to allow allocation and initialization |
507 | to be completed by functions that call expandGLRStack before the | |
508 | stack is expanded, thus insuring that all necessary pointers get | |
01241d47 PH |
509 | properly redirected to new data. */ |
510 | #define YYHEADROOM 2 | |
511 | ||
fa8c3ebc PE |
512 | #if (! defined (YYSTACKEXPANDABLE) \ |
513 | && (! defined (__cplusplus) \ | |
514 | || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL))) | |
01241d47 PH |
515 | #define YYSTACKEXPANDABLE 1 |
516 | #else | |
517 | #define YYSTACKEXPANDABLE 0 | |
518 | #endif | |
519 | ||
520 | /** State numbers, as in LALR(1) machine */ | |
521 | typedef int yyStateNum; | |
522 | ||
523 | /** Rule numbers, as in LALR(1) machine */ | |
524 | typedef int yyRuleNum; | |
525 | ||
526 | /** Grammar symbol */ | |
527 | typedef short yySymbol; | |
528 | ||
529 | /** Item references, as in LALR(1) machine */ | |
530 | typedef short yyItemNum; | |
531 | ||
532 | typedef struct yyGLRState yyGLRState; | |
533 | typedef struct yySemanticOption yySemanticOption; | |
534 | typedef union yyGLRStackItem yyGLRStackItem; | |
535 | typedef struct yyGLRStack yyGLRStack; | |
536 | typedef struct yyGLRStateSet yyGLRStateSet; | |
537 | ||
538 | struct yyGLRState { | |
fb8135fa | 539 | bool yyisState; |
01241d47 PH |
540 | bool yyresolved; |
541 | yyStateNum yylrState; | |
542 | yyGLRState* yypred; | |
543 | size_t yyposn; | |
544 | union { | |
545 | yySemanticOption* yyfirstVal; | |
546 | YYSTYPE yysval; | |
547 | } yysemantics; | |
548 | YYLTYPE yyloc; | |
549 | }; | |
550 | ||
551 | struct yyGLRStateSet { | |
552 | yyGLRState** yystates; | |
553 | size_t yysize, yycapacity; | |
554 | }; | |
555 | ||
556 | struct yySemanticOption { | |
557 | bool yyisState; | |
558 | yyRuleNum yyrule; | |
559 | yyGLRState* yystate; | |
560 | yySemanticOption* yynext; | |
561 | }; | |
562 | ||
563 | union yyGLRStackItem { | |
564 | yyGLRState yystate; | |
565 | yySemanticOption yyoption; | |
566 | }; | |
567 | ||
568 | struct yyGLRStack { | |
569 | int yyerrflag; | |
570 | int yyerrState; | |
571 | ]b4_pure_if( | |
572 | [ | |
573 | int yyerrcnt; | |
574 | int yyrawchar; | |
575 | ])[ | |
576 | yySymbol* yytokenp; | |
577 | jmp_buf yyexception_buffer; | |
578 | yyGLRStackItem* yyitems; | |
579 | yyGLRStackItem* yynextFree; | |
580 | int yyspaceLeft; | |
581 | yyGLRState* yysplitPoint; | |
582 | yyGLRState* yylastDeleted; | |
583 | yyGLRStateSet yytops; | |
584 | }; | |
585 | ||
586 | static void yyinitGLRStack (yyGLRStack* yystack, size_t yysize); | |
2a8d363a | 587 | static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[); |
01241d47 PH |
588 | static void yyfreeGLRStack (yyGLRStack* yystack); |
589 | ||
590 | static void | |
2a8d363a | 591 | yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...) |
01241d47 | 592 | { |
970785f1 | 593 | yystack->yyerrflag = 1; |
01241d47 PH |
594 | if (yyformat != NULL) |
595 | { | |
596 | char yymsg[256]; | |
597 | va_list yyap; | |
598 | va_start (yyap, yyformat); | |
01241d47 | 599 | vsprintf (yymsg, yyformat, yyap); |
93724f13 | 600 | yyerror (]b4_yyerror_args[yymsg); |
01241d47 PH |
601 | } |
602 | longjmp (yystack->yyexception_buffer, 1); | |
603 | } | |
604 | ||
605 | #if YYDEBUG || YYERROR_VERBOSE | |
606 | /** A printable representation of TOKEN. Valid until next call to | |
607 | * tokenName. */ | |
fb8135fa AD |
608 | static inline const char* |
609 | yytokenName (yySymbol yytoken) | |
01241d47 PH |
610 | { |
611 | return yytname[yytoken]; | |
612 | } | |
613 | #endif | |
614 | ||
615 | /** Perform user action for rule number YYN, with RHS length YYRHSLEN, | |
616 | * and top stack item YYVSP. YYLVALP points to place to put semantic | |
617 | * value ($$), and yylocp points to place for location information | |
947427ae | 618 | * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, |
01241d47 PH |
619 | * yyerr for YYERROR, yyabort for YYABORT. */ |
620 | static YYRESULTTAG | |
fb8135fa | 621 | yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, |
e7cb57c0 | 622 | YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack |
2a8d363a | 623 | ]b4_user_formals[) |
01241d47 | 624 | { |
1154cced AD |
625 | /* Avoid `unused' warnings in there are no $n. */ |
626 | (void) yystack; | |
627 | ||
fb8135fa | 628 | if (yyrhslen == 0) |
01241d47 PH |
629 | { |
630 | *yyvalp = yyval_default; | |
631 | *yylocp = yyloc_default; | |
632 | } | |
fb8135fa | 633 | else |
01241d47 PH |
634 | { |
635 | *yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval; | |
636 | *yylocp = yyvsp[1-yyrhslen].yystate.yyloc; | |
637 | } | |
01241d47 PH |
638 | # undef yyerrok |
639 | # define yyerrok (yystack->yyerrState = 0) | |
640 | # undef YYACCEPT | |
641 | # define YYACCEPT return yyaccept | |
642 | # undef YYABORT | |
643 | # define YYABORT return yyabort | |
644 | # undef YYERROR | |
645 | # define YYERROR return yyerr | |
646 | # undef YYRECOVERING | |
647 | # define YYRECOVERING (yystack->yyerrState != 0) | |
648 | # undef yyclearin | |
649 | # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY) | |
650 | # undef YYBACKUP | |
651 | # define YYBACKUP(Token, Value) \ | |
652 | do { \ | |
93724f13 | 653 | yyerror (]b4_yyerror_args["syntax error: cannot back up"); \ |
01241d47 PH |
654 | YYERROR; \ |
655 | } while (0) | |
656 | ||
657 | ] | |
fb8135fa | 658 | switch (yyn) |
01241d47 PH |
659 | { |
660 | b4_actions | |
661 | } | |
662 | ||
663 | return yyok; | |
01241d47 PH |
664 | # undef yyerrok |
665 | # undef YYABORT | |
666 | # undef YYACCEPT | |
667 | # undef YYERROR | |
668 | # undef YYBACKUP | |
669 | # undef yyclearin | |
670 | # undef YYRECOVERING | |
996b1c7e | 671 | /* Line __line__ of glr.c. */ |
947427ae | 672 | b4_syncline([@oline@], [@ofile@]) |
01241d47 PH |
673 | } |
674 | \f | |
675 | ||
676 | static YYSTYPE | |
677 | yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) | |
678 | { | |
679 | YYSTYPE yyval = *yy0; | |
2a8d363a | 680 | /* `Use' the arguments. */ |
1154cced AD |
681 | (void) yy0; |
682 | (void) yy1; | |
683 | ||
fb8135fa | 684 | switch (yyn) |
01241d47 PH |
685 | { |
686 | b4_mergers | |
687 | } | |
688 | return yyval; | |
689 | } | |
690 | [ | |
2a8d363a | 691 | /* Bison grammar-table manipulation. */ |
01241d47 | 692 | |
7bd6c77e AD |
693 | ]b4_yydestruct_generate([b4_c_ansi_function_def])[ |
694 | ||
01241d47 PH |
695 | /** Number of symbols composing the right hand side of rule #RULE. */ |
696 | static inline int | |
fb8135fa | 697 | yyrhsLength (yyRuleNum yyrule) |
01241d47 PH |
698 | { |
699 | return yyr2[yyrule]; | |
700 | } | |
701 | ||
702 | /** Left-hand-side symbol for rule #RULE. */ | |
703 | static inline yySymbol | |
fb8135fa | 704 | yylhsNonterm (yyRuleNum yyrule) |
01241d47 PH |
705 | { |
706 | return yyr1[yyrule]; | |
707 | } | |
708 | ||
944ed9f4 PE |
709 | #define yyis_pact_ninf(yystate) \ |
710 | ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1, | |
711 | 0, | |
712 | ((yystate) == YYPACT_NINF))[ | |
713 | ||
01241d47 PH |
714 | /** True iff LR state STATE has only a default reduction (regardless |
715 | * of token). */ | |
716 | static inline bool | |
717 | yyisDefaultedState (yyStateNum yystate) | |
718 | { | |
944ed9f4 | 719 | return yyis_pact_ninf (yypact[yystate]); |
01241d47 | 720 | } |
fb8135fa | 721 | |
01241d47 PH |
722 | /** The default reduction for STATE, assuming it has one. */ |
723 | static inline yyRuleNum | |
724 | yydefaultAction (yyStateNum yystate) | |
725 | { | |
726 | return yydefact[yystate]; | |
727 | } | |
728 | ||
df38312a | 729 | #define yyis_table_ninf(yytable_value) \ |
944ed9f4 PE |
730 | ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1, |
731 | 0, | |
df38312a | 732 | ((yytable_value) == YYTABLE_NINF))[ |
944ed9f4 | 733 | |
2a1fe6ed | 734 | /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. |
01241d47 PH |
735 | * Result R means |
736 | * R < 0: Reduce on rule -R. | |
737 | * R = 0: Error. | |
fb8135fa AD |
738 | * R > 0: Shift to state R. |
739 | * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of | |
01241d47 PH |
740 | * conflicting reductions. |
741 | */ | |
742 | static inline void | |
fb8135fa | 743 | yygetLRActions (yyStateNum yystate, int yytoken, |
01241d47 PH |
744 | int* yyaction, const short** yyconflicts) |
745 | { | |
746 | int yyindex = yypact[yystate] + yytoken; | |
f50adbbd | 747 | if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) |
01241d47 PH |
748 | { |
749 | *yyaction = -yydefact[yystate]; | |
750 | *yyconflicts = yyconfl; | |
751 | } | |
df38312a | 752 | else if (! yyis_table_ninf (yytable[yyindex])) |
01241d47 PH |
753 | { |
754 | *yyaction = yytable[yyindex]; | |
755 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
756 | } | |
f50adbbd AD |
757 | else |
758 | { | |
759 | *yyaction = 0; | |
760 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
761 | } | |
01241d47 PH |
762 | } |
763 | ||
764 | static inline yyStateNum | |
765 | yyLRgotoState (yyStateNum yystate, yySymbol yylhs) | |
766 | { | |
767 | int yyr; | |
768 | yyr = yypgoto[yylhs - YYNTOKENS] + yystate; | |
f50adbbd | 769 | if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) |
01241d47 PH |
770 | return yytable[yyr]; |
771 | else | |
772 | return yydefgoto[yylhs - YYNTOKENS]; | |
773 | } | |
774 | ||
775 | static inline bool | |
fb8135fa | 776 | yyisShiftAction (int yyaction) |
01241d47 | 777 | { |
39912f52 | 778 | return 0 < yyaction; |
01241d47 PH |
779 | } |
780 | ||
781 | static inline bool | |
fb8135fa | 782 | yyisErrorAction (int yyaction) |
01241d47 | 783 | { |
f50adbbd | 784 | return yyaction == 0; |
01241d47 PH |
785 | } |
786 | ||
787 | /* GLRStates */ | |
788 | ||
1154cced AD |
789 | static void |
790 | yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, | |
2a8d363a | 791 | yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[) |
01241d47 PH |
792 | { |
793 | yySemanticOption* yynewItem; | |
794 | yynewItem = &yystack->yynextFree->yyoption; | |
795 | yystack->yyspaceLeft -= 1; | |
796 | yystack->yynextFree += 1; | |
797 | yynewItem->yyisState = yyfalse; | |
6fed0802 | 798 | yynewItem->yystate = rhs; |
fb8135fa | 799 | yynewItem->yyrule = yyrule; |
01241d47 PH |
800 | yynewItem->yynext = yystate->yysemantics.yyfirstVal; |
801 | yystate->yysemantics.yyfirstVal = yynewItem; | |
802 | if (yystack->yyspaceLeft < YYHEADROOM) | |
2a8d363a | 803 | yyexpandGLRStack (yystack]b4_pure_args[); |
01241d47 PH |
804 | } |
805 | ||
806 | /* GLRStacks */ | |
807 | ||
808 | /** Initialize SET to a singleton set containing an empty stack. */ | |
809 | static void | |
810 | yyinitStateSet (yyGLRStateSet* yyset) | |
811 | { | |
812 | yyset->yysize = 1; | |
813 | yyset->yycapacity = 16; | |
814 | yyset->yystates = (yyGLRState**) malloc (16 * sizeof (yyset->yystates[0])); | |
815 | yyset->yystates[0] = NULL; | |
816 | } | |
817 | ||
fb8135fa | 818 | static void yyfreeStateSet (yyGLRStateSet* yyset) |
01241d47 PH |
819 | { |
820 | free (yyset->yystates); | |
821 | } | |
822 | ||
823 | /** Initialize STACK to a single empty stack, with total maximum | |
824 | * capacity for all stacks of SIZE. */ | |
825 | static void | |
826 | yyinitGLRStack (yyGLRStack* yystack, size_t yysize) | |
827 | { | |
828 | yystack->yyerrflag = 0; | |
829 | yystack->yyerrState = 0; | |
830 | yynerrs = 0; | |
831 | yystack->yyspaceLeft = yysize; | |
fb8135fa | 832 | yystack->yynextFree = yystack->yyitems = |
01241d47 PH |
833 | (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0])); |
834 | yystack->yysplitPoint = NULL; | |
835 | yystack->yylastDeleted = NULL; | |
836 | yyinitStateSet (&yystack->yytops); | |
837 | } | |
838 | ||
839 | #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ | |
840 | &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE | |
841 | ||
842 | /** If STACK is expandable, extend it. WARNING: Pointers into the | |
843 | stack from outside should be considered invalid after this call. | |
844 | We always expand when there are 1 or fewer items left AFTER an | |
845 | allocation, so that we can avoid having external pointers exist | |
846 | across an allocation. */ | |
847 | static void | |
2a8d363a | 848 | yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[) |
01241d47 PH |
849 | { |
850 | #if YYSTACKEXPANDABLE | |
851 | yyGLRStack yynewStack; | |
852 | yyGLRStackItem* yyp0, *yyp1; | |
853 | size_t yysize, yynewSize; | |
854 | size_t yyn; | |
855 | yysize = yystack->yynextFree - yystack->yyitems; | |
39912f52 | 856 | if (YYMAXDEPTH <= yysize) |
6e649e65 | 857 | yyFail (yystack][]b4_pure_args[, "parser stack overflow"); |
01241d47 | 858 | yynewSize = 2*yysize; |
39912f52 | 859 | if (YYMAXDEPTH < yynewSize) |
01241d47 PH |
860 | yynewSize = YYMAXDEPTH; |
861 | yyinitGLRStack (&yynewStack, yynewSize); | |
fb8135fa | 862 | for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize; |
39912f52 | 863 | 0 < yyn; |
fb8135fa | 864 | yyn -= 1, yyp0 += 1, yyp1 += 1) |
01241d47 PH |
865 | { |
866 | *yyp1 = *yyp0; | |
fb8135fa AD |
867 | if (*(bool*) yyp0) |
868 | { | |
01241d47 PH |
869 | yyGLRState* yys0 = &yyp0->yystate; |
870 | yyGLRState* yys1 = &yyp1->yystate; | |
fb8135fa AD |
871 | if (yys0->yypred != NULL) |
872 | yys1->yypred = | |
01241d47 PH |
873 | YYRELOC (yyp0, yyp1, yys0->yypred, yystate); |
874 | if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL) | |
fb8135fa | 875 | yys1->yysemantics.yyfirstVal = |
01241d47 PH |
876 | YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); |
877 | } | |
fb8135fa | 878 | else |
01241d47 PH |
879 | { |
880 | yySemanticOption* yyv0 = &yyp0->yyoption; | |
881 | yySemanticOption* yyv1 = &yyp1->yyoption; | |
882 | if (yyv0->yystate != NULL) | |
883 | yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); | |
884 | if (yyv0->yynext != NULL) | |
885 | yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); | |
886 | } | |
887 | } | |
888 | if (yystack->yysplitPoint != NULL) | |
fb8135fa | 889 | yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems, |
01241d47 | 890 | yystack->yysplitPoint, yystate); |
fb8135fa AD |
891 | |
892 | for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1) | |
01241d47 | 893 | if (yystack->yytops.yystates[yyn] != NULL) |
fb8135fa AD |
894 | yystack->yytops.yystates[yyn] = |
895 | YYRELOC (yystack->yyitems, yynewStack.yyitems, | |
01241d47 PH |
896 | yystack->yytops.yystates[yyn], yystate); |
897 | free (yystack->yyitems); | |
898 | yystack->yyitems = yynewStack.yyitems; | |
899 | yystack->yynextFree = yynewStack.yynextFree + yysize; | |
900 | yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize; | |
901 | ||
902 | #else | |
fb8135fa | 903 | |
6e649e65 | 904 | yyFail (yystack][]b4_lpure_args[, "parser stack overflow"); |
fb8135fa | 905 | #endif |
01241d47 PH |
906 | } |
907 | ||
908 | static void | |
fb8135fa | 909 | yyfreeGLRStack (yyGLRStack* yystack) |
01241d47 PH |
910 | { |
911 | free (yystack->yyitems); | |
912 | yyfreeStateSet (&yystack->yytops); | |
913 | } | |
914 | ||
915 | /** Assuming that S is a GLRState somewhere on STACK, update the | |
fb8135fa | 916 | * splitpoint of STACK, if needed, so that it is at least as deep as |
01241d47 PH |
917 | * S. */ |
918 | static inline void | |
fb8135fa | 919 | yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys) |
01241d47 | 920 | { |
fb8135fa | 921 | if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys) |
01241d47 PH |
922 | yystack->yysplitPoint = yys; |
923 | } | |
924 | ||
925 | /** Invalidate stack #K in STACK. */ | |
926 | static inline void | |
fb8135fa | 927 | yymarkStackDeleted (yyGLRStack* yystack, int yyk) |
01241d47 PH |
928 | { |
929 | if (yystack->yytops.yystates[yyk] != NULL) | |
930 | yystack->yylastDeleted = yystack->yytops.yystates[yyk]; | |
931 | yystack->yytops.yystates[yyk] = NULL; | |
932 | } | |
933 | ||
fb8135fa | 934 | /** Undelete the last stack that was marked as deleted. Can only be |
01241d47 PH |
935 | done once after a deletion, and only when all other stacks have |
936 | been deleted. */ | |
937 | static void | |
938 | yyundeleteLastStack (yyGLRStack* yystack) | |
939 | { | |
940 | if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0) | |
941 | return; | |
fb8135fa | 942 | yystack->yytops.yystates[0] = yystack->yylastDeleted; |
01241d47 PH |
943 | yystack->yytops.yysize = 1; |
944 | YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); | |
945 | yystack->yylastDeleted = NULL; | |
946 | } | |
947 | ||
948 | static inline void | |
949 | yyremoveDeletes (yyGLRStack* yystack) | |
950 | { | |
1154cced | 951 | size_t yyi, yyj; |
01241d47 | 952 | yyi = yyj = 0; |
fb8135fa | 953 | while (yyj < yystack->yytops.yysize) |
01241d47 PH |
954 | { |
955 | if (yystack->yytops.yystates[yyi] == NULL) | |
956 | { | |
1154cced | 957 | if (yyi == yyj) |
ee16363f PE |
958 | { |
959 | YYDPRINTF ((stderr, "Removing dead stacks.\n")); | |
960 | } | |
01241d47 PH |
961 | yystack->yytops.yysize -= 1; |
962 | } | |
fb8135fa | 963 | else |
01241d47 PH |
964 | { |
965 | yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi]; | |
966 | if (yyj != yyi) | |
ee16363f PE |
967 | { |
968 | YYDPRINTF ((stderr, "Rename stack %d -> %d.\n", yyi, yyj)); | |
969 | } | |
01241d47 PH |
970 | yyj += 1; |
971 | } | |
972 | yyi += 1; | |
973 | } | |
974 | } | |
975 | ||
fb8135fa | 976 | /** Shift to a new state on stack #K of STACK, corresponding to LR state |
01241d47 PH |
977 | * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */ |
978 | static inline void | |
fb8135fa | 979 | yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn, |
2a8d363a | 980 | YYSTYPE yysval, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
981 | { |
982 | yyGLRStackItem* yynewItem; | |
983 | ||
984 | yynewItem = yystack->yynextFree; | |
985 | yystack->yynextFree += 1; | |
986 | yystack->yyspaceLeft -= 1; | |
987 | yynewItem->yystate.yyisState = yytrue; | |
988 | yynewItem->yystate.yylrState = yylrState; | |
989 | yynewItem->yystate.yyposn = yyposn; | |
990 | yynewItem->yystate.yyresolved = yytrue; | |
991 | yynewItem->yystate.yypred = yystack->yytops.yystates[yyk]; | |
992 | yystack->yytops.yystates[yyk] = &yynewItem->yystate; | |
993 | yynewItem->yystate.yysemantics.yysval = yysval; | |
994 | yynewItem->yystate.yyloc = *yylocp; | |
995 | if (yystack->yyspaceLeft < YYHEADROOM) | |
2a8d363a | 996 | yyexpandGLRStack (yystack]b4_pure_args[); |
01241d47 PH |
997 | } |
998 | ||
999 | /** Shift to a new state on stack #K of STACK, to a new state | |
1000 | * corresponding to LR state LRSTATE, at input position POSN, with | |
1001 | * the (unresolved) semantic value of RHS under the action for RULE. */ | |
1002 | static inline void | |
fb8135fa | 1003 | yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState, |
2a8d363a | 1004 | size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[) |
01241d47 PH |
1005 | { |
1006 | yyGLRStackItem* yynewItem; | |
1007 | ||
1008 | yynewItem = yystack->yynextFree; | |
1009 | yynewItem->yystate.yyisState = yytrue; | |
1010 | yynewItem->yystate.yylrState = yylrState; | |
1011 | yynewItem->yystate.yyposn = yyposn; | |
1012 | yynewItem->yystate.yyresolved = yyfalse; | |
1013 | yynewItem->yystate.yypred = yystack->yytops.yystates[yyk]; | |
1014 | yynewItem->yystate.yysemantics.yyfirstVal = NULL; | |
1015 | yystack->yytops.yystates[yyk] = &yynewItem->yystate; | |
1016 | yystack->yynextFree += 1; | |
1017 | yystack->yyspaceLeft -= 1; | |
2a8d363a | 1018 | yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule]b4_pure_args[); |
01241d47 PH |
1019 | } |
1020 | ||
1021 | /** Pop the symbols consumed by reduction #RULE from the top of stack | |
fb8135fa AD |
1022 | * #K of STACK, and perform the appropriate semantic action on their |
1023 | * semantic values. Assumes that all ambiguities in semantic values | |
01241d47 PH |
1024 | * have been previously resolved. Set *VALP to the resulting value, |
1025 | * and *LOCP to the computed location (if any). Return value is as | |
1026 | * for userAction. */ | |
ff032592 | 1027 | static inline YYRESULTTAG |
01241d47 | 1028 | yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, |
2a8d363a | 1029 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1030 | { |
1031 | int yynrhs = yyrhsLength (yyrule); | |
1032 | ||
fb8135fa | 1033 | if (yystack->yysplitPoint == NULL) |
01241d47 PH |
1034 | { |
1035 | /* Standard special case: single stack. */ | |
6fed0802 | 1036 | yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk]; |
51dffcbc PE |
1037 | if (yyk != 0) |
1038 | abort (); | |
01241d47 PH |
1039 | yystack->yynextFree -= yynrhs; |
1040 | yystack->yyspaceLeft += yynrhs; | |
1041 | yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate; | |
fb8135fa | 1042 | if (yynrhs == 0) |
01241d47 PH |
1043 | { |
1044 | *yyvalp = yyval_default; | |
1045 | *yylocp = yyloc_default; | |
1046 | } | |
fb8135fa | 1047 | else |
01241d47 | 1048 | { |
6fed0802 AD |
1049 | *yyvalp = rhs[1-yynrhs].yystate.yysemantics.yysval; |
1050 | *yylocp = rhs[1-yynrhs].yystate.yyloc; | |
01241d47 | 1051 | } |
e7cb57c0 | 1052 | return yyuserAction (yyrule, yynrhs, rhs, |
2a8d363a | 1053 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 | 1054 | } |
fb8135fa | 1055 | else |
01241d47 PH |
1056 | { |
1057 | int yyi; | |
1058 | yyGLRState* yys; | |
1059 | yyGLRStackItem yyrhsVals[YYMAXRHS]; | |
39912f52 | 1060 | for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; 0 <= yyi; |
fb8135fa | 1061 | yyi -= 1, yys = yys->yypred) |
01241d47 | 1062 | { |
51dffcbc PE |
1063 | if (! yys->yypred) |
1064 | abort (); | |
01241d47 PH |
1065 | yyrhsVals[yyi].yystate.yyresolved = yytrue; |
1066 | yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval; | |
1067 | yyrhsVals[yyi].yystate.yyloc = yys->yyloc; | |
1068 | } | |
1069 | yyupdateSplit (yystack, yys); | |
1070 | yystack->yytops.yystates[yyk] = yys; | |
fb8135fa | 1071 | if (yynrhs == 0) |
01241d47 PH |
1072 | { |
1073 | *yyvalp = yyval_default; | |
1074 | *yylocp = yyloc_default; | |
1075 | } | |
fb8135fa | 1076 | else |
01241d47 PH |
1077 | { |
1078 | *yyvalp = yyrhsVals[0].yystate.yysemantics.yysval; | |
1079 | *yylocp = yyrhsVals[0].yystate.yyloc; | |
1080 | } | |
fb8135fa | 1081 | return yyuserAction (yyrule, yynrhs, yyrhsVals + (yynrhs-1), |
2a8d363a | 1082 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 PH |
1083 | } |
1084 | } | |
1085 | ||
e7cb57c0 AD |
1086 | #if !YYDEBUG |
1087 | # define YY_REDUCE_PRINT(K, Rule) | |
1088 | #else | |
1089 | # define YY_REDUCE_PRINT(K, Rule) \ | |
1090 | do { \ | |
1091 | if (yydebug) \ | |
1092 | yy_reduce_print (K, Rule); \ | |
1093 | } while (0) | |
1094 | ||
1095 | /*----------------------------------------------------------. | |
1096 | | Report that the RULE is going to be reduced on stack #K. | | |
1097 | `----------------------------------------------------------*/ | |
1098 | ||
1099 | static inline void | |
1100 | yy_reduce_print (size_t yyk, yyRuleNum yyrule) | |
1101 | { | |
1102 | int yyi; | |
c5d128ec PE |
1103 | unsigned int yylineno = yyrline[yyrule]; |
1104 | YYFPRINTF (stderr, "Reducing stack %d by rule %d (line %u), ", | |
1105 | yyk, yyrule - 1, yylineno); | |
e7cb57c0 AD |
1106 | /* Print the symbols being reduced, and their result. */ |
1107 | for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) | |
1108 | YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi])); | |
9c1e26bd | 1109 | YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule])); |
e7cb57c0 AD |
1110 | } |
1111 | #endif | |
1112 | ||
01241d47 PH |
1113 | /** Pop items off stack #K of STACK according to grammar rule RULE, |
1114 | * and push back on the resulting nonterminal symbol. Perform the | |
fb8135fa | 1115 | * semantic action associated with RULE and store its value with the |
01241d47 PH |
1116 | * newly pushed state, if FORCEEVAL or if STACK is currently |
1117 | * unambiguous. Otherwise, store the deferred semantic action with | |
1118 | * the new state. If the new state would have an identical input | |
1119 | * position, LR state, and predecessor to an existing state on the stack, | |
fb8135fa AD |
1120 | * it is identified with that existing state, eliminating stack #K from |
1121 | * the STACK. In this case, the (necessarily deferred) semantic value is | |
1122 | * added to the options for the existing state's semantic value. | |
01241d47 PH |
1123 | */ |
1124 | static inline YYRESULTTAG | |
1154cced | 1125 | yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, |
2a8d363a | 1126 | bool yyforceEval]b4_pure_formals[) |
01241d47 | 1127 | { |
1154cced | 1128 | size_t yyposn = yystack->yytops.yystates[yyk]->yyposn; |
01241d47 | 1129 | |
fb8135fa | 1130 | if (yyforceEval || yystack->yysplitPoint == NULL) |
01241d47 PH |
1131 | { |
1132 | YYSTYPE yysval; | |
1133 | YYLTYPE yyloc; | |
fb8135fa | 1134 | |
e7cb57c0 | 1135 | YY_REDUCE_PRINT (yyk, yyrule); |
2a8d363a | 1136 | YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); |
fb8135fa AD |
1137 | yyglrShift (yystack, yyk, |
1138 | yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState, | |
01241d47 | 1139 | yylhsNonterm (yyrule)), |
2a8d363a | 1140 | yyposn, yysval, &yyloc]b4_user_args[); |
01241d47 | 1141 | } |
fb8135fa | 1142 | else |
01241d47 | 1143 | { |
1154cced AD |
1144 | size_t yyi; |
1145 | int yyn; | |
01241d47 PH |
1146 | yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk]; |
1147 | yyStateNum yynewLRState; | |
1148 | ||
fb8135fa | 1149 | for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); |
39912f52 | 1150 | 0 < yyn; yyn -= 1) |
01241d47 PH |
1151 | { |
1152 | yys = yys->yypred; | |
51dffcbc PE |
1153 | if (! yys) |
1154 | abort (); | |
01241d47 PH |
1155 | } |
1156 | yyupdateSplit (yystack, yys); | |
1157 | yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); | |
fb8135fa | 1158 | YYDPRINTF ((stderr, |
01241d47 PH |
1159 | "Reduced stack %d by rule #%d; action deferred. " |
1160 | "Now in state %d.\n", | |
1161 | yyk, yyrule-1, yynewLRState)); | |
1162 | for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1) | |
fb8135fa | 1163 | if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL) |
01241d47 PH |
1164 | { |
1165 | yyGLRState* yyp, *yysplit = yystack->yysplitPoint; | |
1166 | yyp = yystack->yytops.yystates[yyi]; | |
fb8135fa | 1167 | while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) |
01241d47 | 1168 | { |
fb8135fa | 1169 | if (yyp->yylrState == yynewLRState && yyp->yypred == yys) |
01241d47 | 1170 | { |
2a8d363a | 1171 | yyaddDeferredAction (yystack, yyp, yys0, yyrule]b4_pure_args[); |
01241d47 PH |
1172 | yymarkStackDeleted (yystack, yyk); |
1173 | YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n", | |
1174 | yyk, yyi)); | |
ff032592 | 1175 | return yyok; |
01241d47 PH |
1176 | } |
1177 | yyp = yyp->yypred; | |
1178 | } | |
1179 | } | |
1180 | yystack->yytops.yystates[yyk] = yys; | |
2a8d363a | 1181 | yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule]b4_pure_args[); |
fb8135fa | 1182 | } |
ff032592 | 1183 | return yyok; |
01241d47 PH |
1184 | } |
1185 | ||
1186 | static int | |
1187 | yysplitStack (yyGLRStack* yystack, int yyk) | |
1188 | { | |
fb8135fa | 1189 | if (yystack->yysplitPoint == NULL) |
01241d47 | 1190 | { |
51dffcbc PE |
1191 | if (yyk != 0) |
1192 | abort (); | |
01241d47 PH |
1193 | yystack->yysplitPoint = yystack->yytops.yystates[yyk]; |
1194 | } | |
fb8135fa | 1195 | if (yystack->yytops.yysize >= yystack->yytops.yycapacity) |
01241d47 PH |
1196 | { |
1197 | yystack->yytops.yycapacity *= 2; | |
fb8135fa AD |
1198 | yystack->yytops.yystates = |
1199 | (yyGLRState**) realloc (yystack->yytops.yystates, | |
1200 | yystack->yytops.yycapacity | |
01241d47 PH |
1201 | * sizeof (yyGLRState*)); |
1202 | } | |
fb8135fa | 1203 | yystack->yytops.yystates[yystack->yytops.yysize] |
01241d47 PH |
1204 | = yystack->yytops.yystates[yyk]; |
1205 | yystack->yytops.yysize += 1; | |
1206 | return yystack->yytops.yysize-1; | |
1207 | } | |
1208 | ||
1209 | /** True iff Y0 and Y1 represent identical options at the top level. | |
1210 | * That is, they represent the same rule applied to RHS symbols | |
1211 | * that produce the same terminal symbols. */ | |
1212 | static bool | |
1213 | yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) | |
1214 | { | |
fb8135fa | 1215 | if (yyy0->yyrule == yyy1->yyrule) |
01241d47 PH |
1216 | { |
1217 | yyGLRState *yys0, *yys1; | |
1218 | int yyn; | |
fb8135fa | 1219 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, |
01241d47 PH |
1220 | yyn = yyrhsLength (yyy0->yyrule); |
1221 | yyn > 0; | |
1222 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1223 | if (yys0->yyposn != yys1->yyposn) | |
1224 | return yyfalse; | |
1225 | return yytrue; | |
1226 | } | |
1227 | else | |
1228 | return yyfalse; | |
1229 | } | |
1230 | ||
1231 | /** Assuming identicalOptions (Y0,Y1), (destructively) merge the | |
fb8135fa | 1232 | * alternative semantic values for the RHS-symbols of Y1 into the |
01241d47 PH |
1233 | * corresponding semantic value sets of the symbols of Y0. */ |
1234 | static void | |
1235 | yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) | |
1236 | { | |
1237 | yyGLRState *yys0, *yys1; | |
1238 | int yyn; | |
fb8135fa | 1239 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, |
01241d47 PH |
1240 | yyn = yyrhsLength (yyy0->yyrule); |
1241 | yyn > 0; | |
1242 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1243 | if (yys0 == yys1) | |
1244 | break; | |
fb8135fa | 1245 | else if (! yys0->yyresolved && ! yys1->yyresolved) |
01241d47 PH |
1246 | { |
1247 | yySemanticOption* yyz; | |
fb8135fa | 1248 | for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL; |
01241d47 | 1249 | yyz = yyz->yynext) |
ee16363f | 1250 | continue; |
01241d47 PH |
1251 | yyz->yynext = yys1->yysemantics.yyfirstVal; |
1252 | } | |
1253 | } | |
1254 | ||
1255 | /** Y0 and Y1 represent two possible actions to take in a given | |
1256 | * parsing state; return 0 if no combination is possible, | |
1257 | * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ | |
1258 | static int | |
1154cced | 1259 | yypreference (yySemanticOption* y0, yySemanticOption* y1) |
01241d47 | 1260 | { |
1154cced AD |
1261 | yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; |
1262 | int p0 = yydprec[r0], p1 = yydprec[r1]; | |
01241d47 | 1263 | |
1154cced | 1264 | if (p0 == p1) |
01241d47 | 1265 | { |
1154cced | 1266 | if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) |
01241d47 PH |
1267 | return 0; |
1268 | else | |
1269 | return 1; | |
1270 | } | |
1154cced | 1271 | if (p0 == 0 || p1 == 0) |
01241d47 | 1272 | return 0; |
1154cced | 1273 | if (p0 < p1) |
01241d47 | 1274 | return 3; |
39912f52 | 1275 | if (p1 < p0) |
01241d47 PH |
1276 | return 2; |
1277 | return 0; | |
1278 | } | |
1279 | ||
fb8135fa AD |
1280 | static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList, |
1281 | yyGLRStack* yystack, YYSTYPE* yyvalp, | |
2a8d363a | 1282 | YYLTYPE* yylocp]b4_user_formals[); |
01241d47 PH |
1283 | |
1284 | static YYRESULTTAG | |
2a8d363a | 1285 | yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[) |
01241d47 PH |
1286 | { |
1287 | YYRESULTTAG yyflag; | |
39912f52 | 1288 | if (0 < yyn) |
01241d47 | 1289 | { |
51dffcbc PE |
1290 | if (! yys->yypred) |
1291 | abort (); | |
2a8d363a | 1292 | yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[); |
01241d47 PH |
1293 | if (yyflag != yyok) |
1294 | return yyflag; | |
fb8135fa | 1295 | if (! yys->yyresolved) |
01241d47 PH |
1296 | { |
1297 | yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack, | |
e7cb57c0 | 1298 | &yys->yysemantics.yysval, &yys->yyloc |
2a8d363a | 1299 | ]b4_user_args[); |
01241d47 PH |
1300 | if (yyflag != yyok) |
1301 | return yyflag; | |
1302 | yys->yyresolved = yytrue; | |
1303 | } | |
1304 | } | |
1305 | return yyok; | |
1306 | } | |
1307 | ||
1308 | static YYRESULTTAG | |
fb8135fa | 1309 | yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, |
2a8d363a | 1310 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1311 | { |
1312 | yyGLRStackItem yyrhsVals[YYMAXRHS]; | |
1313 | int yynrhs, yyi; | |
1314 | yyGLRState* yys; | |
1315 | ||
1316 | yynrhs = yyrhsLength (yyopt->yyrule); | |
2a8d363a | 1317 | YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[)); |
39912f52 | 1318 | for (yyi = yynrhs-1, yys = yyopt->yystate; 0 <= yyi; |
01241d47 PH |
1319 | yyi -= 1, yys = yys->yypred) |
1320 | { | |
51dffcbc PE |
1321 | if (! yys->yypred) |
1322 | abort (); | |
01241d47 PH |
1323 | yyrhsVals[yyi].yystate.yyresolved = yytrue; |
1324 | yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval; | |
1325 | yyrhsVals[yyi].yystate.yyloc = yys->yyloc; | |
fb8135fa AD |
1326 | } |
1327 | return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + (yynrhs-1), | |
2a8d363a | 1328 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 PH |
1329 | } |
1330 | ||
1331 | #if YYDEBUG | |
e7cb57c0 AD |
1332 | static void |
1333 | yyreportTree (yySemanticOption* yyx, int yyindent) | |
01241d47 PH |
1334 | { |
1335 | int yynrhs = yyrhsLength (yyx->yyrule); | |
1336 | int yyi; | |
1337 | yyGLRState* yys; | |
1338 | yyGLRState* yystates[YYMAXRHS]; | |
782a05f9 | 1339 | yyGLRState yyleftmost_state; |
01241d47 | 1340 | |
39912f52 | 1341 | for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) |
01241d47 PH |
1342 | yystates[yyi] = yys; |
1343 | if (yys == NULL) | |
782a05f9 PE |
1344 | { |
1345 | yyleftmost_state.yyposn = 0; | |
1346 | yystates[0] = &yyleftmost_state; | |
1347 | } | |
01241d47 PH |
1348 | else |
1349 | yystates[0] = yys; | |
1350 | ||
39912f52 | 1351 | if (yyx->yystate->yyposn < yys->yyposn + 1) |
01241d47 | 1352 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n", |
fb8135fa | 1353 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), |
01241d47 PH |
1354 | yyx->yyrule); |
1355 | else | |
fb8135fa | 1356 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n", |
01241d47 PH |
1357 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), |
1358 | yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn); | |
fb8135fa | 1359 | for (yyi = 1; yyi <= yynrhs; yyi += 1) |
01241d47 | 1360 | { |
fb8135fa | 1361 | if (yystates[yyi]->yyresolved) |
01241d47 PH |
1362 | { |
1363 | if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) | |
1364 | YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "", | |
1365 | yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1])); | |
1366 | else | |
1367 | YYFPRINTF (stderr, "%*s%s <tokens %d .. %d>\n", yyindent+2, "", | |
1368 | yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]), | |
1369 | yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn); | |
1370 | } | |
fb8135fa | 1371 | else |
01241d47 PH |
1372 | yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); |
1373 | } | |
1374 | } | |
fb8135fa | 1375 | #endif |
01241d47 PH |
1376 | |
1377 | static void | |
1378 | yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, | |
2a8d363a | 1379 | yyGLRStack* yystack]b4_pure_formals[) |
01241d47 | 1380 | { |
1154cced AD |
1381 | /* `Unused' warnings. */ |
1382 | (void) yyx0; | |
1383 | (void) yyx1; | |
1384 | ||
01241d47 PH |
1385 | #if YYDEBUG |
1386 | YYFPRINTF (stderr, "Ambiguity detected.\n"); | |
1387 | YYFPRINTF (stderr, "Option 1,\n"); | |
1388 | yyreportTree (yyx0, 2); | |
1389 | YYFPRINTF (stderr, "\nOption 2,\n"); | |
1390 | yyreportTree (yyx1, 2); | |
1391 | YYFPRINTF (stderr, "\n"); | |
1392 | #endif | |
2a8d363a | 1393 | yyFail (yystack][]b4_pure_args[, "ambiguity detected"); |
01241d47 PH |
1394 | } |
1395 | ||
1396 | ||
1397 | /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated | |
1398 | * actions, and return the result. */ | |
1399 | static YYRESULTTAG | |
fb8135fa | 1400 | yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, |
2a8d363a | 1401 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1402 | { |
1403 | yySemanticOption* yybest; | |
1404 | yySemanticOption* yyp; | |
1405 | int yymerge; | |
1406 | ||
fb8135fa | 1407 | yybest = yyoptionList; |
01241d47 | 1408 | yymerge = 0; |
fb8135fa | 1409 | for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext) |
01241d47 PH |
1410 | { |
1411 | if (yyidenticalOptions (yybest, yyp)) | |
1412 | yymergeOptionSets (yybest, yyp); | |
1413 | else | |
fb8135fa | 1414 | switch (yypreference (yybest, yyp)) |
01241d47 PH |
1415 | { |
1416 | case 0: | |
2a8d363a | 1417 | yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[); |
01241d47 PH |
1418 | break; |
1419 | case 1: | |
1420 | yymerge = 1; | |
1421 | break; | |
1422 | case 2: | |
1423 | break; | |
1424 | case 3: | |
1425 | yybest = yyp; | |
1426 | yymerge = 0; | |
1427 | break; | |
1428 | } | |
1429 | } | |
1430 | ||
fb8135fa | 1431 | if (yymerge) |
01241d47 PH |
1432 | { |
1433 | int yyprec = yydprec[yybest->yyrule]; | |
2a8d363a | 1434 | YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[)); |
fb8135fa | 1435 | for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext) |
01241d47 | 1436 | { |
fb8135fa | 1437 | if (yyprec == yydprec[yyp->yyrule]) |
01241d47 PH |
1438 | { |
1439 | YYSTYPE yyval1; | |
1440 | YYLTYPE yydummy; | |
2a8d363a | 1441 | YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[)); |
01241d47 PH |
1442 | *yyvalp = yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1); |
1443 | } | |
1444 | } | |
1445 | return yyok; | |
1446 | } | |
1447 | else | |
2a8d363a | 1448 | return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[); |
01241d47 PH |
1449 | } |
1450 | ||
1451 | static YYRESULTTAG | |
2a8d363a | 1452 | yyresolveStack (yyGLRStack* yystack]b4_user_formals[) |
01241d47 | 1453 | { |
fb8135fa | 1454 | if (yystack->yysplitPoint != NULL) |
01241d47 PH |
1455 | { |
1456 | yyGLRState* yys; | |
1457 | int yyn; | |
1458 | ||
fb8135fa AD |
1459 | for (yyn = 0, yys = yystack->yytops.yystates[0]; |
1460 | yys != yystack->yysplitPoint; | |
01241d47 | 1461 | yys = yys->yypred, yyn += 1) |
ee16363f | 1462 | continue; |
e7cb57c0 | 1463 | YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack |
2a8d363a | 1464 | ]b4_user_args[)); |
01241d47 PH |
1465 | } |
1466 | return yyok; | |
1467 | } | |
1468 | ||
1469 | static void | |
fb8135fa | 1470 | yycompressStack (yyGLRStack* yystack) |
01241d47 PH |
1471 | { |
1472 | yyGLRState* yyp, *yyq, *yyr; | |
1473 | ||
1474 | if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL) | |
1475 | return; | |
1476 | ||
fb8135fa AD |
1477 | for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL; |
1478 | yyp != yystack->yysplitPoint; | |
01241d47 PH |
1479 | yyr = yyp, yyp = yyq, yyq = yyp->yypred) |
1480 | yyp->yypred = yyr; | |
fb8135fa | 1481 | |
01241d47 PH |
1482 | yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems; |
1483 | yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1; | |
1484 | yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems; | |
1485 | yystack->yysplitPoint = NULL; | |
1486 | yystack->yylastDeleted = NULL; | |
fb8135fa AD |
1487 | |
1488 | while (yyr != NULL) | |
1489 | { | |
01241d47 PH |
1490 | yystack->yynextFree->yystate = *yyr; |
1491 | yyr = yyr->yypred; | |
1492 | yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate; | |
1493 | yystack->yytops.yystates[0] = &yystack->yynextFree->yystate; | |
1494 | yystack->yynextFree += 1; | |
1495 | yystack->yyspaceLeft -= 1; | |
1496 | } | |
1497 | } | |
1498 | ||
1499 | static YYRESULTTAG | |
fb8135fa | 1500 | yyprocessOneStack (yyGLRStack* yystack, int yyk, |
e7cb57c0 | 1501 | size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp |
2a8d363a | 1502 | ]b4_user_formals[) |
01241d47 PH |
1503 | { |
1504 | int yyaction; | |
1505 | const short* yyconflicts; | |
1506 | yyRuleNum yyrule; | |
1507 | yySymbol* const yytokenp = yystack->yytokenp; | |
1508 | ||
fb8135fa | 1509 | while (yystack->yytops.yystates[yyk] != NULL) |
01241d47 PH |
1510 | { |
1511 | yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState; | |
b0937b22 | 1512 | YYDPRINTF ((stderr, "Stack %d Entering state %d\n", yyk, yystate)); |
01241d47 | 1513 | |
51dffcbc PE |
1514 | if (yystate == YYFINAL) |
1515 | abort (); | |
fb8135fa | 1516 | if (yyisDefaultedState (yystate)) |
01241d47 PH |
1517 | { |
1518 | yyrule = yydefaultAction (yystate); | |
fb8135fa | 1519 | if (yyrule == 0) |
01241d47 PH |
1520 | { |
1521 | YYDPRINTF ((stderr, "Stack %d dies.\n", yyk)); | |
1522 | yymarkStackDeleted (yystack, yyk); | |
1523 | return yyok; | |
1524 | } | |
2a8d363a | 1525 | YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_lpure_args[)); |
01241d47 | 1526 | } |
fb8135fa | 1527 | else |
01241d47 | 1528 | { |
fb8135fa | 1529 | if (*yytokenp == YYEMPTY) |
01241d47 | 1530 | { |
2a1fe6ed | 1531 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 | 1532 | yychar = YYLEX; |
b0400cc6 | 1533 | *yytokenp = YYTRANSLATE (yychar); |
9c1e26bd | 1534 | YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp); |
01241d47 PH |
1535 | } |
1536 | yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts); | |
1537 | ||
fb8135fa | 1538 | while (*yyconflicts != 0) |
01241d47 PH |
1539 | { |
1540 | int yynewStack = yysplitStack (yystack, yyk); | |
1541 | YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n", | |
1542 | yynewStack, yyk)); | |
e7cb57c0 | 1543 | YYCHK (yyglrReduce (yystack, yynewStack, |
2a8d363a | 1544 | *yyconflicts, yyfalse]b4_lpure_args[)); |
fb8135fa | 1545 | YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn, |
2a8d363a | 1546 | yylvalp, yyllocp]b4_user_args[)); |
01241d47 PH |
1547 | yyconflicts += 1; |
1548 | } | |
fb8135fa AD |
1549 | |
1550 | if (yyisShiftAction (yyaction)) | |
01241d47 | 1551 | { |
2a1fe6ed | 1552 | YYDPRINTF ((stderr, "Shifting token %s on stack %d, ", |
01241d47 | 1553 | yytokenName (*yytokenp), yyk)); |
2a8d363a AD |
1554 | yyglrShift (yystack, yyk, yyaction, yyposn+1, |
1555 | *yylvalp, yyllocp]b4_user_args[); | |
fb8135fa | 1556 | YYDPRINTF ((stderr, "which is now in state #%d\n", |
01241d47 PH |
1557 | yystack->yytops.yystates[yyk]->yylrState)); |
1558 | break; | |
1559 | } | |
fb8135fa | 1560 | else if (yyisErrorAction (yyaction)) |
01241d47 PH |
1561 | { |
1562 | YYDPRINTF ((stderr, "Stack %d dies.\n", yyk)); | |
1563 | yymarkStackDeleted (yystack, yyk); | |
1564 | break; | |
1565 | } | |
1566 | else | |
2a8d363a | 1567 | YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_lpure_args[)); |
01241d47 PH |
1568 | } |
1569 | } | |
1570 | return yyok; | |
1571 | } | |
1572 | ||
1573 | static void | |
ee16363f PE |
1574 | yyreportSyntaxError (yyGLRStack* yystack, |
1575 | YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) | |
01241d47 | 1576 | { |
1154cced AD |
1577 | /* `Unused' warnings. */ |
1578 | (void) yylvalp; | |
1579 | (void) yyllocp; | |
01241d47 PH |
1580 | |
1581 | if (yystack->yyerrState == 0) | |
1582 | { | |
fb8135fa | 1583 | #if YYERROR_VERBOSE |
1154cced | 1584 | yySymbol* const yytokenp = yystack->yytokenp; |
cf126971 PE |
1585 | int yyn, yyx, yycount; |
1586 | size_t yysize; | |
1154cced | 1587 | const char* yyprefix; |
01241d47 PH |
1588 | char* yyp; |
1589 | char* yymsg; | |
1590 | yyn = yypact[yystack->yytops.yystates[0]->yylrState]; | |
12b0043a | 1591 | if (YYPACT_NINF < yyn && yyn < YYLAST) |
01241d47 PH |
1592 | { |
1593 | yycount = 0; | |
1594 | /* Start YYX at -YYN if negative to avoid negative indexes in | |
1595 | YYCHECK. */ | |
6e649e65 | 1596 | yysize = sizeof ("syntax error, unexpected ") |
01241d47 PH |
1597 | + strlen (yytokenName (*yytokenp)); |
1598 | yyprefix = ", expecting "; | |
fb8135fa | 1599 | for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5; |
01241d47 | 1600 | yyx += 1) |
217598da | 1601 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
01241d47 PH |
1602 | yysize += strlen (yytokenName (yyx)) + strlen (yyprefix), |
1603 | yycount += 1, yyprefix = " or "; | |
1604 | yymsg = yyp = (char*) malloc (yysize); | |
6e649e65 PE |
1605 | sprintf (yyp, "syntax error, unexpected %s", |
1606 | yytokenName (*yytokenp)); | |
3eb49163 | 1607 | yyp += strlen (yyp); |
01241d47 PH |
1608 | if (yycount < 5) |
1609 | { | |
1610 | yyprefix = ", expecting "; | |
1611 | for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size; yyx += 1) | |
f50adbbd | 1612 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
01241d47 | 1613 | { |
3eb49163 PE |
1614 | sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx)); |
1615 | yyp += strlen (yyp); | |
01241d47 PH |
1616 | yyprefix = " or "; |
1617 | } | |
1618 | } | |
93724f13 | 1619 | yyerror (]b4_lyyerror_args[yymsg); |
01241d47 PH |
1620 | free (yymsg); |
1621 | } | |
1622 | else | |
1623 | #endif | |
6e649e65 | 1624 | yyerror (]b4_lyyerror_args["syntax error"); |
01241d47 PH |
1625 | yynerrs += 1; |
1626 | } | |
1627 | } | |
1628 | ||
f50adbbd | 1629 | /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP, |
01241d47 | 1630 | YYLVALP, and YYLLOCP point to the syntactic category, semantic |
f50adbbd | 1631 | value, and location of the lookahead. */ |
fb8135fa | 1632 | static void |
ee16363f PE |
1633 | yyrecoverSyntaxError (yyGLRStack* yystack, |
1634 | YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) | |
01241d47 PH |
1635 | { |
1636 | yySymbol* const yytokenp = yystack->yytokenp; | |
1154cced AD |
1637 | size_t yyk; |
1638 | int yyj; | |
01241d47 | 1639 | |
fb8135fa | 1640 | if (yystack->yyerrState == 0) |
01241d47 | 1641 | yystack->yyerrState = 3; |
fb8135fa | 1642 | else if (yystack->yyerrState == 3) |
2a1fe6ed AD |
1643 | /* We just shifted the error token and (perhaps) took some |
1644 | reductions. Skip tokens until we can proceed. */ | |
1645 | while (yytrue) | |
1646 | { | |
01241d47 | 1647 | if (*yytokenp == YYEOF) |
7bd6c77e AD |
1648 | { |
1649 | /* Now pop stack until we find a state that shifts the | |
1650 | error token. */ | |
1651 | while (yystack->yytops.yystates[0] != NULL) | |
1652 | { | |
1653 | yyGLRState *yys = yystack->yytops.yystates[0]; | |
9c1e26bd | 1654 | YYDSYMPRINTF ("Error: popping", |
7bd6c77e | 1655 | yystos[yys->yylrState], |
9c1e26bd | 1656 | &yys->yysemantics.yysval, &yys->yyloc); |
7bd6c77e AD |
1657 | yydestruct (yystos[yys->yylrState], |
1658 | &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); | |
1659 | yystack->yytops.yystates[0] = yys->yypred; | |
1660 | yystack->yynextFree -= 1; | |
1661 | yystack->yyspaceLeft += 1; | |
1662 | } | |
1663 | yyFail (yystack][]b4_lpure_args[, NULL); | |
1664 | } | |
01241d47 | 1665 | if (*yytokenp != YYEMPTY) |
7bd6c77e | 1666 | { |
9c1e26bd | 1667 | YYDSYMPRINTF ("Error: discarding", *yytokenp, yylvalp, yyllocp); |
7bd6c77e AD |
1668 | yydestruct (*yytokenp, yylvalp]b4_location_if([, yyllocp])[); |
1669 | } | |
2a1fe6ed | 1670 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 PH |
1671 | yychar = YYLEX; |
1672 | *yytokenp = YYTRANSLATE (yychar); | |
9c1e26bd | 1673 | YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp); |
01241d47 | 1674 | yyj = yypact[yystack->yytops.yystates[0]->yylrState]; |
944ed9f4 | 1675 | if (yyis_pact_ninf (yyj)) |
2a1fe6ed | 1676 | /* Something's not right; we shouldn't be here. */ |
2a8d363a | 1677 | yyFail (yystack][]b4_lpure_args[, NULL); |
01241d47 | 1678 | yyj += *yytokenp; |
ea99527d | 1679 | if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp) |
01241d47 PH |
1680 | { |
1681 | if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0) | |
1682 | return; | |
1683 | } | |
944ed9f4 | 1684 | else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj])) |
01241d47 | 1685 | return; |
2a1fe6ed | 1686 | } |
fb8135fa | 1687 | |
2a1fe6ed | 1688 | /* Reduce to one stack. */ |
01241d47 PH |
1689 | for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1) |
1690 | if (yystack->yytops.yystates[yyk] != NULL) | |
1691 | break; | |
1692 | if (yyk >= yystack->yytops.yysize) | |
2a8d363a | 1693 | yyFail (yystack][]b4_lpure_args[, NULL); |
01241d47 PH |
1694 | for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1) |
1695 | yymarkStackDeleted (yystack, yyk); | |
1696 | yyremoveDeletes (yystack); | |
1697 | yycompressStack (yystack); | |
1698 | ||
1699 | /* Now pop stack until we find a state that shifts the error token. */ | |
fb8135fa | 1700 | while (yystack->yytops.yystates[0] != NULL) |
01241d47 | 1701 | { |
7bd6c77e AD |
1702 | yyGLRState *yys = yystack->yytops.yystates[0]; |
1703 | yyj = yypact[yys->yylrState]; | |
944ed9f4 | 1704 | if (! yyis_pact_ninf (yyj)) |
01241d47 | 1705 | { |
944ed9f4 PE |
1706 | yyj += YYTERROR; |
1707 | if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR | |
1708 | && yyisShiftAction (yytable[yyj])) | |
1709 | { | |
7bd6c77e | 1710 | YYDPRINTF ((stderr, "Shifting error token, ")); |
944ed9f4 | 1711 | yyglrShift (yystack, 0, yytable[yyj], |
7bd6c77e | 1712 | yys->yyposn, *yylvalp, yyllocp]b4_user_args[); |
944ed9f4 PE |
1713 | break; |
1714 | } | |
01241d47 | 1715 | } |
9c1e26bd | 1716 | YYDSYMPRINTF ("Error: popping", |
7bd6c77e | 1717 | yystos[yys->yylrState], |
9c1e26bd | 1718 | &yys->yysemantics.yysval, &yys->yyloc); |
7bd6c77e AD |
1719 | yydestruct (yystos[yys->yylrState], |
1720 | &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); | |
1721 | yystack->yytops.yystates[0] = yys->yypred; | |
01241d47 PH |
1722 | yystack->yynextFree -= 1; |
1723 | yystack->yyspaceLeft += 1; | |
1724 | } | |
1725 | if (yystack->yytops.yystates[0] == NULL) | |
2a8d363a | 1726 | yyFail (yystack][]b4_lpure_args[, NULL); |
fb8135fa AD |
1727 | } |
1728 | ||
01241d47 PH |
1729 | #define YYCHK1(YYE) \ |
1730 | do { \ | |
1731 | switch (YYE) { \ | |
1732 | default: \ | |
1733 | break; \ | |
1734 | case yyabort: \ | |
1735 | yystack.yyerrflag = 1; \ | |
1736 | goto yyDone; \ | |
1737 | case yyaccept: \ | |
1738 | yystack.yyerrflag = 0; \ | |
1739 | goto yyDone; \ | |
1740 | case yyerr: \ | |
1741 | goto yyuser_error; \ | |
1742 | } \ | |
fb8135fa | 1743 | } while (0) |
01241d47 | 1744 | |
0245f82d AD |
1745 | |
1746 | /*----------. | |
1747 | | yyparse. | | |
1748 | `----------*/ | |
1749 | ||
1750 | ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[ | |
01241d47 PH |
1751 | { |
1752 | yySymbol yytoken; | |
1753 | yyGLRStack yystack; | |
1754 | size_t yyposn; | |
1755 | ]b4_pure_if( | |
1756 | [ | |
1757 | YYSTYPE yylval; | |
1758 | YYLTYPE yylloc; | |
1759 | #undef yychar | |
1760 | #define yychar (yystack.yyrawchar) | |
1761 | ])[ | |
1762 | ||
1763 | YYSTYPE* const yylvalp = &yylval; | |
1764 | YYLTYPE* const yyllocp = &yylloc; | |
fb8135fa | 1765 | |
01241d47 PH |
1766 | yyinitGLRStack (&yystack, YYINITDEPTH); |
1767 | yystack.yytokenp = &yytoken; | |
1768 | ||
2a1fe6ed AD |
1769 | YYDPRINTF ((stderr, "Starting parse\n")); |
1770 | ||
01241d47 PH |
1771 | if (setjmp (yystack.yyexception_buffer) != 0) |
1772 | goto yyDone; | |
1773 | ||
2a8d363a | 1774 | yyglrShift (&yystack, 0, 0, 0, yyval_default, &yyloc_default]b4_user_args[); |
01241d47 PH |
1775 | yytoken = YYEMPTY; |
1776 | yyposn = 0; | |
1777 | ||
fb8135fa | 1778 | while (yytrue) |
01241d47 | 1779 | { |
21964f43 AD |
1780 | /* For efficiency, we have two loops, the first of which is |
1781 | specialized to deterministic operation (single stack, no | |
1782 | potential ambiguity). */ | |
01241d47 | 1783 | /* Standard mode */ |
fb8135fa | 1784 | while (yytrue) |
01241d47 PH |
1785 | { |
1786 | yyRuleNum yyrule; | |
1787 | int yyaction; | |
1788 | const short* yyconflicts; | |
1789 | ||
1790 | yyStateNum yystate = yystack.yytops.yystates[0]->yylrState; | |
b0937b22 | 1791 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
01241d47 PH |
1792 | if (yystate == YYFINAL) |
1793 | goto yyDone; | |
fb8135fa | 1794 | if (yyisDefaultedState (yystate)) |
01241d47 PH |
1795 | { |
1796 | yyrule = yydefaultAction (yystate); | |
fb8135fa | 1797 | if (yyrule == 0) |
01241d47 | 1798 | { |
ee16363f | 1799 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1800 | goto yyuser_error; |
1801 | } | |
2a8d363a | 1802 | YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_lpure_args[)); |
01241d47 | 1803 | } |
fb8135fa | 1804 | else |
01241d47 | 1805 | { |
fb8135fa | 1806 | if (yytoken == YYEMPTY) |
01241d47 | 1807 | { |
2a1fe6ed | 1808 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 PH |
1809 | yychar = YYLEX; |
1810 | yytoken = YYTRANSLATE (yychar); | |
9c1e26bd | 1811 | YYDSYMPRINTF ("Next token is", yytoken, yylvalp, yyllocp); |
01241d47 PH |
1812 | } |
1813 | yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); | |
1814 | if (*yyconflicts != 0) | |
1815 | break; | |
fb8135fa | 1816 | if (yyisShiftAction (yyaction)) |
01241d47 | 1817 | { |
2a1fe6ed | 1818 | YYDPRINTF ((stderr, "Shifting token %s, ", |
01241d47 PH |
1819 | yytokenName (yytoken))); |
1820 | if (yytoken != YYEOF) | |
1821 | yytoken = YYEMPTY; | |
1822 | yyposn += 1; | |
2a8d363a AD |
1823 | yyglrShift (&yystack, 0, yyaction, yyposn, |
1824 | yylval, yyllocp]b4_user_args[); | |
39912f52 | 1825 | if (0 < yystack.yyerrState) |
01241d47 | 1826 | yystack.yyerrState -= 1; |
01241d47 PH |
1827 | } |
1828 | else if (yyisErrorAction (yyaction)) | |
1829 | { | |
ee16363f | 1830 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1831 | goto yyuser_error; |
1832 | } | |
1833 | else | |
2a8d363a | 1834 | YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_lpure_args[)); |
01241d47 PH |
1835 | } |
1836 | } | |
1837 | ||
fb8135fa | 1838 | while (yytrue) |
01241d47 PH |
1839 | { |
1840 | int yys; | |
1841 | int yyn = yystack.yytops.yysize; | |
1842 | for (yys = 0; yys < yyn; yys += 1) | |
1843 | YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, | |
2a8d363a | 1844 | yylvalp, yyllocp]b4_user_args[)); |
01241d47 PH |
1845 | yytoken = YYEMPTY; |
1846 | yyposn += 1; | |
1847 | yyremoveDeletes (&yystack); | |
1848 | if (yystack.yytops.yysize == 0) | |
1849 | { | |
1850 | yyundeleteLastStack (&yystack); | |
1851 | if (yystack.yytops.yysize == 0) | |
6e649e65 | 1852 | yyFail (&yystack][]b4_lpure_args[, "syntax error"); |
2a8d363a | 1853 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); |
01241d47 | 1854 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); |
ee16363f | 1855 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1856 | goto yyuser_error; |
1857 | } | |
fb8135fa | 1858 | else if (yystack.yytops.yysize == 1) |
01241d47 | 1859 | { |
2a8d363a | 1860 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); |
01241d47 PH |
1861 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); |
1862 | yycompressStack (&yystack); | |
1863 | break; | |
1864 | } | |
1865 | } | |
1866 | continue; | |
1867 | yyuser_error: | |
ee16363f | 1868 | yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1869 | yyposn = yystack.yytops.yystates[0]->yyposn; |
1870 | } | |
1871 | yyDone: | |
1872 | ; | |
1873 | ||
1874 | yyfreeGLRStack (&yystack); | |
1875 | return yystack.yyerrflag; | |
1876 | } | |
1877 | ||
1878 | /* DEBUGGING ONLY */ | |
1154cced AD |
1879 | static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED; |
1880 | static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED; | |
01241d47 | 1881 | |
1154cced | 1882 | static void |
cf126971 | 1883 | yy_yypstack (yyGLRState* yys) |
01241d47 | 1884 | { |
cf126971 | 1885 | if (yys->yypred) |
01241d47 | 1886 | { |
cf126971 PE |
1887 | yy_yypstack (yys->yypred); |
1888 | fprintf (stderr, " -> "); | |
01241d47 | 1889 | } |
947427ae | 1890 | fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long) yys->yyposn); |
cf126971 | 1891 | } |
01241d47 | 1892 | |
cf126971 PE |
1893 | static void |
1894 | yypstates (yyGLRState* yyst) | |
1895 | { | |
fb8135fa | 1896 | if (yyst == NULL) |
01241d47 | 1897 | fprintf (stderr, "<null>"); |
fb8135fa | 1898 | else |
01241d47 PH |
1899 | yy_yypstack (yyst); |
1900 | fprintf (stderr, "\n"); | |
1901 | } | |
1902 | ||
1154cced | 1903 | static void |
fb8135fa | 1904 | yypstack (yyGLRStack* yystack, int yyk) |
01241d47 PH |
1905 | { |
1906 | yypstates (yystack->yytops.yystates[yyk]); | |
1907 | } | |
1908 | ||
1909 | #define YYINDEX(YYX) \ | |
1910 | ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems) | |
1911 | ||
1912 | ||
1154cced | 1913 | static void |
fb8135fa | 1914 | yypdumpstack (yyGLRStack* yystack) |
01241d47 PH |
1915 | { |
1916 | yyGLRStackItem* yyp; | |
1154cced | 1917 | size_t yyi; |
fb8135fa | 1918 | for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1) |
01241d47 | 1919 | { |
cf126971 | 1920 | fprintf (stderr, "%3lu. ", (unsigned long) (yyp - yystack->yyitems)); |
fb8135fa | 1921 | if (*(bool*) yyp) |
01241d47 | 1922 | { |
cf126971 | 1923 | fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", |
fb8135fa | 1924 | yyp->yystate.yyresolved, yyp->yystate.yylrState, |
cf126971 PE |
1925 | (unsigned long) yyp->yystate.yyposn, |
1926 | (long) YYINDEX (yyp->yystate.yypred)); | |
fb8135fa | 1927 | if (! yyp->yystate.yyresolved) |
cf126971 PE |
1928 | fprintf (stderr, ", firstVal: %ld", |
1929 | (long) YYINDEX (yyp->yystate.yysemantics.yyfirstVal)); | |
01241d47 | 1930 | } |
fb8135fa | 1931 | else |
01241d47 | 1932 | { |
cf126971 PE |
1933 | fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld", |
1934 | yyp->yyoption.yyrule, | |
1935 | (long) YYINDEX (yyp->yyoption.yystate), | |
1936 | (long) YYINDEX (yyp->yyoption.yynext)); | |
01241d47 PH |
1937 | } |
1938 | fprintf (stderr, "\n"); | |
1939 | } | |
1940 | fprintf (stderr, "Tops:"); | |
1941 | for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1) | |
cf126971 PE |
1942 | fprintf (stderr, "%lu: %ld; ", (unsigned long) yyi, |
1943 | (long) YYINDEX (yystack->yytops.yystates[yyi])); | |
01241d47 PH |
1944 | fprintf (stderr, "\n"); |
1945 | } | |
01241d47 PH |
1946 | ] |
1947 | ||
1948 | b4_epilogue | |
1949 | m4_if(b4_defines_flag, 0, [], | |
947427ae | 1950 | [@output @output_header_name@ |
fb8135fa | 1951 | b4_copyright([Skeleton parser for GLR parsing with Bison], [2002]) |
01241d47 PH |
1952 | |
1953 | b4_token_defines(b4_tokens) | |
1954 | ||
fa8c3ebc | 1955 | #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) |
01241d47 | 1956 | m4_ifdef([b4_stype], |
437c2d80 | 1957 | [b4_syncline([b4_stype_line], [b4_filename]) |
fa8c3ebc | 1958 | typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE; |
996b1c7e | 1959 | /* Line __line__ of glr.c. */ |
947427ae | 1960 | b4_syncline([@oline@], [@ofile@])], |
fa8c3ebc PE |
1961 | [typedef int YYSTYPE;]) |
1962 | # define YYSTYPE_IS_DECLARED 1 | |
947427ae | 1963 | # define YYSTYPE_IS_TRIVIAL 1 |
01241d47 PH |
1964 | #endif |
1965 | ||
1966 | b4_pure_if([], | |
1967 | [extern YYSTYPE b4_prefix[]lval;]) | |
1968 | ||
1969 | b4_location_if( | |
fa8c3ebc PE |
1970 | [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) |
1971 | typedef struct YYLTYPE | |
01241d47 | 1972 | { |
f50adbbd AD |
1973 | int first_line; |
1974 | int first_column; | |
1975 | int last_line; | |
1976 | int last_column; | |
fa8c3ebc PE |
1977 | } YYLTYPE; |
1978 | # define YYLTYPE_IS_DECLARED 1 | |
1979 | # define YYLTYPE_IS_TRIVIAL 1 | |
01241d47 PH |
1980 | #endif |
1981 | ||
1982 | m4_if(b4_pure, [0], | |
1983 | [extern YYLTYPE b4_prefix[]lloc;]) | |
1984 | ]) | |
01241d47 | 1985 | ]) |