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