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