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