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