]>
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) \ | |
f5452625 PE |
513 | || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ |
514 | && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) | |
01241d47 PH |
515 | #define YYSTACKEXPANDABLE 1 |
516 | #else | |
517 | #define YYSTACKEXPANDABLE 0 | |
518 | #endif | |
519 | ||
520 | /** State numbers, as in LALR(1) machine */ | |
521 | typedef int yyStateNum; | |
522 | ||
523 | /** Rule numbers, as in LALR(1) machine */ | |
524 | typedef int yyRuleNum; | |
525 | ||
526 | /** Grammar symbol */ | |
527 | typedef short yySymbol; | |
528 | ||
529 | /** Item references, as in LALR(1) machine */ | |
530 | typedef short yyItemNum; | |
531 | ||
532 | typedef struct yyGLRState yyGLRState; | |
533 | typedef struct yySemanticOption yySemanticOption; | |
534 | typedef union yyGLRStackItem yyGLRStackItem; | |
535 | typedef struct yyGLRStack yyGLRStack; | |
536 | typedef struct yyGLRStateSet yyGLRStateSet; | |
537 | ||
538 | struct yyGLRState { | |
f7c398aa PE |
539 | yybool yyisState; |
540 | yybool yyresolved; | |
01241d47 PH |
541 | yyStateNum yylrState; |
542 | yyGLRState* yypred; | |
543 | size_t yyposn; | |
544 | union { | |
545 | yySemanticOption* yyfirstVal; | |
546 | YYSTYPE yysval; | |
547 | } yysemantics; | |
548 | YYLTYPE yyloc; | |
549 | }; | |
550 | ||
551 | struct yyGLRStateSet { | |
552 | yyGLRState** yystates; | |
553 | size_t yysize, yycapacity; | |
554 | }; | |
555 | ||
556 | struct yySemanticOption { | |
f7c398aa | 557 | yybool yyisState; |
01241d47 PH |
558 | yyRuleNum yyrule; |
559 | yyGLRState* yystate; | |
560 | yySemanticOption* yynext; | |
561 | }; | |
562 | ||
563 | union yyGLRStackItem { | |
564 | yyGLRState yystate; | |
565 | yySemanticOption yyoption; | |
566 | }; | |
567 | ||
568 | struct yyGLRStack { | |
569 | int yyerrflag; | |
570 | int yyerrState; | |
571 | ]b4_pure_if( | |
572 | [ | |
573 | int yyerrcnt; | |
574 | int yyrawchar; | |
575 | ])[ | |
576 | yySymbol* yytokenp; | |
577 | jmp_buf yyexception_buffer; | |
578 | yyGLRStackItem* yyitems; | |
579 | yyGLRStackItem* yynextFree; | |
580 | int yyspaceLeft; | |
581 | yyGLRState* yysplitPoint; | |
582 | yyGLRState* yylastDeleted; | |
583 | yyGLRStateSet yytops; | |
584 | }; | |
585 | ||
586 | static void yyinitGLRStack (yyGLRStack* yystack, size_t yysize); | |
2a8d363a | 587 | static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[); |
01241d47 PH |
588 | static void yyfreeGLRStack (yyGLRStack* yystack); |
589 | ||
590 | static void | |
2a8d363a | 591 | yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...) |
01241d47 | 592 | { |
970785f1 | 593 | yystack->yyerrflag = 1; |
01241d47 PH |
594 | if (yyformat != NULL) |
595 | { | |
596 | char yymsg[256]; | |
597 | va_list yyap; | |
598 | va_start (yyap, yyformat); | |
01241d47 | 599 | vsprintf (yymsg, yyformat, yyap); |
93724f13 | 600 | yyerror (]b4_yyerror_args[yymsg); |
01241d47 PH |
601 | } |
602 | longjmp (yystack->yyexception_buffer, 1); | |
603 | } | |
604 | ||
605 | #if YYDEBUG || YYERROR_VERBOSE | |
606 | /** A printable representation of TOKEN. Valid until next call to | |
607 | * tokenName. */ | |
fb8135fa AD |
608 | static inline const char* |
609 | yytokenName (yySymbol yytoken) | |
01241d47 PH |
610 | { |
611 | return yytname[yytoken]; | |
612 | } | |
613 | #endif | |
614 | ||
f868dc04 PH |
615 | /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting |
616 | * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred | |
c4749565 | 617 | * containing the pointer to the next state in the chain. Assumes |
6a84279c PE |
618 | * YYLOW1 < YYLOW0. */ |
619 | static void yyfillin (yyGLRStackItem *, int, int) ATTRIBUTE_UNUSED; | |
620 | static void | |
621 | yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) | |
f868dc04 PH |
622 | { |
623 | yyGLRState* s; | |
624 | int i; | |
c4749565 | 625 | s = yyvsp[yylow0].yystate.yypred; |
f868dc04 PH |
626 | for (i = yylow0-1; i >= yylow1; i -= 1) |
627 | { | |
628 | if (! s->yyresolved) | |
629 | abort (); | |
630 | yyvsp[i].yystate.yyresolved = yytrue; | |
631 | yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval; | |
632 | yyvsp[i].yystate.yyloc = s->yyloc; | |
633 | s = yyvsp[i].yystate.yypred = s->yypred; | |
634 | } | |
6a84279c PE |
635 | } |
636 | ||
637 | /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in | |
638 | YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. | |
639 | For convenience, always return YYLOW1. */ | |
640 | static inline int yyfill (yyGLRStackItem *, int *, int, yybool) | |
641 | ATTRIBUTE_UNUSED; | |
642 | static inline int | |
643 | yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) | |
644 | { | |
645 | if (!yynormal && yylow1 < *yylow) | |
646 | { | |
647 | yyfillin (yyvsp, *yylow, yylow1); | |
648 | *yylow = yylow1; | |
649 | } | |
f868dc04 PH |
650 | return yylow1; |
651 | } | |
652 | ||
01241d47 PH |
653 | /** Perform user action for rule number YYN, with RHS length YYRHSLEN, |
654 | * and top stack item YYVSP. YYLVALP points to place to put semantic | |
655 | * value ($$), and yylocp points to place for location information | |
947427ae | 656 | * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, |
01241d47 PH |
657 | * yyerr for YYERROR, yyabort for YYABORT. */ |
658 | static YYRESULTTAG | |
fb8135fa | 659 | yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, |
e7cb57c0 | 660 | YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack |
2a8d363a | 661 | ]b4_user_formals[) |
01241d47 | 662 | { |
6a84279c | 663 | yybool yynormal ATTRIBUTE_UNUSED = (yystack->yysplitPoint == NULL); |
f868dc04 | 664 | int yylow; |
1154cced | 665 | |
fb8135fa | 666 | if (yyrhslen == 0) |
01241d47 PH |
667 | { |
668 | *yyvalp = yyval_default; | |
669 | *yylocp = yyloc_default; | |
670 | } | |
fb8135fa | 671 | else |
01241d47 PH |
672 | { |
673 | *yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval; | |
674 | *yylocp = yyvsp[1-yyrhslen].yystate.yyloc; | |
675 | } | |
01241d47 PH |
676 | # undef yyerrok |
677 | # define yyerrok (yystack->yyerrState = 0) | |
678 | # undef YYACCEPT | |
679 | # define YYACCEPT return yyaccept | |
680 | # undef YYABORT | |
681 | # define YYABORT return yyabort | |
682 | # undef YYERROR | |
683 | # define YYERROR return yyerr | |
684 | # undef YYRECOVERING | |
685 | # define YYRECOVERING (yystack->yyerrState != 0) | |
686 | # undef yyclearin | |
687 | # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY) | |
f868dc04 | 688 | # undef YYFILL |
6a84279c | 689 | # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal) |
01241d47 PH |
690 | # undef YYBACKUP |
691 | # define YYBACKUP(Token, Value) \ | |
692 | do { \ | |
93724f13 | 693 | yyerror (]b4_yyerror_args["syntax error: cannot back up"); \ |
01241d47 PH |
694 | YYERROR; \ |
695 | } while (0) | |
696 | ||
697 | ] | |
f868dc04 | 698 | yylow = 1; |
fb8135fa | 699 | switch (yyn) |
01241d47 PH |
700 | { |
701 | b4_actions | |
702 | } | |
703 | ||
704 | return yyok; | |
01241d47 PH |
705 | # undef yyerrok |
706 | # undef YYABORT | |
707 | # undef YYACCEPT | |
708 | # undef YYERROR | |
709 | # undef YYBACKUP | |
710 | # undef yyclearin | |
711 | # undef YYRECOVERING | |
996b1c7e | 712 | /* Line __line__ of glr.c. */ |
947427ae | 713 | b4_syncline([@oline@], [@ofile@]) |
01241d47 PH |
714 | } |
715 | \f | |
716 | ||
717 | static YYSTYPE | |
718 | yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) | |
719 | { | |
720 | YYSTYPE yyval = *yy0; | |
2a8d363a | 721 | /* `Use' the arguments. */ |
1154cced AD |
722 | (void) yy0; |
723 | (void) yy1; | |
724 | ||
fb8135fa | 725 | switch (yyn) |
01241d47 PH |
726 | { |
727 | b4_mergers | |
728 | } | |
729 | return yyval; | |
730 | } | |
731 | [ | |
2a8d363a | 732 | /* Bison grammar-table manipulation. */ |
01241d47 | 733 | |
7bd6c77e AD |
734 | ]b4_yydestruct_generate([b4_c_ansi_function_def])[ |
735 | ||
01241d47 PH |
736 | /** Number of symbols composing the right hand side of rule #RULE. */ |
737 | static inline int | |
fb8135fa | 738 | yyrhsLength (yyRuleNum yyrule) |
01241d47 PH |
739 | { |
740 | return yyr2[yyrule]; | |
741 | } | |
742 | ||
743 | /** Left-hand-side symbol for rule #RULE. */ | |
744 | static inline yySymbol | |
fb8135fa | 745 | yylhsNonterm (yyRuleNum yyrule) |
01241d47 PH |
746 | { |
747 | return yyr1[yyrule]; | |
748 | } | |
749 | ||
944ed9f4 PE |
750 | #define yyis_pact_ninf(yystate) \ |
751 | ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1, | |
752 | 0, | |
753 | ((yystate) == YYPACT_NINF))[ | |
754 | ||
01241d47 PH |
755 | /** True iff LR state STATE has only a default reduction (regardless |
756 | * of token). */ | |
f7c398aa | 757 | static inline yybool |
01241d47 PH |
758 | yyisDefaultedState (yyStateNum yystate) |
759 | { | |
944ed9f4 | 760 | return yyis_pact_ninf (yypact[yystate]); |
01241d47 | 761 | } |
fb8135fa | 762 | |
01241d47 PH |
763 | /** The default reduction for STATE, assuming it has one. */ |
764 | static inline yyRuleNum | |
765 | yydefaultAction (yyStateNum yystate) | |
766 | { | |
767 | return yydefact[yystate]; | |
768 | } | |
769 | ||
df38312a | 770 | #define yyis_table_ninf(yytable_value) \ |
944ed9f4 PE |
771 | ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1, |
772 | 0, | |
df38312a | 773 | ((yytable_value) == YYTABLE_NINF))[ |
944ed9f4 | 774 | |
2a1fe6ed | 775 | /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. |
01241d47 PH |
776 | * Result R means |
777 | * R < 0: Reduce on rule -R. | |
778 | * R = 0: Error. | |
fb8135fa AD |
779 | * R > 0: Shift to state R. |
780 | * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of | |
01241d47 PH |
781 | * conflicting reductions. |
782 | */ | |
783 | static inline void | |
fb8135fa | 784 | yygetLRActions (yyStateNum yystate, int yytoken, |
01241d47 PH |
785 | int* yyaction, const short** yyconflicts) |
786 | { | |
787 | int yyindex = yypact[yystate] + yytoken; | |
f50adbbd | 788 | if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) |
01241d47 PH |
789 | { |
790 | *yyaction = -yydefact[yystate]; | |
791 | *yyconflicts = yyconfl; | |
792 | } | |
df38312a | 793 | else if (! yyis_table_ninf (yytable[yyindex])) |
01241d47 PH |
794 | { |
795 | *yyaction = yytable[yyindex]; | |
796 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
797 | } | |
f50adbbd AD |
798 | else |
799 | { | |
800 | *yyaction = 0; | |
801 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
802 | } | |
01241d47 PH |
803 | } |
804 | ||
805 | static inline yyStateNum | |
806 | yyLRgotoState (yyStateNum yystate, yySymbol yylhs) | |
807 | { | |
808 | int yyr; | |
809 | yyr = yypgoto[yylhs - YYNTOKENS] + yystate; | |
f50adbbd | 810 | if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) |
01241d47 PH |
811 | return yytable[yyr]; |
812 | else | |
813 | return yydefgoto[yylhs - YYNTOKENS]; | |
814 | } | |
815 | ||
f7c398aa | 816 | static inline yybool |
fb8135fa | 817 | yyisShiftAction (int yyaction) |
01241d47 | 818 | { |
39912f52 | 819 | return 0 < yyaction; |
01241d47 PH |
820 | } |
821 | ||
f7c398aa | 822 | static inline yybool |
fb8135fa | 823 | yyisErrorAction (int yyaction) |
01241d47 | 824 | { |
f50adbbd | 825 | return yyaction == 0; |
01241d47 PH |
826 | } |
827 | ||
828 | /* GLRStates */ | |
829 | ||
1154cced AD |
830 | static void |
831 | yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, | |
2a8d363a | 832 | yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[) |
01241d47 PH |
833 | { |
834 | yySemanticOption* yynewItem; | |
835 | yynewItem = &yystack->yynextFree->yyoption; | |
836 | yystack->yyspaceLeft -= 1; | |
837 | yystack->yynextFree += 1; | |
838 | yynewItem->yyisState = yyfalse; | |
6fed0802 | 839 | yynewItem->yystate = rhs; |
fb8135fa | 840 | yynewItem->yyrule = yyrule; |
01241d47 PH |
841 | yynewItem->yynext = yystate->yysemantics.yyfirstVal; |
842 | yystate->yysemantics.yyfirstVal = yynewItem; | |
843 | if (yystack->yyspaceLeft < YYHEADROOM) | |
2a8d363a | 844 | yyexpandGLRStack (yystack]b4_pure_args[); |
01241d47 PH |
845 | } |
846 | ||
847 | /* GLRStacks */ | |
848 | ||
849 | /** Initialize SET to a singleton set containing an empty stack. */ | |
850 | static void | |
851 | yyinitStateSet (yyGLRStateSet* yyset) | |
852 | { | |
853 | yyset->yysize = 1; | |
854 | yyset->yycapacity = 16; | |
855 | yyset->yystates = (yyGLRState**) malloc (16 * sizeof (yyset->yystates[0])); | |
856 | yyset->yystates[0] = NULL; | |
857 | } | |
858 | ||
fb8135fa | 859 | static void yyfreeStateSet (yyGLRStateSet* yyset) |
01241d47 PH |
860 | { |
861 | free (yyset->yystates); | |
862 | } | |
863 | ||
864 | /** Initialize STACK to a single empty stack, with total maximum | |
865 | * capacity for all stacks of SIZE. */ | |
866 | static void | |
867 | yyinitGLRStack (yyGLRStack* yystack, size_t yysize) | |
868 | { | |
869 | yystack->yyerrflag = 0; | |
870 | yystack->yyerrState = 0; | |
871 | yynerrs = 0; | |
872 | yystack->yyspaceLeft = yysize; | |
fb8135fa | 873 | yystack->yynextFree = yystack->yyitems = |
01241d47 PH |
874 | (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0])); |
875 | yystack->yysplitPoint = NULL; | |
876 | yystack->yylastDeleted = NULL; | |
877 | yyinitStateSet (&yystack->yytops); | |
878 | } | |
879 | ||
880 | #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ | |
881 | &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE | |
882 | ||
883 | /** If STACK is expandable, extend it. WARNING: Pointers into the | |
884 | stack from outside should be considered invalid after this call. | |
885 | We always expand when there are 1 or fewer items left AFTER an | |
886 | allocation, so that we can avoid having external pointers exist | |
887 | across an allocation. */ | |
888 | static void | |
2a8d363a | 889 | yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[) |
01241d47 PH |
890 | { |
891 | #if YYSTACKEXPANDABLE | |
892 | yyGLRStack yynewStack; | |
893 | yyGLRStackItem* yyp0, *yyp1; | |
894 | size_t yysize, yynewSize; | |
895 | size_t yyn; | |
896 | yysize = yystack->yynextFree - yystack->yyitems; | |
39912f52 | 897 | if (YYMAXDEPTH <= yysize) |
6e649e65 | 898 | yyFail (yystack][]b4_pure_args[, "parser stack overflow"); |
01241d47 | 899 | yynewSize = 2*yysize; |
39912f52 | 900 | if (YYMAXDEPTH < yynewSize) |
01241d47 PH |
901 | yynewSize = YYMAXDEPTH; |
902 | yyinitGLRStack (&yynewStack, yynewSize); | |
fb8135fa | 903 | for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize; |
39912f52 | 904 | 0 < yyn; |
fb8135fa | 905 | yyn -= 1, yyp0 += 1, yyp1 += 1) |
01241d47 PH |
906 | { |
907 | *yyp1 = *yyp0; | |
f7c398aa | 908 | if (*(yybool *) yyp0) |
fb8135fa | 909 | { |
01241d47 PH |
910 | yyGLRState* yys0 = &yyp0->yystate; |
911 | yyGLRState* yys1 = &yyp1->yystate; | |
fb8135fa AD |
912 | if (yys0->yypred != NULL) |
913 | yys1->yypred = | |
01241d47 PH |
914 | YYRELOC (yyp0, yyp1, yys0->yypred, yystate); |
915 | if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL) | |
fb8135fa | 916 | yys1->yysemantics.yyfirstVal = |
01241d47 PH |
917 | YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); |
918 | } | |
fb8135fa | 919 | else |
01241d47 PH |
920 | { |
921 | yySemanticOption* yyv0 = &yyp0->yyoption; | |
922 | yySemanticOption* yyv1 = &yyp1->yyoption; | |
923 | if (yyv0->yystate != NULL) | |
924 | yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); | |
925 | if (yyv0->yynext != NULL) | |
926 | yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); | |
927 | } | |
928 | } | |
929 | if (yystack->yysplitPoint != NULL) | |
fb8135fa | 930 | yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems, |
01241d47 | 931 | yystack->yysplitPoint, yystate); |
fb8135fa AD |
932 | |
933 | for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1) | |
01241d47 | 934 | if (yystack->yytops.yystates[yyn] != NULL) |
fb8135fa AD |
935 | yystack->yytops.yystates[yyn] = |
936 | YYRELOC (yystack->yyitems, yynewStack.yyitems, | |
01241d47 PH |
937 | yystack->yytops.yystates[yyn], yystate); |
938 | free (yystack->yyitems); | |
939 | yystack->yyitems = yynewStack.yyitems; | |
940 | yystack->yynextFree = yynewStack.yynextFree + yysize; | |
941 | yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize; | |
942 | ||
943 | #else | |
fb8135fa | 944 | |
1d2d7edd | 945 | yyFail (yystack][]b4_pure_args[, "parser stack overflow"); |
fb8135fa | 946 | #endif |
01241d47 PH |
947 | } |
948 | ||
949 | static void | |
fb8135fa | 950 | yyfreeGLRStack (yyGLRStack* yystack) |
01241d47 PH |
951 | { |
952 | free (yystack->yyitems); | |
953 | yyfreeStateSet (&yystack->yytops); | |
954 | } | |
955 | ||
956 | /** Assuming that S is a GLRState somewhere on STACK, update the | |
fb8135fa | 957 | * splitpoint of STACK, if needed, so that it is at least as deep as |
01241d47 PH |
958 | * S. */ |
959 | static inline void | |
fb8135fa | 960 | yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys) |
01241d47 | 961 | { |
fb8135fa | 962 | if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys) |
01241d47 PH |
963 | yystack->yysplitPoint = yys; |
964 | } | |
965 | ||
966 | /** Invalidate stack #K in STACK. */ | |
967 | static inline void | |
fb8135fa | 968 | yymarkStackDeleted (yyGLRStack* yystack, int yyk) |
01241d47 PH |
969 | { |
970 | if (yystack->yytops.yystates[yyk] != NULL) | |
971 | yystack->yylastDeleted = yystack->yytops.yystates[yyk]; | |
972 | yystack->yytops.yystates[yyk] = NULL; | |
973 | } | |
974 | ||
fb8135fa | 975 | /** Undelete the last stack that was marked as deleted. Can only be |
01241d47 PH |
976 | done once after a deletion, and only when all other stacks have |
977 | been deleted. */ | |
978 | static void | |
979 | yyundeleteLastStack (yyGLRStack* yystack) | |
980 | { | |
981 | if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0) | |
982 | return; | |
fb8135fa | 983 | yystack->yytops.yystates[0] = yystack->yylastDeleted; |
01241d47 PH |
984 | yystack->yytops.yysize = 1; |
985 | YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); | |
986 | yystack->yylastDeleted = NULL; | |
987 | } | |
988 | ||
989 | static inline void | |
990 | yyremoveDeletes (yyGLRStack* yystack) | |
991 | { | |
1154cced | 992 | size_t yyi, yyj; |
01241d47 | 993 | yyi = yyj = 0; |
fb8135fa | 994 | while (yyj < yystack->yytops.yysize) |
01241d47 PH |
995 | { |
996 | if (yystack->yytops.yystates[yyi] == NULL) | |
997 | { | |
1154cced | 998 | if (yyi == yyj) |
ee16363f PE |
999 | { |
1000 | YYDPRINTF ((stderr, "Removing dead stacks.\n")); | |
1001 | } | |
01241d47 PH |
1002 | yystack->yytops.yysize -= 1; |
1003 | } | |
fb8135fa | 1004 | else |
01241d47 PH |
1005 | { |
1006 | yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi]; | |
1007 | if (yyj != yyi) | |
ee16363f PE |
1008 | { |
1009 | YYDPRINTF ((stderr, "Rename stack %d -> %d.\n", yyi, yyj)); | |
1010 | } | |
01241d47 PH |
1011 | yyj += 1; |
1012 | } | |
1013 | yyi += 1; | |
1014 | } | |
1015 | } | |
1016 | ||
fb8135fa | 1017 | /** Shift to a new state on stack #K of STACK, corresponding to LR state |
01241d47 PH |
1018 | * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */ |
1019 | static inline void | |
fb8135fa | 1020 | yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn, |
2a8d363a | 1021 | YYSTYPE yysval, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1022 | { |
1023 | yyGLRStackItem* yynewItem; | |
1024 | ||
1025 | yynewItem = yystack->yynextFree; | |
1026 | yystack->yynextFree += 1; | |
1027 | yystack->yyspaceLeft -= 1; | |
1028 | yynewItem->yystate.yyisState = yytrue; | |
1029 | yynewItem->yystate.yylrState = yylrState; | |
1030 | yynewItem->yystate.yyposn = yyposn; | |
1031 | yynewItem->yystate.yyresolved = yytrue; | |
1032 | yynewItem->yystate.yypred = yystack->yytops.yystates[yyk]; | |
1033 | yystack->yytops.yystates[yyk] = &yynewItem->yystate; | |
1034 | yynewItem->yystate.yysemantics.yysval = yysval; | |
1035 | yynewItem->yystate.yyloc = *yylocp; | |
1036 | if (yystack->yyspaceLeft < YYHEADROOM) | |
2a8d363a | 1037 | yyexpandGLRStack (yystack]b4_pure_args[); |
01241d47 PH |
1038 | } |
1039 | ||
f868dc04 | 1040 | /** Shift stack #K of YYSTACK, to a new state corresponding to LR |
c4749565 | 1041 | * state YYLRSTATE, at input position YYPOSN, with the (unresolved) |
f868dc04 | 1042 | * semantic value of YYRHS under the action for YYRULE. */ |
01241d47 | 1043 | static inline void |
fb8135fa | 1044 | yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState, |
2a8d363a | 1045 | size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[) |
01241d47 PH |
1046 | { |
1047 | yyGLRStackItem* yynewItem; | |
1048 | ||
1049 | yynewItem = yystack->yynextFree; | |
1050 | yynewItem->yystate.yyisState = yytrue; | |
1051 | yynewItem->yystate.yylrState = yylrState; | |
1052 | yynewItem->yystate.yyposn = yyposn; | |
1053 | yynewItem->yystate.yyresolved = yyfalse; | |
1054 | yynewItem->yystate.yypred = yystack->yytops.yystates[yyk]; | |
1055 | yynewItem->yystate.yysemantics.yyfirstVal = NULL; | |
1056 | yystack->yytops.yystates[yyk] = &yynewItem->yystate; | |
1057 | yystack->yynextFree += 1; | |
1058 | yystack->yyspaceLeft -= 1; | |
2a8d363a | 1059 | yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule]b4_pure_args[); |
01241d47 PH |
1060 | } |
1061 | ||
1062 | /** Pop the symbols consumed by reduction #RULE from the top of stack | |
fb8135fa AD |
1063 | * #K of STACK, and perform the appropriate semantic action on their |
1064 | * semantic values. Assumes that all ambiguities in semantic values | |
01241d47 PH |
1065 | * have been previously resolved. Set *VALP to the resulting value, |
1066 | * and *LOCP to the computed location (if any). Return value is as | |
1067 | * for userAction. */ | |
ff032592 | 1068 | static inline YYRESULTTAG |
01241d47 | 1069 | yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, |
2a8d363a | 1070 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1071 | { |
1072 | int yynrhs = yyrhsLength (yyrule); | |
1073 | ||
fb8135fa | 1074 | if (yystack->yysplitPoint == NULL) |
01241d47 PH |
1075 | { |
1076 | /* Standard special case: single stack. */ | |
6fed0802 | 1077 | yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk]; |
51dffcbc PE |
1078 | if (yyk != 0) |
1079 | abort (); | |
01241d47 PH |
1080 | yystack->yynextFree -= yynrhs; |
1081 | yystack->yyspaceLeft += yynrhs; | |
1082 | yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate; | |
fb8135fa | 1083 | if (yynrhs == 0) |
01241d47 PH |
1084 | { |
1085 | *yyvalp = yyval_default; | |
1086 | *yylocp = yyloc_default; | |
1087 | } | |
fb8135fa | 1088 | else |
01241d47 | 1089 | { |
6fed0802 AD |
1090 | *yyvalp = rhs[1-yynrhs].yystate.yysemantics.yysval; |
1091 | *yylocp = rhs[1-yynrhs].yystate.yyloc; | |
01241d47 | 1092 | } |
e7cb57c0 | 1093 | return yyuserAction (yyrule, yynrhs, rhs, |
2a8d363a | 1094 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 | 1095 | } |
fb8135fa | 1096 | else |
01241d47 PH |
1097 | { |
1098 | int yyi; | |
1099 | yyGLRState* yys; | |
f868dc04 PH |
1100 | yyGLRStackItem yyrhsVals[YYMAXRHS+1]; |
1101 | yys = yyrhsVals[YYMAXRHS].yystate.yypred = yystack->yytops.yystates[yyk]; | |
1102 | for (yyi = 0; yyi < yynrhs; yyi += 1) | |
01241d47 | 1103 | { |
f868dc04 PH |
1104 | yys = yys->yypred; |
1105 | if (yys == NULL) | |
51dffcbc | 1106 | abort (); |
01241d47 PH |
1107 | } |
1108 | yyupdateSplit (yystack, yys); | |
1109 | yystack->yytops.yystates[yyk] = yys; | |
fb8135fa | 1110 | if (yynrhs == 0) |
01241d47 PH |
1111 | { |
1112 | *yyvalp = yyval_default; | |
1113 | *yylocp = yyloc_default; | |
1114 | } | |
fb8135fa | 1115 | else |
01241d47 | 1116 | { |
f868dc04 PH |
1117 | *yyvalp = yyrhsVals[1].yystate.yysemantics.yysval; |
1118 | *yylocp = yyrhsVals[1].yystate.yyloc; | |
01241d47 | 1119 | } |
f868dc04 | 1120 | return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS - 1, |
2a8d363a | 1121 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 PH |
1122 | } |
1123 | } | |
1124 | ||
e7cb57c0 AD |
1125 | #if !YYDEBUG |
1126 | # define YY_REDUCE_PRINT(K, Rule) | |
1127 | #else | |
1128 | # define YY_REDUCE_PRINT(K, Rule) \ | |
1129 | do { \ | |
1130 | if (yydebug) \ | |
1131 | yy_reduce_print (K, Rule); \ | |
1132 | } while (0) | |
1133 | ||
1134 | /*----------------------------------------------------------. | |
1135 | | Report that the RULE is going to be reduced on stack #K. | | |
1136 | `----------------------------------------------------------*/ | |
1137 | ||
1138 | static inline void | |
1139 | yy_reduce_print (size_t yyk, yyRuleNum yyrule) | |
1140 | { | |
1141 | int yyi; | |
47ee29cf | 1142 | unsigned int yylno = yyrline[yyrule]; |
c5d128ec | 1143 | YYFPRINTF (stderr, "Reducing stack %d by rule %d (line %u), ", |
47ee29cf | 1144 | yyk, yyrule - 1, yylno); |
e7cb57c0 AD |
1145 | /* Print the symbols being reduced, and their result. */ |
1146 | for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) | |
1147 | YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi])); | |
9c1e26bd | 1148 | YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule])); |
e7cb57c0 AD |
1149 | } |
1150 | #endif | |
1151 | ||
01241d47 PH |
1152 | /** Pop items off stack #K of STACK according to grammar rule RULE, |
1153 | * and push back on the resulting nonterminal symbol. Perform the | |
fb8135fa | 1154 | * semantic action associated with RULE and store its value with the |
01241d47 PH |
1155 | * newly pushed state, if FORCEEVAL or if STACK is currently |
1156 | * unambiguous. Otherwise, store the deferred semantic action with | |
1157 | * the new state. If the new state would have an identical input | |
1158 | * position, LR state, and predecessor to an existing state on the stack, | |
fb8135fa AD |
1159 | * it is identified with that existing state, eliminating stack #K from |
1160 | * the STACK. In this case, the (necessarily deferred) semantic value is | |
1161 | * added to the options for the existing state's semantic value. | |
01241d47 PH |
1162 | */ |
1163 | static inline YYRESULTTAG | |
1154cced | 1164 | yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, |
f7c398aa | 1165 | yybool yyforceEval]b4_pure_formals[) |
01241d47 | 1166 | { |
1154cced | 1167 | size_t yyposn = yystack->yytops.yystates[yyk]->yyposn; |
01241d47 | 1168 | |
fb8135fa | 1169 | if (yyforceEval || yystack->yysplitPoint == NULL) |
01241d47 PH |
1170 | { |
1171 | YYSTYPE yysval; | |
1172 | YYLTYPE yyloc; | |
fb8135fa | 1173 | |
e7cb57c0 | 1174 | YY_REDUCE_PRINT (yyk, yyrule); |
2a8d363a | 1175 | YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); |
fb8135fa AD |
1176 | yyglrShift (yystack, yyk, |
1177 | yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState, | |
01241d47 | 1178 | yylhsNonterm (yyrule)), |
2a8d363a | 1179 | yyposn, yysval, &yyloc]b4_user_args[); |
01241d47 | 1180 | } |
fb8135fa | 1181 | else |
01241d47 | 1182 | { |
1154cced AD |
1183 | size_t yyi; |
1184 | int yyn; | |
01241d47 PH |
1185 | yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk]; |
1186 | yyStateNum yynewLRState; | |
1187 | ||
fb8135fa | 1188 | for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); |
39912f52 | 1189 | 0 < yyn; yyn -= 1) |
01241d47 PH |
1190 | { |
1191 | yys = yys->yypred; | |
f868dc04 | 1192 | if (yys == NULL) |
51dffcbc | 1193 | abort (); |
01241d47 PH |
1194 | } |
1195 | yyupdateSplit (yystack, yys); | |
1196 | yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); | |
fb8135fa | 1197 | YYDPRINTF ((stderr, |
01241d47 PH |
1198 | "Reduced stack %d by rule #%d; action deferred. " |
1199 | "Now in state %d.\n", | |
1200 | yyk, yyrule-1, yynewLRState)); | |
1201 | for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1) | |
fb8135fa | 1202 | if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL) |
01241d47 PH |
1203 | { |
1204 | yyGLRState* yyp, *yysplit = yystack->yysplitPoint; | |
1205 | yyp = yystack->yytops.yystates[yyi]; | |
fb8135fa | 1206 | while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) |
01241d47 | 1207 | { |
fb8135fa | 1208 | if (yyp->yylrState == yynewLRState && yyp->yypred == yys) |
01241d47 | 1209 | { |
2a8d363a | 1210 | yyaddDeferredAction (yystack, yyp, yys0, yyrule]b4_pure_args[); |
01241d47 PH |
1211 | yymarkStackDeleted (yystack, yyk); |
1212 | YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n", | |
1213 | yyk, yyi)); | |
ff032592 | 1214 | return yyok; |
01241d47 PH |
1215 | } |
1216 | yyp = yyp->yypred; | |
1217 | } | |
1218 | } | |
1219 | yystack->yytops.yystates[yyk] = yys; | |
2a8d363a | 1220 | yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule]b4_pure_args[); |
fb8135fa | 1221 | } |
ff032592 | 1222 | return yyok; |
01241d47 PH |
1223 | } |
1224 | ||
1225 | static int | |
1226 | yysplitStack (yyGLRStack* yystack, int yyk) | |
1227 | { | |
fb8135fa | 1228 | if (yystack->yysplitPoint == NULL) |
01241d47 | 1229 | { |
51dffcbc PE |
1230 | if (yyk != 0) |
1231 | abort (); | |
01241d47 PH |
1232 | yystack->yysplitPoint = yystack->yytops.yystates[yyk]; |
1233 | } | |
fb8135fa | 1234 | if (yystack->yytops.yysize >= yystack->yytops.yycapacity) |
01241d47 PH |
1235 | { |
1236 | yystack->yytops.yycapacity *= 2; | |
fb8135fa AD |
1237 | yystack->yytops.yystates = |
1238 | (yyGLRState**) realloc (yystack->yytops.yystates, | |
1239 | yystack->yytops.yycapacity | |
01241d47 PH |
1240 | * sizeof (yyGLRState*)); |
1241 | } | |
fb8135fa | 1242 | yystack->yytops.yystates[yystack->yytops.yysize] |
01241d47 PH |
1243 | = yystack->yytops.yystates[yyk]; |
1244 | yystack->yytops.yysize += 1; | |
1245 | return yystack->yytops.yysize-1; | |
1246 | } | |
1247 | ||
1248 | /** True iff Y0 and Y1 represent identical options at the top level. | |
1249 | * That is, they represent the same rule applied to RHS symbols | |
1250 | * that produce the same terminal symbols. */ | |
f7c398aa | 1251 | static yybool |
01241d47 PH |
1252 | yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) |
1253 | { | |
fb8135fa | 1254 | if (yyy0->yyrule == yyy1->yyrule) |
01241d47 PH |
1255 | { |
1256 | yyGLRState *yys0, *yys1; | |
1257 | int yyn; | |
fb8135fa | 1258 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, |
01241d47 PH |
1259 | yyn = yyrhsLength (yyy0->yyrule); |
1260 | yyn > 0; | |
1261 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1262 | if (yys0->yyposn != yys1->yyposn) | |
1263 | return yyfalse; | |
1264 | return yytrue; | |
1265 | } | |
1266 | else | |
1267 | return yyfalse; | |
1268 | } | |
1269 | ||
1270 | /** Assuming identicalOptions (Y0,Y1), (destructively) merge the | |
fb8135fa | 1271 | * alternative semantic values for the RHS-symbols of Y1 into the |
01241d47 PH |
1272 | * corresponding semantic value sets of the symbols of Y0. */ |
1273 | static void | |
1274 | yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) | |
1275 | { | |
1276 | yyGLRState *yys0, *yys1; | |
1277 | int yyn; | |
fb8135fa | 1278 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, |
01241d47 PH |
1279 | yyn = yyrhsLength (yyy0->yyrule); |
1280 | yyn > 0; | |
1281 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1282 | if (yys0 == yys1) | |
1283 | break; | |
fb8135fa | 1284 | else if (! yys0->yyresolved && ! yys1->yyresolved) |
01241d47 PH |
1285 | { |
1286 | yySemanticOption* yyz; | |
fb8135fa | 1287 | for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL; |
01241d47 | 1288 | yyz = yyz->yynext) |
ee16363f | 1289 | continue; |
01241d47 PH |
1290 | yyz->yynext = yys1->yysemantics.yyfirstVal; |
1291 | } | |
1292 | } | |
1293 | ||
1294 | /** Y0 and Y1 represent two possible actions to take in a given | |
1295 | * parsing state; return 0 if no combination is possible, | |
1296 | * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ | |
1297 | static int | |
1154cced | 1298 | yypreference (yySemanticOption* y0, yySemanticOption* y1) |
01241d47 | 1299 | { |
1154cced AD |
1300 | yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; |
1301 | int p0 = yydprec[r0], p1 = yydprec[r1]; | |
01241d47 | 1302 | |
1154cced | 1303 | if (p0 == p1) |
01241d47 | 1304 | { |
1154cced | 1305 | if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) |
01241d47 PH |
1306 | return 0; |
1307 | else | |
1308 | return 1; | |
1309 | } | |
1154cced | 1310 | if (p0 == 0 || p1 == 0) |
01241d47 | 1311 | return 0; |
1154cced | 1312 | if (p0 < p1) |
01241d47 | 1313 | return 3; |
39912f52 | 1314 | if (p1 < p0) |
01241d47 PH |
1315 | return 2; |
1316 | return 0; | |
1317 | } | |
1318 | ||
fb8135fa AD |
1319 | static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList, |
1320 | yyGLRStack* yystack, YYSTYPE* yyvalp, | |
2a8d363a | 1321 | YYLTYPE* yylocp]b4_user_formals[); |
01241d47 PH |
1322 | |
1323 | static YYRESULTTAG | |
2a8d363a | 1324 | yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[) |
01241d47 PH |
1325 | { |
1326 | YYRESULTTAG yyflag; | |
39912f52 | 1327 | if (0 < yyn) |
01241d47 | 1328 | { |
f868dc04 | 1329 | if (yys->yypred == NULL) |
51dffcbc | 1330 | abort (); |
2a8d363a | 1331 | yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[); |
01241d47 PH |
1332 | if (yyflag != yyok) |
1333 | return yyflag; | |
fb8135fa | 1334 | if (! yys->yyresolved) |
01241d47 PH |
1335 | { |
1336 | yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack, | |
e7cb57c0 | 1337 | &yys->yysemantics.yysval, &yys->yyloc |
2a8d363a | 1338 | ]b4_user_args[); |
01241d47 PH |
1339 | if (yyflag != yyok) |
1340 | return yyflag; | |
1341 | yys->yyresolved = yytrue; | |
1342 | } | |
1343 | } | |
1344 | return yyok; | |
1345 | } | |
1346 | ||
1347 | static YYRESULTTAG | |
fb8135fa | 1348 | yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, |
2a8d363a | 1349 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 | 1350 | { |
f868dc04 PH |
1351 | yyGLRStackItem yyrhsVals[YYMAXRHS+1]; |
1352 | int yynrhs; | |
01241d47 PH |
1353 | |
1354 | yynrhs = yyrhsLength (yyopt->yyrule); | |
2a8d363a | 1355 | YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[)); |
f868dc04 PH |
1356 | yyrhsVals[YYMAXRHS].yystate.yypred = yyopt->yystate; |
1357 | return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + YYMAXRHS - 1, | |
2a8d363a | 1358 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 PH |
1359 | } |
1360 | ||
1361 | #if YYDEBUG | |
e7cb57c0 AD |
1362 | static void |
1363 | yyreportTree (yySemanticOption* yyx, int yyindent) | |
01241d47 PH |
1364 | { |
1365 | int yynrhs = yyrhsLength (yyx->yyrule); | |
1366 | int yyi; | |
1367 | yyGLRState* yys; | |
1368 | yyGLRState* yystates[YYMAXRHS]; | |
782a05f9 | 1369 | yyGLRState yyleftmost_state; |
01241d47 | 1370 | |
39912f52 | 1371 | for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) |
01241d47 PH |
1372 | yystates[yyi] = yys; |
1373 | if (yys == NULL) | |
782a05f9 PE |
1374 | { |
1375 | yyleftmost_state.yyposn = 0; | |
1376 | yystates[0] = &yyleftmost_state; | |
1377 | } | |
01241d47 PH |
1378 | else |
1379 | yystates[0] = yys; | |
1380 | ||
39912f52 | 1381 | if (yyx->yystate->yyposn < yys->yyposn + 1) |
01241d47 | 1382 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n", |
fb8135fa | 1383 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), |
01241d47 PH |
1384 | yyx->yyrule); |
1385 | else | |
fb8135fa | 1386 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n", |
01241d47 PH |
1387 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), |
1388 | yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn); | |
fb8135fa | 1389 | for (yyi = 1; yyi <= yynrhs; yyi += 1) |
01241d47 | 1390 | { |
fb8135fa | 1391 | if (yystates[yyi]->yyresolved) |
01241d47 PH |
1392 | { |
1393 | if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) | |
1394 | YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "", | |
1395 | yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1])); | |
1396 | else | |
1397 | YYFPRINTF (stderr, "%*s%s <tokens %d .. %d>\n", yyindent+2, "", | |
1398 | yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]), | |
1399 | yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn); | |
1400 | } | |
fb8135fa | 1401 | else |
01241d47 PH |
1402 | yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); |
1403 | } | |
1404 | } | |
fb8135fa | 1405 | #endif |
01241d47 PH |
1406 | |
1407 | static void | |
1408 | yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, | |
2a8d363a | 1409 | yyGLRStack* yystack]b4_pure_formals[) |
01241d47 | 1410 | { |
1154cced AD |
1411 | /* `Unused' warnings. */ |
1412 | (void) yyx0; | |
1413 | (void) yyx1; | |
1414 | ||
01241d47 PH |
1415 | #if YYDEBUG |
1416 | YYFPRINTF (stderr, "Ambiguity detected.\n"); | |
1417 | YYFPRINTF (stderr, "Option 1,\n"); | |
1418 | yyreportTree (yyx0, 2); | |
1419 | YYFPRINTF (stderr, "\nOption 2,\n"); | |
1420 | yyreportTree (yyx1, 2); | |
1421 | YYFPRINTF (stderr, "\n"); | |
1422 | #endif | |
2a8d363a | 1423 | yyFail (yystack][]b4_pure_args[, "ambiguity detected"); |
01241d47 PH |
1424 | } |
1425 | ||
1426 | ||
1427 | /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated | |
1428 | * actions, and return the result. */ | |
1429 | static YYRESULTTAG | |
fb8135fa | 1430 | yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, |
2a8d363a | 1431 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1432 | { |
1433 | yySemanticOption* yybest; | |
1434 | yySemanticOption* yyp; | |
1435 | int yymerge; | |
1436 | ||
fb8135fa | 1437 | yybest = yyoptionList; |
01241d47 | 1438 | yymerge = 0; |
fb8135fa | 1439 | for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext) |
01241d47 PH |
1440 | { |
1441 | if (yyidenticalOptions (yybest, yyp)) | |
1442 | yymergeOptionSets (yybest, yyp); | |
1443 | else | |
fb8135fa | 1444 | switch (yypreference (yybest, yyp)) |
01241d47 PH |
1445 | { |
1446 | case 0: | |
2a8d363a | 1447 | yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[); |
01241d47 PH |
1448 | break; |
1449 | case 1: | |
1450 | yymerge = 1; | |
1451 | break; | |
1452 | case 2: | |
1453 | break; | |
1454 | case 3: | |
1455 | yybest = yyp; | |
1456 | yymerge = 0; | |
1457 | break; | |
1458 | } | |
1459 | } | |
1460 | ||
fb8135fa | 1461 | if (yymerge) |
01241d47 PH |
1462 | { |
1463 | int yyprec = yydprec[yybest->yyrule]; | |
2a8d363a | 1464 | YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[)); |
fb8135fa | 1465 | for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext) |
01241d47 | 1466 | { |
fb8135fa | 1467 | if (yyprec == yydprec[yyp->yyrule]) |
01241d47 PH |
1468 | { |
1469 | YYSTYPE yyval1; | |
1470 | YYLTYPE yydummy; | |
2a8d363a | 1471 | YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[)); |
01241d47 PH |
1472 | *yyvalp = yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1); |
1473 | } | |
1474 | } | |
1475 | return yyok; | |
1476 | } | |
1477 | else | |
2a8d363a | 1478 | return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[); |
01241d47 PH |
1479 | } |
1480 | ||
1481 | static YYRESULTTAG | |
2a8d363a | 1482 | yyresolveStack (yyGLRStack* yystack]b4_user_formals[) |
01241d47 | 1483 | { |
fb8135fa | 1484 | if (yystack->yysplitPoint != NULL) |
01241d47 PH |
1485 | { |
1486 | yyGLRState* yys; | |
1487 | int yyn; | |
1488 | ||
fb8135fa AD |
1489 | for (yyn = 0, yys = yystack->yytops.yystates[0]; |
1490 | yys != yystack->yysplitPoint; | |
01241d47 | 1491 | yys = yys->yypred, yyn += 1) |
ee16363f | 1492 | continue; |
e7cb57c0 | 1493 | YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack |
2a8d363a | 1494 | ]b4_user_args[)); |
01241d47 PH |
1495 | } |
1496 | return yyok; | |
1497 | } | |
1498 | ||
1499 | static void | |
fb8135fa | 1500 | yycompressStack (yyGLRStack* yystack) |
01241d47 PH |
1501 | { |
1502 | yyGLRState* yyp, *yyq, *yyr; | |
1503 | ||
1504 | if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL) | |
1505 | return; | |
1506 | ||
fb8135fa AD |
1507 | for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL; |
1508 | yyp != yystack->yysplitPoint; | |
01241d47 PH |
1509 | yyr = yyp, yyp = yyq, yyq = yyp->yypred) |
1510 | yyp->yypred = yyr; | |
fb8135fa | 1511 | |
01241d47 PH |
1512 | yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems; |
1513 | yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1; | |
1514 | yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems; | |
1515 | yystack->yysplitPoint = NULL; | |
1516 | yystack->yylastDeleted = NULL; | |
fb8135fa AD |
1517 | |
1518 | while (yyr != NULL) | |
1519 | { | |
01241d47 PH |
1520 | yystack->yynextFree->yystate = *yyr; |
1521 | yyr = yyr->yypred; | |
1522 | yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate; | |
1523 | yystack->yytops.yystates[0] = &yystack->yynextFree->yystate; | |
1524 | yystack->yynextFree += 1; | |
1525 | yystack->yyspaceLeft -= 1; | |
1526 | } | |
1527 | } | |
1528 | ||
1529 | static YYRESULTTAG | |
fb8135fa | 1530 | yyprocessOneStack (yyGLRStack* yystack, int yyk, |
e7cb57c0 | 1531 | size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp |
2a8d363a | 1532 | ]b4_user_formals[) |
01241d47 PH |
1533 | { |
1534 | int yyaction; | |
1535 | const short* yyconflicts; | |
1536 | yyRuleNum yyrule; | |
1537 | yySymbol* const yytokenp = yystack->yytokenp; | |
1538 | ||
fb8135fa | 1539 | while (yystack->yytops.yystates[yyk] != NULL) |
01241d47 PH |
1540 | { |
1541 | yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState; | |
b0937b22 | 1542 | YYDPRINTF ((stderr, "Stack %d Entering state %d\n", yyk, yystate)); |
01241d47 | 1543 | |
51dffcbc PE |
1544 | if (yystate == YYFINAL) |
1545 | abort (); | |
fb8135fa | 1546 | if (yyisDefaultedState (yystate)) |
01241d47 PH |
1547 | { |
1548 | yyrule = yydefaultAction (yystate); | |
fb8135fa | 1549 | if (yyrule == 0) |
01241d47 PH |
1550 | { |
1551 | YYDPRINTF ((stderr, "Stack %d dies.\n", yyk)); | |
1552 | yymarkStackDeleted (yystack, yyk); | |
1553 | return yyok; | |
1554 | } | |
2a8d363a | 1555 | YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_lpure_args[)); |
01241d47 | 1556 | } |
fb8135fa | 1557 | else |
01241d47 | 1558 | { |
fb8135fa | 1559 | if (*yytokenp == YYEMPTY) |
01241d47 | 1560 | { |
2a1fe6ed | 1561 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 | 1562 | yychar = YYLEX; |
b0400cc6 | 1563 | *yytokenp = YYTRANSLATE (yychar); |
9c1e26bd | 1564 | YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp); |
01241d47 PH |
1565 | } |
1566 | yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts); | |
1567 | ||
fb8135fa | 1568 | while (*yyconflicts != 0) |
01241d47 PH |
1569 | { |
1570 | int yynewStack = yysplitStack (yystack, yyk); | |
1571 | YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n", | |
1572 | yynewStack, yyk)); | |
e7cb57c0 | 1573 | YYCHK (yyglrReduce (yystack, yynewStack, |
2a8d363a | 1574 | *yyconflicts, yyfalse]b4_lpure_args[)); |
fb8135fa | 1575 | YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn, |
2a8d363a | 1576 | yylvalp, yyllocp]b4_user_args[)); |
01241d47 PH |
1577 | yyconflicts += 1; |
1578 | } | |
fb8135fa AD |
1579 | |
1580 | if (yyisShiftAction (yyaction)) | |
01241d47 | 1581 | { |
2a1fe6ed | 1582 | YYDPRINTF ((stderr, "Shifting token %s on stack %d, ", |
01241d47 | 1583 | yytokenName (*yytokenp), yyk)); |
2a8d363a AD |
1584 | yyglrShift (yystack, yyk, yyaction, yyposn+1, |
1585 | *yylvalp, yyllocp]b4_user_args[); | |
fb8135fa | 1586 | YYDPRINTF ((stderr, "which is now in state #%d\n", |
01241d47 PH |
1587 | yystack->yytops.yystates[yyk]->yylrState)); |
1588 | break; | |
1589 | } | |
fb8135fa | 1590 | else if (yyisErrorAction (yyaction)) |
01241d47 PH |
1591 | { |
1592 | YYDPRINTF ((stderr, "Stack %d dies.\n", yyk)); | |
1593 | yymarkStackDeleted (yystack, yyk); | |
1594 | break; | |
1595 | } | |
1596 | else | |
2a8d363a | 1597 | YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_lpure_args[)); |
01241d47 PH |
1598 | } |
1599 | } | |
1600 | return yyok; | |
1601 | } | |
1602 | ||
1603 | static void | |
ee16363f PE |
1604 | yyreportSyntaxError (yyGLRStack* yystack, |
1605 | YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) | |
01241d47 | 1606 | { |
1154cced AD |
1607 | /* `Unused' warnings. */ |
1608 | (void) yylvalp; | |
1609 | (void) yyllocp; | |
01241d47 PH |
1610 | |
1611 | if (yystack->yyerrState == 0) | |
1612 | { | |
fb8135fa | 1613 | #if YYERROR_VERBOSE |
1154cced | 1614 | yySymbol* const yytokenp = yystack->yytokenp; |
93a0df69 | 1615 | int yyn; |
01241d47 | 1616 | yyn = yypact[yystack->yytops.yystates[0]->yylrState]; |
12b0043a | 1617 | if (YYPACT_NINF < yyn && yyn < YYLAST) |
01241d47 | 1618 | { |
93a0df69 | 1619 | size_t yysize = 0; |
c4749565 | 1620 | const char* yyprefix; |
93a0df69 PE |
1621 | char* yymsg; |
1622 | int yyx; | |
1623 | ||
01241d47 PH |
1624 | /* Start YYX at -YYN if negative to avoid negative indexes in |
1625 | YYCHECK. */ | |
c4749565 | 1626 | int yyxbegin = yyn < 0 ? -yyn : 0; |
93a0df69 PE |
1627 | |
1628 | /* Stay within bounds of both yycheck and yytname. */ | |
1629 | int yychecklim = YYLAST - yyn; | |
c4749565 | 1630 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; |
93a0df69 PE |
1631 | int yycount = 0; |
1632 | ||
01241d47 | 1633 | yyprefix = ", expecting "; |
c4749565 | 1634 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
217598da | 1635 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
93a0df69 | 1636 | { |
c4749565 | 1637 | yysize += strlen (yyprefix) + strlen (yytokenName (yyx)); |
93a0df69 PE |
1638 | yycount += 1; |
1639 | if (yycount == 5) | |
01241d47 | 1640 | { |
93a0df69 PE |
1641 | yysize = 0; |
1642 | break; | |
01241d47 | 1643 | } |
93a0df69 PE |
1644 | yyprefix = " or "; |
1645 | } | |
1646 | yysize += (sizeof ("syntax error, unexpected ") | |
1647 | + strlen (yytokenName (*yytokenp))); | |
1648 | yymsg = (char*) malloc (yysize); | |
1649 | if (yymsg != 0) | |
1650 | { | |
1651 | char* yyp = yymsg; | |
1652 | sprintf (yyp, "syntax error, unexpected %s", | |
1653 | yytokenName (*yytokenp)); | |
1654 | yyp += strlen (yyp); | |
1655 | if (yycount < 5) | |
1656 | { | |
1657 | yyprefix = ", expecting "; | |
c4749565 | 1658 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
93a0df69 PE |
1659 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
1660 | { | |
1661 | sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx)); | |
1662 | yyp += strlen (yyp); | |
1663 | yyprefix = " or "; | |
1664 | } | |
1665 | } | |
1666 | yyerror (]b4_lyyerror_args[yymsg); | |
1667 | free (yymsg); | |
01241d47 | 1668 | } |
93a0df69 PE |
1669 | else |
1670 | yyerror (]b4_lyyerror_args["syntax error; also virtual memory exhausted"); | |
01241d47 PH |
1671 | } |
1672 | else | |
93a0df69 | 1673 | #endif /* YYERROR_VERBOSE */ |
6e649e65 | 1674 | yyerror (]b4_lyyerror_args["syntax error"); |
01241d47 PH |
1675 | yynerrs += 1; |
1676 | } | |
1677 | } | |
1678 | ||
f50adbbd | 1679 | /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP, |
01241d47 | 1680 | YYLVALP, and YYLLOCP point to the syntactic category, semantic |
f50adbbd | 1681 | value, and location of the lookahead. */ |
fb8135fa | 1682 | static void |
ee16363f PE |
1683 | yyrecoverSyntaxError (yyGLRStack* yystack, |
1684 | YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) | |
01241d47 PH |
1685 | { |
1686 | yySymbol* const yytokenp = yystack->yytokenp; | |
1154cced AD |
1687 | size_t yyk; |
1688 | int yyj; | |
01241d47 | 1689 | |
fb8135fa | 1690 | if (yystack->yyerrState == 0) |
01241d47 | 1691 | yystack->yyerrState = 3; |
fb8135fa | 1692 | else if (yystack->yyerrState == 3) |
2a1fe6ed AD |
1693 | /* We just shifted the error token and (perhaps) took some |
1694 | reductions. Skip tokens until we can proceed. */ | |
1695 | while (yytrue) | |
1696 | { | |
01241d47 | 1697 | if (*yytokenp == YYEOF) |
7bd6c77e AD |
1698 | { |
1699 | /* Now pop stack until we find a state that shifts the | |
1700 | error token. */ | |
1701 | while (yystack->yytops.yystates[0] != NULL) | |
1702 | { | |
1703 | yyGLRState *yys = yystack->yytops.yystates[0]; | |
9c1e26bd | 1704 | YYDSYMPRINTF ("Error: popping", |
7bd6c77e | 1705 | yystos[yys->yylrState], |
9c1e26bd | 1706 | &yys->yysemantics.yysval, &yys->yyloc); |
7bd6c77e AD |
1707 | yydestruct (yystos[yys->yylrState], |
1708 | &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); | |
1709 | yystack->yytops.yystates[0] = yys->yypred; | |
1710 | yystack->yynextFree -= 1; | |
1711 | yystack->yyspaceLeft += 1; | |
1712 | } | |
1713 | yyFail (yystack][]b4_lpure_args[, NULL); | |
1714 | } | |
01241d47 | 1715 | if (*yytokenp != YYEMPTY) |
7bd6c77e | 1716 | { |
9c1e26bd | 1717 | YYDSYMPRINTF ("Error: discarding", *yytokenp, yylvalp, yyllocp); |
7bd6c77e AD |
1718 | yydestruct (*yytokenp, yylvalp]b4_location_if([, yyllocp])[); |
1719 | } | |
2a1fe6ed | 1720 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 PH |
1721 | yychar = YYLEX; |
1722 | *yytokenp = YYTRANSLATE (yychar); | |
9c1e26bd | 1723 | YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp); |
01241d47 | 1724 | yyj = yypact[yystack->yytops.yystates[0]->yylrState]; |
944ed9f4 | 1725 | if (yyis_pact_ninf (yyj)) |
2a1fe6ed | 1726 | /* Something's not right; we shouldn't be here. */ |
2a8d363a | 1727 | yyFail (yystack][]b4_lpure_args[, NULL); |
01241d47 | 1728 | yyj += *yytokenp; |
ea99527d | 1729 | if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp) |
01241d47 PH |
1730 | { |
1731 | if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0) | |
1732 | return; | |
1733 | } | |
944ed9f4 | 1734 | else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj])) |
01241d47 | 1735 | return; |
2a1fe6ed | 1736 | } |
fb8135fa | 1737 | |
2a1fe6ed | 1738 | /* Reduce to one stack. */ |
01241d47 PH |
1739 | for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1) |
1740 | if (yystack->yytops.yystates[yyk] != NULL) | |
1741 | break; | |
1742 | if (yyk >= yystack->yytops.yysize) | |
2a8d363a | 1743 | yyFail (yystack][]b4_lpure_args[, NULL); |
01241d47 PH |
1744 | for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1) |
1745 | yymarkStackDeleted (yystack, yyk); | |
1746 | yyremoveDeletes (yystack); | |
1747 | yycompressStack (yystack); | |
1748 | ||
1749 | /* Now pop stack until we find a state that shifts the error token. */ | |
fb8135fa | 1750 | while (yystack->yytops.yystates[0] != NULL) |
01241d47 | 1751 | { |
7bd6c77e AD |
1752 | yyGLRState *yys = yystack->yytops.yystates[0]; |
1753 | yyj = yypact[yys->yylrState]; | |
944ed9f4 | 1754 | if (! yyis_pact_ninf (yyj)) |
01241d47 | 1755 | { |
944ed9f4 PE |
1756 | yyj += YYTERROR; |
1757 | if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR | |
1758 | && yyisShiftAction (yytable[yyj])) | |
1759 | { | |
7bd6c77e | 1760 | YYDPRINTF ((stderr, "Shifting error token, ")); |
944ed9f4 | 1761 | yyglrShift (yystack, 0, yytable[yyj], |
7bd6c77e | 1762 | yys->yyposn, *yylvalp, yyllocp]b4_user_args[); |
944ed9f4 PE |
1763 | break; |
1764 | } | |
01241d47 | 1765 | } |
9c1e26bd | 1766 | YYDSYMPRINTF ("Error: popping", |
7bd6c77e | 1767 | yystos[yys->yylrState], |
9c1e26bd | 1768 | &yys->yysemantics.yysval, &yys->yyloc); |
7bd6c77e AD |
1769 | yydestruct (yystos[yys->yylrState], |
1770 | &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); | |
1771 | yystack->yytops.yystates[0] = yys->yypred; | |
01241d47 PH |
1772 | yystack->yynextFree -= 1; |
1773 | yystack->yyspaceLeft += 1; | |
1774 | } | |
1775 | if (yystack->yytops.yystates[0] == NULL) | |
2a8d363a | 1776 | yyFail (yystack][]b4_lpure_args[, NULL); |
fb8135fa AD |
1777 | } |
1778 | ||
01241d47 PH |
1779 | #define YYCHK1(YYE) \ |
1780 | do { \ | |
1781 | switch (YYE) { \ | |
1782 | default: \ | |
1783 | break; \ | |
1784 | case yyabort: \ | |
1785 | yystack.yyerrflag = 1; \ | |
1786 | goto yyDone; \ | |
1787 | case yyaccept: \ | |
1788 | yystack.yyerrflag = 0; \ | |
1789 | goto yyDone; \ | |
1790 | case yyerr: \ | |
1791 | goto yyuser_error; \ | |
1792 | } \ | |
fb8135fa | 1793 | } while (0) |
01241d47 | 1794 | |
0245f82d AD |
1795 | |
1796 | /*----------. | |
1797 | | yyparse. | | |
1798 | `----------*/ | |
1799 | ||
1800 | ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[ | |
01241d47 PH |
1801 | { |
1802 | yySymbol yytoken; | |
1803 | yyGLRStack yystack; | |
1804 | size_t yyposn; | |
1805 | ]b4_pure_if( | |
1806 | [ | |
1807 | YYSTYPE yylval; | |
1808 | YYLTYPE yylloc; | |
1809 | #undef yychar | |
1810 | #define yychar (yystack.yyrawchar) | |
1811 | ])[ | |
1812 | ||
1813 | YYSTYPE* const yylvalp = &yylval; | |
1814 | YYLTYPE* const yyllocp = &yylloc; | |
fb8135fa | 1815 | |
01241d47 PH |
1816 | yyinitGLRStack (&yystack, YYINITDEPTH); |
1817 | yystack.yytokenp = &yytoken; | |
1818 | ||
2a1fe6ed AD |
1819 | YYDPRINTF ((stderr, "Starting parse\n")); |
1820 | ||
01241d47 PH |
1821 | if (setjmp (yystack.yyexception_buffer) != 0) |
1822 | goto yyDone; | |
1823 | ||
2a8d363a | 1824 | yyglrShift (&yystack, 0, 0, 0, yyval_default, &yyloc_default]b4_user_args[); |
01241d47 PH |
1825 | yytoken = YYEMPTY; |
1826 | yyposn = 0; | |
1827 | ||
fb8135fa | 1828 | while (yytrue) |
01241d47 | 1829 | { |
21964f43 AD |
1830 | /* For efficiency, we have two loops, the first of which is |
1831 | specialized to deterministic operation (single stack, no | |
1832 | potential ambiguity). */ | |
01241d47 | 1833 | /* Standard mode */ |
fb8135fa | 1834 | while (yytrue) |
01241d47 PH |
1835 | { |
1836 | yyRuleNum yyrule; | |
1837 | int yyaction; | |
1838 | const short* yyconflicts; | |
1839 | ||
1840 | yyStateNum yystate = yystack.yytops.yystates[0]->yylrState; | |
b0937b22 | 1841 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
01241d47 PH |
1842 | if (yystate == YYFINAL) |
1843 | goto yyDone; | |
fb8135fa | 1844 | if (yyisDefaultedState (yystate)) |
01241d47 PH |
1845 | { |
1846 | yyrule = yydefaultAction (yystate); | |
fb8135fa | 1847 | if (yyrule == 0) |
01241d47 | 1848 | { |
ee16363f | 1849 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1850 | goto yyuser_error; |
1851 | } | |
2a8d363a | 1852 | YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_lpure_args[)); |
01241d47 | 1853 | } |
fb8135fa | 1854 | else |
01241d47 | 1855 | { |
fb8135fa | 1856 | if (yytoken == YYEMPTY) |
01241d47 | 1857 | { |
2a1fe6ed | 1858 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 PH |
1859 | yychar = YYLEX; |
1860 | yytoken = YYTRANSLATE (yychar); | |
9c1e26bd | 1861 | YYDSYMPRINTF ("Next token is", yytoken, yylvalp, yyllocp); |
01241d47 PH |
1862 | } |
1863 | yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); | |
1864 | if (*yyconflicts != 0) | |
1865 | break; | |
fb8135fa | 1866 | if (yyisShiftAction (yyaction)) |
01241d47 | 1867 | { |
2a1fe6ed | 1868 | YYDPRINTF ((stderr, "Shifting token %s, ", |
01241d47 PH |
1869 | yytokenName (yytoken))); |
1870 | if (yytoken != YYEOF) | |
1871 | yytoken = YYEMPTY; | |
1872 | yyposn += 1; | |
2a8d363a AD |
1873 | yyglrShift (&yystack, 0, yyaction, yyposn, |
1874 | yylval, yyllocp]b4_user_args[); | |
39912f52 | 1875 | if (0 < yystack.yyerrState) |
01241d47 | 1876 | yystack.yyerrState -= 1; |
01241d47 PH |
1877 | } |
1878 | else if (yyisErrorAction (yyaction)) | |
1879 | { | |
ee16363f | 1880 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1881 | goto yyuser_error; |
1882 | } | |
1883 | else | |
2a8d363a | 1884 | YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_lpure_args[)); |
01241d47 PH |
1885 | } |
1886 | } | |
1887 | ||
fb8135fa | 1888 | while (yytrue) |
01241d47 PH |
1889 | { |
1890 | int yys; | |
1891 | int yyn = yystack.yytops.yysize; | |
1892 | for (yys = 0; yys < yyn; yys += 1) | |
1893 | YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, | |
2a8d363a | 1894 | yylvalp, yyllocp]b4_user_args[)); |
01241d47 PH |
1895 | yytoken = YYEMPTY; |
1896 | yyposn += 1; | |
1897 | yyremoveDeletes (&yystack); | |
1898 | if (yystack.yytops.yysize == 0) | |
1899 | { | |
1900 | yyundeleteLastStack (&yystack); | |
1901 | if (yystack.yytops.yysize == 0) | |
6e649e65 | 1902 | yyFail (&yystack][]b4_lpure_args[, "syntax error"); |
2a8d363a | 1903 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); |
01241d47 | 1904 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); |
ee16363f | 1905 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1906 | goto yyuser_error; |
1907 | } | |
fb8135fa | 1908 | else if (yystack.yytops.yysize == 1) |
01241d47 | 1909 | { |
2a8d363a | 1910 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); |
01241d47 PH |
1911 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); |
1912 | yycompressStack (&yystack); | |
1913 | break; | |
1914 | } | |
1915 | } | |
1916 | continue; | |
1917 | yyuser_error: | |
ee16363f | 1918 | yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
1919 | yyposn = yystack.yytops.yystates[0]->yyposn; |
1920 | } | |
1921 | yyDone: | |
1922 | ; | |
1923 | ||
1924 | yyfreeGLRStack (&yystack); | |
1925 | return yystack.yyerrflag; | |
1926 | } | |
1927 | ||
1928 | /* DEBUGGING ONLY */ | |
1154cced AD |
1929 | static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED; |
1930 | static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED; | |
01241d47 | 1931 | |
1154cced | 1932 | static void |
cf126971 | 1933 | yy_yypstack (yyGLRState* yys) |
01241d47 | 1934 | { |
cf126971 | 1935 | if (yys->yypred) |
01241d47 | 1936 | { |
cf126971 PE |
1937 | yy_yypstack (yys->yypred); |
1938 | fprintf (stderr, " -> "); | |
01241d47 | 1939 | } |
947427ae | 1940 | fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long) yys->yyposn); |
cf126971 | 1941 | } |
01241d47 | 1942 | |
cf126971 PE |
1943 | static void |
1944 | yypstates (yyGLRState* yyst) | |
1945 | { | |
fb8135fa | 1946 | if (yyst == NULL) |
01241d47 | 1947 | fprintf (stderr, "<null>"); |
fb8135fa | 1948 | else |
01241d47 PH |
1949 | yy_yypstack (yyst); |
1950 | fprintf (stderr, "\n"); | |
1951 | } | |
1952 | ||
1154cced | 1953 | static void |
fb8135fa | 1954 | yypstack (yyGLRStack* yystack, int yyk) |
01241d47 PH |
1955 | { |
1956 | yypstates (yystack->yytops.yystates[yyk]); | |
1957 | } | |
1958 | ||
1959 | #define YYINDEX(YYX) \ | |
1960 | ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems) | |
1961 | ||
1962 | ||
1154cced | 1963 | static void |
fb8135fa | 1964 | yypdumpstack (yyGLRStack* yystack) |
01241d47 PH |
1965 | { |
1966 | yyGLRStackItem* yyp; | |
1154cced | 1967 | size_t yyi; |
fb8135fa | 1968 | for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1) |
01241d47 | 1969 | { |
cf126971 | 1970 | fprintf (stderr, "%3lu. ", (unsigned long) (yyp - yystack->yyitems)); |
f7c398aa | 1971 | if (*(yybool *) yyp) |
01241d47 | 1972 | { |
cf126971 | 1973 | fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", |
fb8135fa | 1974 | yyp->yystate.yyresolved, yyp->yystate.yylrState, |
cf126971 PE |
1975 | (unsigned long) yyp->yystate.yyposn, |
1976 | (long) YYINDEX (yyp->yystate.yypred)); | |
fb8135fa | 1977 | if (! yyp->yystate.yyresolved) |
cf126971 PE |
1978 | fprintf (stderr, ", firstVal: %ld", |
1979 | (long) YYINDEX (yyp->yystate.yysemantics.yyfirstVal)); | |
01241d47 | 1980 | } |
fb8135fa | 1981 | else |
01241d47 | 1982 | { |
cf126971 PE |
1983 | fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld", |
1984 | yyp->yyoption.yyrule, | |
1985 | (long) YYINDEX (yyp->yyoption.yystate), | |
1986 | (long) YYINDEX (yyp->yyoption.yynext)); | |
01241d47 PH |
1987 | } |
1988 | fprintf (stderr, "\n"); | |
1989 | } | |
1990 | fprintf (stderr, "Tops:"); | |
1991 | for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1) | |
cf126971 PE |
1992 | fprintf (stderr, "%lu: %ld; ", (unsigned long) yyi, |
1993 | (long) YYINDEX (yystack->yytops.yystates[yyi])); | |
01241d47 PH |
1994 | fprintf (stderr, "\n"); |
1995 | } | |
01241d47 PH |
1996 | ] |
1997 | ||
1998 | b4_epilogue | |
1999 | m4_if(b4_defines_flag, 0, [], | |
947427ae | 2000 | [@output @output_header_name@ |
c1a0d7e0 | 2001 | b4_copyright([Skeleton parser for GLR parsing with Bison], [2002, 2003]) |
01241d47 PH |
2002 | |
2003 | b4_token_defines(b4_tokens) | |
2004 | ||
fa8c3ebc | 2005 | #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) |
01241d47 | 2006 | m4_ifdef([b4_stype], |
437c2d80 | 2007 | [b4_syncline([b4_stype_line], [b4_filename]) |
fa8c3ebc | 2008 | typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE; |
996b1c7e | 2009 | /* Line __line__ of glr.c. */ |
947427ae | 2010 | b4_syncline([@oline@], [@ofile@])], |
fa8c3ebc PE |
2011 | [typedef int YYSTYPE;]) |
2012 | # define YYSTYPE_IS_DECLARED 1 | |
947427ae | 2013 | # define YYSTYPE_IS_TRIVIAL 1 |
01241d47 PH |
2014 | #endif |
2015 | ||
2016 | b4_pure_if([], | |
2017 | [extern YYSTYPE b4_prefix[]lval;]) | |
2018 | ||
2019 | b4_location_if( | |
fa8c3ebc PE |
2020 | [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) |
2021 | typedef struct YYLTYPE | |
01241d47 | 2022 | { |
f50adbbd AD |
2023 | int first_line; |
2024 | int first_column; | |
2025 | int last_line; | |
2026 | int last_column; | |
fa8c3ebc PE |
2027 | } YYLTYPE; |
2028 | # define YYLTYPE_IS_DECLARED 1 | |
2029 | # define YYLTYPE_IS_TRIVIAL 1 | |
01241d47 PH |
2030 | #endif |
2031 | ||
2032 | m4_if(b4_pure, [0], | |
2033 | [extern YYLTYPE b4_prefix[]lloc;]) | |
2034 | ]) | |
01241d47 | 2035 | ]) |