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