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