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