]>
Commit | Line | Data |
---|---|---|
720623af | 1 | m4_divert(-1) -*- C -*- |
01241d47 | 2 | |
fb8135fa | 3 | # GLR skeleton for Bison |
010f91c3 | 4 | # Copyright (C) 2002, 2003, 2004, 2005 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 | |
0fb669f9 PE |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | # 02110-1301 USA | |
fb8135fa | 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 | ||
4b367315 AD |
37 | # b4_user_formals |
38 | # --------------- | |
1989d947 AD |
39 | # The possible parse-params formal arguments preceded by a comma. |
40 | # | |
41 | # This is not shared with yacc.c in c.m4 because GLR relies on ISO C | |
42 | # formal argument declarations. | |
4b367315 AD |
43 | m4_define([b4_user_formals], |
44 | [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) | |
45 | ||
46 | ||
2a8d363a AD |
47 | # b4_lex_param |
48 | # ------------ | |
21964f43 AD |
49 | # Accumule in b4_lex_param all the yylex arguments. |
50 | # Yes, this is quite ugly... | |
51 | m4_define([b4_lex_param], | |
52 | m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnl | |
53 | b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl | |
54 | m4_ifdef([b4_lex_param], [, ]b4_lex_param))) | |
55 | ||
2a8d363a | 56 | |
93724f13 AD |
57 | # b4_yyerror_args |
58 | # --------------- | |
1989d947 AD |
59 | # Optional effective arguments passed to yyerror: user args plus yylloc, and |
60 | # a trailing comma. | |
93724f13 AD |
61 | m4_define([b4_yyerror_args], |
62 | [b4_pure_if([b4_location_if([yylocp, ])])dnl | |
63 | m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) | |
64 | ||
65 | ||
66 | # b4_lyyerror_args | |
67 | # ---------------- | |
8dd162d3 | 68 | # Same as above, but on the look-ahead, hence yyllocp instead of yylocp. |
93724f13 AD |
69 | m4_define([b4_lyyerror_args], |
70 | [b4_pure_if([b4_location_if([yyllocp, ])])dnl | |
71 | m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) | |
72 | ||
73 | ||
2a8d363a AD |
74 | # b4_pure_args |
75 | # ------------ | |
1989d947 | 76 | # Same as b4_yyerror_args, but with a leading comma. |
2a8d363a AD |
77 | m4_define([b4_pure_args], |
78 | [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args]) | |
79 | ||
80 | ||
2a8d363a AD |
81 | # b4_lpure_args |
82 | # ------------- | |
8dd162d3 | 83 | # Same as above, but on the look-ahead, hence yyllocp instead of yylocp. |
2a8d363a AD |
84 | m4_define([b4_lpure_args], |
85 | [b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args]) | |
0245f82d | 86 | |
66d30cd4 | 87 | |
1989d947 AD |
88 | # b4_pure_formals |
89 | # --------------- | |
90 | # Arguments passed to yyerror: user formals plus yyllocp. | |
91 | m4_define([b4_pure_formals], | |
92 | [b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals]) | |
93 | ||
94 | ||
2a8d363a AD |
95 | # b4_lpure_formals |
96 | # ---------------- | |
8dd162d3 | 97 | # Same as above, but on the look-ahead, hence yyllocp instead of yylocp. |
2a8d363a AD |
98 | m4_define([b4_lpure_formals], |
99 | [b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals]) | |
100 | ||
66d30cd4 AD |
101 | |
102 | ## ----------------- ## | |
103 | ## Semantic Values. ## | |
104 | ## ----------------- ## | |
105 | ||
106 | ||
01241d47 PH |
107 | # b4_lhs_value([TYPE]) |
108 | # -------------------- | |
109 | # Expansion of $<TYPE>$. | |
110 | m4_define([b4_lhs_value], | |
bc82c5a5 | 111 | [((*yyvalp)[]m4_ifval([$1], [.$1]))]) |
01241d47 PH |
112 | |
113 | ||
114 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
115 | # -------------------------------------- | |
116 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
117 | # symbols on RHS. | |
118 | m4_define([b4_rhs_value], | |
6de5398d | 119 | [(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))]) |
01241d47 PH |
120 | |
121 | ||
122 | ||
123 | ## ----------- ## | |
124 | ## Locations. ## | |
125 | ## ----------- ## | |
126 | ||
01241d47 PH |
127 | # b4_lhs_location() |
128 | # ----------------- | |
129 | # Expansion of @$. | |
130 | m4_define([b4_lhs_location], | |
131 | [(*yylocp)]) | |
132 | ||
133 | ||
134 | # b4_rhs_location(RULE-LENGTH, NUM) | |
135 | # --------------------------------- | |
136 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
137 | # on RHS. | |
138 | m4_define([b4_rhs_location], | |
6de5398d | 139 | [(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yyloc)]) |
01241d47 | 140 | |
5059b5c8 AD |
141 | |
142 | ||
143 | ## -------------- ## | |
144 | ## Output files. ## | |
145 | ## -------------- ## | |
146 | ||
b526ee61 AD |
147 | # We do want M4 expansion after # for CPP macros. |
148 | m4_changecom() | |
01241d47 | 149 | m4_divert(0)dnl |
947427ae | 150 | @output @output_parser_name@ |
010f91c3 PE |
151 | b4_copyright([Skeleton parser for GLR parsing with Bison], |
152 | [2002, 2003, 2004, 2005]) | |
fb8135fa | 153 | [ |
01241d47 PH |
154 | /* This is the parser code for GLR (Generalized LR) parser. */ |
155 | ||
2a8d363a | 156 | ]b4_identification |
5059b5c8 | 157 | |
2a8d363a | 158 | m4_if(b4_prefix[], [yy], [], |
c5b95ccf | 159 | [/* Substitute the variable and function names. */ |
01241d47 PH |
160 | #define yyparse b4_prefix[]parse |
161 | #define yylex b4_prefix[]lex | |
162 | #define yyerror b4_prefix[]error | |
163 | #define yylval b4_prefix[]lval | |
164 | #define yychar b4_prefix[]char | |
165 | #define yydebug b4_prefix[]debug | |
166 | #define yynerrs b4_prefix[]nerrs | |
5059b5c8 | 167 | #define yylloc b4_prefix[]lloc]) |
01241d47 | 168 | |
5059b5c8 AD |
169 | dnl # b4_shared_declarations |
170 | dnl # ---------------------- | |
171 | dnl # Declaration that might either go into the header (if --defines) | |
172 | dnl # or open coded in the parser body. | |
173 | m4_define([b4_shared_declarations], | |
174 | [b4_token_enums(b4_tokens)[ | |
01241d47 | 175 | |
17acead5 | 176 | /* Copy the first part of user declarations. */ |
5059b5c8 | 177 | ]b4_pre_prologue[ |
141f5793 | 178 | |
fa8c3ebc | 179 | #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) |
01241d47 | 180 | ]m4_ifdef([b4_stype], |
48b16bbc | 181 | [b4_syncline([b4_stype_line], [b4_file_name]) |
fa8c3ebc | 182 | typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE; |
996b1c7e | 183 | /* Line __line__ of glr.c. */ |
947427ae | 184 | b4_syncline([@oline@], [@ofile@])], |
fa8c3ebc PE |
185 | [typedef int YYSTYPE;])[ |
186 | # define YYSTYPE_IS_DECLARED 1 | |
01241d47 PH |
187 | # define YYSTYPE_IS_TRIVIAL 1 |
188 | #endif | |
189 | ||
fa8c3ebc PE |
190 | #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) |
191 | typedef struct YYLTYPE | |
01241d47 | 192 | { |
25005f6a | 193 | ]b4_location_if([ |
f50adbbd AD |
194 | int first_line; |
195 | int first_column; | |
196 | int last_line; | |
ffa4c58a | 197 | int last_column; |
5cc16ecc PE |
198 | ],[ |
199 | char yydummy; | |
25005f6a | 200 | ])[ |
fa8c3ebc PE |
201 | } YYLTYPE; |
202 | # define YYLTYPE_IS_DECLARED 1 | |
01241d47 PH |
203 | # define YYLTYPE_IS_TRIVIAL 1 |
204 | #endif | |
5059b5c8 AD |
205 | ]]) |
206 | ||
207 | m4_if(b4_defines_flag, 0, | |
208 | [b4_shared_declarations], | |
209 | [#include @output_header_name@])[ | |
210 | ||
211 | /* Enabling traces. */ | |
212 | #ifndef YYDEBUG | |
213 | # define YYDEBUG ]b4_debug[ | |
214 | #endif | |
215 | ||
216 | /* Enabling verbose error messages. */ | |
217 | #ifdef YYERROR_VERBOSE | |
218 | # undef YYERROR_VERBOSE | |
219 | # define YYERROR_VERBOSE 1 | |
220 | #else | |
221 | # define YYERROR_VERBOSE ]b4_error_verbose[ | |
222 | #endif | |
223 | ||
224 | /* Enabling the token table. */ | |
225 | #ifndef YYTOKEN_TABLE | |
226 | # define YYTOKEN_TABLE ]b4_token_table[ | |
227 | #endif | |
01241d47 | 228 | |
288006a2 | 229 | /* Default (constant) value used for initialization for null |
f6abc26e | 230 | right-hand sides. Unlike the standard yacc.c template, |
288006a2 | 231 | here we set the default value of $$ to a zeroed-out value. |
b9b51bf0 PE |
232 | Since the default value is undefined, this behavior is |
233 | technically correct. */ | |
01241d47 | 234 | static YYSTYPE yyval_default; |
01241d47 PH |
235 | |
236 | /* Copy the second part of user declarations. */ | |
237 | ]b4_post_prologue[ | |
238 | ||
996b1c7e | 239 | ]/* Line __line__ of glr.c. */ |
947427ae | 240 | b4_syncline([@oline@], [@ofile@]) |
01241d47 | 241 | [ |
63cb01d6 PE |
242 | #include <stdio.h> |
243 | #include <stdlib.h> | |
244 | #include <string.h> | |
245 | #include <stdarg.h> | |
63cb01d6 | 246 | |
30757c8c PE |
247 | #ifndef YY_ |
248 | # if YYENABLE_NLS | |
249 | # if ENABLE_NLS | |
250 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ | |
251 | # define YY_(msgid) dgettext ("bison-runtime", msgid) | |
252 | # endif | |
253 | # endif | |
254 | # ifndef YY_ | |
255 | # define YY_(msgid) msgid | |
256 | # endif | |
257 | #endif | |
258 | ||
2a4647a3 | 259 | /* Suppress unused-variable warnings by "using" E. */ |
12ce2df6 PE |
260 | #ifndef lint |
261 | # define YYUSE(e) ((void) (e)) | |
613d8952 | 262 | #else |
12ce2df6 PE |
263 | # define YYUSE(e) /* empty */ |
264 | #endif | |
265 | ||
266 | /* Identity function, used to suppress warnings about constant conditions. */ | |
267 | #ifndef lint | |
268 | # define YYID(n) (n) | |
269 | #else | |
270 | ]b4_c_function_def([YYID], [static int], [[int i], [i]])[ | |
271 | { | |
272 | return i; | |
273 | } | |
613d8952 | 274 | #endif |
2a4647a3 | 275 | |
a525b568 PE |
276 | #ifndef YYFREE |
277 | # define YYFREE free | |
278 | #endif | |
279 | #ifndef YYMALLOC | |
280 | # define YYMALLOC malloc | |
281 | #endif | |
282 | #ifndef YYREALLOC | |
283 | # define YYREALLOC realloc | |
284 | #endif | |
285 | ||
63cb01d6 PE |
286 | #define YYSIZEMAX ((size_t) -1) |
287 | ||
f7c398aa PE |
288 | #ifdef __cplusplus |
289 | typedef bool yybool; | |
290 | #else | |
291 | typedef unsigned char yybool; | |
01241d47 | 292 | #endif |
f7c398aa PE |
293 | #define yytrue 1 |
294 | #define yyfalse 0 | |
01241d47 | 295 | |
c89b4c03 PE |
296 | #ifndef YYSETJMP |
297 | # include <setjmp.h> | |
298 | # define YYJMP_BUF jmp_buf | |
299 | # define YYSETJMP(env) setjmp (env) | |
300 | # define YYLONGJMP(env, val) longjmp (env, val) | |
301 | #endif | |
302 | ||
1154cced AD |
303 | /*-----------------. |
304 | | GCC extensions. | | |
305 | `-----------------*/ | |
306 | ||
307 | #ifndef __attribute__ | |
308 | /* This feature is available in gcc versions 2.5 and later. */ | |
3bc00d6c PE |
309 | # if (!defined (__GNUC__) || __GNUC__ < 2 \ |
310 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) | |
1154cced AD |
311 | # define __attribute__(Spec) /* empty */ |
312 | # endif | |
313 | #endif | |
314 | ||
3bc00d6c PE |
315 | ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[ |
316 | #ifdef __cplusplus | |
317 | # define YYOPTIONAL_LOC(Name) /* empty */ | |
318 | #else | |
319 | # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__)) | |
320 | #endif])[ | |
321 | ||
64c4fd52 PE |
322 | #ifndef YYASSERT |
323 | # define YYASSERT(condition) ((void) ((condition) || (abort (), 0))) | |
324 | #endif | |
325 | ||
01241d47 | 326 | /* YYFINAL -- State number of the termination state. */ |
7db2ed2d | 327 | #define YYFINAL ]b4_final_state_number[ |
39912f52 | 328 | /* YYLAST -- Last index in YYTABLE. */ |
01241d47 PH |
329 | #define YYLAST ]b4_last[ |
330 | ||
331 | /* YYNTOKENS -- Number of terminals. */ | |
7db2ed2d | 332 | #define YYNTOKENS ]b4_tokens_number[ |
01241d47 | 333 | /* YYNNTS -- Number of nonterminals. */ |
7db2ed2d | 334 | #define YYNNTS ]b4_nterms_number[ |
01241d47 | 335 | /* YYNRULES -- Number of rules. */ |
7db2ed2d | 336 | #define YYNRULES ]b4_rules_number[ |
01241d47 | 337 | /* YYNRULES -- Number of states. */ |
7db2ed2d | 338 | #define YYNSTATES ]b4_states_number[ |
01241d47 PH |
339 | /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ |
340 | #define YYMAXRHS ]b4_r2_max[ | |
25005f6a PH |
341 | /* YYMAXLEFT -- Maximum number of symbols to the left of a handle |
342 | accessed by $0, $-1, etc., in any rule. */ | |
343 | #define YYMAXLEFT ]b4_max_left_semantic_context[ | |
01241d47 PH |
344 | |
345 | /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */ | |
346 | #define YYUNDEFTOK ]b4_undef_token_number[ | |
347 | #define YYMAXUTOK ]b4_user_token_number_max[ | |
348 | ||
5cc16ecc | 349 | #define YYTRANSLATE(YYX) \ |
b0400cc6 | 350 | ((YYX <= 0) ? YYEOF : \ |
779e7ceb | 351 | (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) |
01241d47 PH |
352 | |
353 | /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ | |
a762e609 | 354 | static const ]b4_int_type_for([b4_translate])[ yytranslate[] = |
01241d47 PH |
355 | { |
356 | ]b4_translate[ | |
357 | }; | |
358 | ||
359 | #if YYDEBUG | |
360 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in | |
361 | YYRHS. */ | |
a762e609 | 362 | static const ]b4_int_type_for([b4_prhs])[ yyprhs[] = |
01241d47 PH |
363 | { |
364 | ]b4_prhs[ | |
365 | }; | |
366 | ||
367 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ | |
a762e609 | 368 | static const ]b4_int_type_for([b4_rhs])[ yyrhs[] = |
01241d47 PH |
369 | { |
370 | ]b4_rhs[ | |
371 | }; | |
372 | ||
373 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ | |
a762e609 | 374 | static const ]b4_int_type_for([b4_rline])[ yyrline[] = |
01241d47 PH |
375 | { |
376 | ]b4_rline[ | |
377 | }; | |
378 | #endif | |
379 | ||
141f5793 | 380 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE |
9e0876fb | 381 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
01241d47 PH |
382 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
383 | static const char *const yytname[] = | |
384 | { | |
385 | ]b4_tname[ | |
386 | }; | |
01241d47 PH |
387 | #endif |
388 | ||
389 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ | |
a762e609 | 390 | static const ]b4_int_type_for([b4_r1])[ yyr1[] = |
01241d47 PH |
391 | { |
392 | ]b4_r1[ | |
393 | }; | |
394 | ||
395 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ | |
a762e609 | 396 | static const ]b4_int_type_for([b4_r2])[ yyr2[] = |
01241d47 PH |
397 | { |
398 | ]b4_r2[ | |
399 | }; | |
400 | ||
401 | /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ | |
a762e609 | 402 | static const ]b4_int_type_for([b4_dprec])[ yydprec[] = |
01241d47 PH |
403 | { |
404 | ]b4_dprec[ | |
405 | }; | |
406 | ||
407 | /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ | |
a762e609 | 408 | static const ]b4_int_type_for([b4_merger])[ yymerger[] = |
01241d47 PH |
409 | { |
410 | ]b4_merger[ | |
411 | }; | |
412 | ||
413 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE | |
414 | doesn't specify something else to do. Zero means the default is an | |
415 | error. */ | |
a762e609 | 416 | static const ]b4_int_type_for([b4_defact])[ yydefact[] = |
01241d47 PH |
417 | { |
418 | ]b4_defact[ | |
419 | }; | |
420 | ||
12b0043a | 421 | /* YYPDEFGOTO[NTERM-NUM]. */ |
a762e609 | 422 | static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] = |
01241d47 PH |
423 | { |
424 | ]b4_defgoto[ | |
425 | }; | |
426 | ||
427 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing | |
428 | STATE-NUM. */ | |
12b0043a | 429 | #define YYPACT_NINF ]b4_pact_ninf[ |
a762e609 | 430 | static const ]b4_int_type_for([b4_pact])[ yypact[] = |
01241d47 PH |
431 | { |
432 | ]b4_pact[ | |
433 | }; | |
434 | ||
435 | /* YYPGOTO[NTERM-NUM]. */ | |
a762e609 | 436 | static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] = |
01241d47 PH |
437 | { |
438 | ]b4_pgoto[ | |
439 | }; | |
440 | ||
441 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If | |
442 | positive, shift that token. If negative, reduce the rule which | |
f50adbbd | 443 | number is the opposite. If zero, do what YYDEFACT says. |
6e649e65 | 444 | If YYTABLE_NINF, syntax error. */ |
12b0043a | 445 | #define YYTABLE_NINF ]b4_table_ninf[ |
a762e609 | 446 | static const ]b4_int_type_for([b4_table])[ yytable[] = |
01241d47 PH |
447 | { |
448 | ]b4_table[ | |
449 | }; | |
450 | ||
ea99527d AD |
451 | /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of |
452 | list of conflicting reductions corresponding to action entry for | |
453 | state STATE-NUM in yytable. 0 means no conflicts. The list in | |
454 | yyconfl is terminated by a rule number of 0. */ | |
a762e609 | 455 | static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = |
01241d47 PH |
456 | { |
457 | ]b4_conflict_list_heads[ | |
458 | }; | |
459 | ||
ea99527d AD |
460 | /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by |
461 | 0, pointed into by YYCONFLP. */ | |
a762e609 | 462 | ]dnl Do not use b4_int_type_for here, since there are places where |
779e7ceb | 463 | dnl pointers onto yyconfl are taken, which type is "short int *". |
a762e609 | 464 | dnl We probably ought to introduce a type for confl. |
779e7ceb | 465 | [static const short int yyconfl[] = |
01241d47 PH |
466 | { |
467 | ]b4_conflicting_rules[ | |
468 | }; | |
469 | ||
a762e609 | 470 | static const ]b4_int_type_for([b4_check])[ yycheck[] = |
01241d47 PH |
471 | { |
472 | ]b4_check[ | |
473 | }; | |
474 | ||
7bd6c77e AD |
475 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
476 | symbol of state STATE-NUM. */ | |
477 | static const ]b4_int_type_for([b4_stos])[ yystos[] = | |
478 | { | |
479 | ]b4_stos[ | |
480 | }; | |
481 | ||
01241d47 | 482 | \f |
0245f82d | 483 | /* Prevent warning if -Wmissing-prototypes. */ |
2a8d363a | 484 | ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[ |
e7cb57c0 | 485 | |
2a8d363a | 486 | /* Error token number */ |
01241d47 PH |
487 | #define YYTERROR 1 |
488 | ||
b4a20338 AD |
489 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. |
490 | If N is 0, then set CURRENT to the empty location which ends | |
491 | the previous symbol: RHS[0] (always defined). */ | |
01241d47 | 492 | |
25005f6a | 493 | ]b4_location_if([[ |
9fafc4dd | 494 | #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) |
01241d47 | 495 | #ifndef YYLLOC_DEFAULT |
9fafc4dd PE |
496 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
497 | do \ | |
498 | if (N) \ | |
499 | { \ | |
9bec482e PE |
500 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ |
501 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ | |
502 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ | |
503 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ | |
9fafc4dd PE |
504 | } \ |
505 | else \ | |
506 | { \ | |
507 | (Current).first_line = (Current).last_line = \ | |
9bec482e | 508 | YYRHSLOC (Rhs, 0).last_line; \ |
9fafc4dd | 509 | (Current).first_column = (Current).last_column = \ |
9bec482e | 510 | YYRHSLOC (Rhs, 0).last_column; \ |
9fafc4dd | 511 | } \ |
12ce2df6 | 512 | while (YYID (0)) |
3fc16193 AD |
513 | |
514 | /* YY_LOCATION_PRINT -- Print the location on the stream. | |
515 | This macro was not mandated originally: define only if we know | |
516 | we won't break user code: when these are the locations we know. */ | |
517 | ||
518 | # define YY_LOCATION_PRINT(File, Loc) \ | |
519 | fprintf (File, "%d.%d-%d.%d", \ | |
69ce078b PE |
520 | (Loc).first_line, (Loc).first_column, \ |
521 | (Loc).last_line, (Loc).last_column) | |
25005f6a PH |
522 | #endif |
523 | ]],[ | |
524 | #ifndef YYLLOC_DEFAULT | |
9fafc4dd | 525 | # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0) |
01241d47 | 526 | #endif |
25005f6a PH |
527 | ])[ |
528 | ||
3fc16193 AD |
529 | #ifndef YY_LOCATION_PRINT |
530 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) | |
531 | #endif | |
532 | ||
01241d47 PH |
533 | |
534 | /* YYLEX -- calling `yylex' with the right arguments. */ | |
21964f43 | 535 | #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[ |
01241d47 PH |
536 | |
537 | ]b4_pure_if( | |
538 | [ | |
01241d47 PH |
539 | #undef yynerrs |
540 | #define yynerrs (yystack->yyerrcnt) | |
541 | #undef yychar | |
542 | #define yychar (yystack->yyrawchar)], | |
543 | [YYSTYPE yylval; | |
544 | ||
545 | YYLTYPE yylloc; | |
546 | ||
547 | int yynerrs; | |
548 | int yychar;])[ | |
549 | ||
550 | static const int YYEOF = 0; | |
551 | static const int YYEMPTY = -2; | |
552 | ||
553 | typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; | |
554 | ||
555 | #define YYCHK(YYE) \ | |
5cc16ecc | 556 | do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ |
12ce2df6 | 557 | while (YYID (0)) |
01241d47 PH |
558 | |
559 | #if YYDEBUG | |
560 | ||
2f4f028d | 561 | #if ! defined (YYFPRINTF) |
01241d47 | 562 | # define YYFPRINTF fprintf |
2f4f028d | 563 | #endif |
01241d47 PH |
564 | |
565 | # define YYDPRINTF(Args) \ | |
566 | do { \ | |
567 | if (yydebug) \ | |
568 | YYFPRINTF Args; \ | |
12ce2df6 | 569 | } while (YYID (0)) |
7bd6c77e AD |
570 | |
571 | ]b4_yysymprint_generate([b4_c_ansi_function_def])[ | |
572 | ||
4b367315 AD |
573 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ |
574 | do { \ | |
575 | if (yydebug) \ | |
576 | { \ | |
577 | YYFPRINTF (stderr, "%s ", Title); \ | |
578 | yysymprint (stderr, \ | |
69ce078b | 579 | Type, Value]b4_location_if([, Location])[]b4_user_args[); \ |
4b367315 AD |
580 | YYFPRINTF (stderr, "\n"); \ |
581 | } \ | |
12ce2df6 | 582 | } while (YYID (0)) |
9c1e26bd | 583 | |
01241d47 PH |
584 | /* Nonzero means print parse trace. It is left uninitialized so that |
585 | multiple parsers can coexist. */ | |
586 | int yydebug; | |
7bd6c77e | 587 | |
01241d47 | 588 | #else /* !YYDEBUG */ |
7bd6c77e | 589 | |
ee16363f | 590 | # define YYDPRINTF(Args) |
284acc8b | 591 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) |
7bd6c77e | 592 | |
01241d47 PH |
593 | #endif /* !YYDEBUG */ |
594 | ||
595 | /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
596 | #ifndef YYINITDEPTH | |
66d30cd4 | 597 | # define YYINITDEPTH ]b4_stack_depth_init[ |
01241d47 PH |
598 | #endif |
599 | ||
600 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only | |
601 | if the built-in stack extension method is used). | |
602 | ||
603 | Do not make this value too large; the results are undefined if | |
fb8135fa | 604 | SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) |
01241d47 PH |
605 | evaluated with infinite-precision integer arithmetic. */ |
606 | ||
01241d47 | 607 | #ifndef YYMAXDEPTH |
66d30cd4 | 608 | # define YYMAXDEPTH ]b4_stack_depth_max[ |
01241d47 PH |
609 | #endif |
610 | ||
611 | /* Minimum number of free items on the stack allowed after an | |
fb8135fa | 612 | allocation. This is to allow allocation and initialization |
63cb01d6 | 613 | to be completed by functions that call yyexpandGLRStack before the |
fb8135fa | 614 | stack is expanded, thus insuring that all necessary pointers get |
01241d47 PH |
615 | properly redirected to new data. */ |
616 | #define YYHEADROOM 2 | |
617 | ||
e2688cd9 PE |
618 | #ifndef YYSTACKEXPANDABLE |
619 | # if (! defined (__cplusplus) \ | |
620 | || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ | |
621 | && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)) | |
622 | # define YYSTACKEXPANDABLE 1 | |
623 | # else | |
624 | # define YYSTACKEXPANDABLE 0 | |
625 | # endif | |
01241d47 PH |
626 | #endif |
627 | ||
02998094 AD |
628 | #if YYSTACKEXPANDABLE |
629 | # define YY_RESERVE_GLRSTACK(Yystack) \ | |
630 | do { \ | |
631 | if (Yystack->yyspaceLeft < YYHEADROOM) \ | |
632 | yyexpandGLRStack (Yystack); \ | |
12ce2df6 | 633 | } while (YYID (0)) |
02998094 AD |
634 | #else |
635 | # define YY_RESERVE_GLRSTACK(Yystack) \ | |
636 | do { \ | |
637 | if (Yystack->yyspaceLeft < YYHEADROOM) \ | |
638 | yyMemoryExhausted (Yystack); \ | |
12ce2df6 | 639 | } while (YYID (0)) |
02998094 AD |
640 | #endif |
641 | ||
642 | ||
63cb01d6 PE |
643 | #if YYERROR_VERBOSE |
644 | ||
645 | # ifndef yystpcpy | |
646 | # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) | |
647 | # define yystpcpy stpcpy | |
648 | # else | |
649 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in | |
650 | YYDEST. */ | |
651 | static char * | |
652 | yystpcpy (char *yydest, const char *yysrc) | |
653 | { | |
654 | char *yyd = yydest; | |
655 | const char *yys = yysrc; | |
656 | ||
657 | while ((*yyd++ = *yys++) != '\0') | |
658 | continue; | |
659 | ||
660 | return yyd - 1; | |
661 | } | |
662 | # endif | |
663 | # endif | |
664 | ||
9e0876fb PE |
665 | # ifndef yytnamerr |
666 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary | |
667 | quotes and backslashes, so that it's suitable for yyerror. The | |
668 | heuristic is that double-quoting is unnecessary unless the string | |
669 | contains an apostrophe, a comma, or backslash (other than | |
670 | backslash-backslash). YYSTR is taken from yytname. If YYRES is | |
671 | null, do not copy; instead, return the length of what the result | |
672 | would have been. */ | |
673 | static size_t | |
674 | yytnamerr (char *yyres, const char *yystr) | |
675 | { | |
676 | if (*yystr == '"') | |
677 | { | |
678 | size_t yyn = 0; | |
679 | char const *yyp = yystr; | |
680 | ||
681 | for (;;) | |
682 | switch (*++yyp) | |
683 | { | |
684 | case '\'': | |
685 | case ',': | |
686 | goto do_not_strip_quotes; | |
687 | ||
688 | case '\\': | |
689 | if (*++yyp != '\\') | |
690 | goto do_not_strip_quotes; | |
691 | /* Fall through. */ | |
692 | default: | |
693 | if (yyres) | |
694 | yyres[yyn] = *yyp; | |
695 | yyn++; | |
696 | break; | |
697 | ||
698 | case '"': | |
699 | if (yyres) | |
700 | yyres[yyn] = '\0'; | |
701 | return yyn; | |
702 | } | |
703 | do_not_strip_quotes: ; | |
704 | } | |
705 | ||
706 | if (! yyres) | |
707 | return strlen (yystr); | |
708 | ||
709 | return yystpcpy (yyres, yystr) - yyres; | |
710 | } | |
711 | # endif | |
712 | ||
63cb01d6 PE |
713 | #endif /* !YYERROR_VERBOSE */ |
714 | ||
01241d47 PH |
715 | /** State numbers, as in LALR(1) machine */ |
716 | typedef int yyStateNum; | |
717 | ||
718 | /** Rule numbers, as in LALR(1) machine */ | |
719 | typedef int yyRuleNum; | |
720 | ||
721 | /** Grammar symbol */ | |
779e7ceb | 722 | typedef short int yySymbol; |
01241d47 PH |
723 | |
724 | /** Item references, as in LALR(1) machine */ | |
779e7ceb | 725 | typedef short int yyItemNum; |
01241d47 PH |
726 | |
727 | typedef struct yyGLRState yyGLRState; | |
728 | typedef struct yySemanticOption yySemanticOption; | |
729 | typedef union yyGLRStackItem yyGLRStackItem; | |
730 | typedef struct yyGLRStack yyGLRStack; | |
731 | typedef struct yyGLRStateSet yyGLRStateSet; | |
732 | ||
733 | struct yyGLRState { | |
5e6f62f2 | 734 | /** Type tag: always true. */ |
f7c398aa | 735 | yybool yyisState; |
5e6f62f2 PH |
736 | /** Type tag for yysemantics. If true, yysval applies, otherwise |
737 | * yyfirstVal applies. */ | |
f7c398aa | 738 | yybool yyresolved; |
5e6f62f2 | 739 | /** Number of corresponding LALR(1) machine state. */ |
01241d47 | 740 | yyStateNum yylrState; |
5e6f62f2 | 741 | /** Preceding state in this stack */ |
01241d47 | 742 | yyGLRState* yypred; |
5e6f62f2 | 743 | /** Source position of the first token produced by my symbol */ |
01241d47 PH |
744 | size_t yyposn; |
745 | union { | |
5e6f62f2 | 746 | /** First in a chain of alternative reductions producing the |
010f91c3 | 747 | * non-terminal corresponding to this state, threaded through |
5e6f62f2 | 748 | * yynext. */ |
01241d47 | 749 | yySemanticOption* yyfirstVal; |
5e6f62f2 | 750 | /** Semantic value for this state. */ |
01241d47 PH |
751 | YYSTYPE yysval; |
752 | } yysemantics; | |
5e6f62f2 | 753 | /** Source location for this state. */ |
01241d47 PH |
754 | YYLTYPE yyloc; |
755 | }; | |
756 | ||
757 | struct yyGLRStateSet { | |
758 | yyGLRState** yystates; | |
759 | size_t yysize, yycapacity; | |
760 | }; | |
761 | ||
762 | struct yySemanticOption { | |
5e6f62f2 | 763 | /** Type tag: always false. */ |
f7c398aa | 764 | yybool yyisState; |
5e6f62f2 | 765 | /** Rule number for this reduction */ |
01241d47 | 766 | yyRuleNum yyrule; |
5e6f62f2 | 767 | /** The last RHS state in the list of states to be reduced. */ |
01241d47 | 768 | yyGLRState* yystate; |
5e6f62f2 PH |
769 | /** Next sibling in chain of options. To facilitate merging, |
770 | * options are chained in decreasing order by address. */ | |
01241d47 PH |
771 | yySemanticOption* yynext; |
772 | }; | |
773 | ||
010f91c3 | 774 | /** Type of the items in the GLR stack. The yyisState field |
5e6f62f2 | 775 | * indicates which item of the union is valid. */ |
01241d47 PH |
776 | union yyGLRStackItem { |
777 | yyGLRState yystate; | |
778 | yySemanticOption yyoption; | |
779 | }; | |
780 | ||
781 | struct yyGLRStack { | |
01241d47 | 782 | int yyerrState; |
63d72da7 PE |
783 | ]b4_location_if([[ /* To compute the location of the error token. */ |
784 | yyGLRStackItem yyerror_range[3];]])[ | |
01241d47 PH |
785 | ]b4_pure_if( |
786 | [ | |
787 | int yyerrcnt; | |
788 | int yyrawchar; | |
789 | ])[ | |
790 | yySymbol* yytokenp; | |
c89b4c03 | 791 | YYJMP_BUF yyexception_buffer; |
01241d47 PH |
792 | yyGLRStackItem* yyitems; |
793 | yyGLRStackItem* yynextFree; | |
63cb01d6 | 794 | size_t yyspaceLeft; |
01241d47 PH |
795 | yyGLRState* yysplitPoint; |
796 | yyGLRState* yylastDeleted; | |
797 | yyGLRStateSet yytops; | |
798 | }; | |
799 | ||
b2741627 | 800 | #if YYSTACKEXPANDABLE |
df9a1ba4 | 801 | static void yyexpandGLRStack (yyGLRStack* yystack); |
b2741627 | 802 | #endif |
01241d47 | 803 | |
135bc829 PE |
804 | static void yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg) |
805 | __attribute__ ((__noreturn__)); | |
01241d47 | 806 | static void |
fd2df2ed | 807 | yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg) |
01241d47 | 808 | { |
fd2df2ed PE |
809 | if (yymsg != NULL) |
810 | yyerror (]b4_yyerror_args[yymsg); | |
c89b4c03 | 811 | YYLONGJMP (yystack->yyexception_buffer, 1); |
01241d47 PH |
812 | } |
813 | ||
135bc829 PE |
814 | static void yyMemoryExhausted (yyGLRStack* yystack) |
815 | __attribute__ ((__noreturn__)); | |
63cb01d6 | 816 | static void |
1a059451 | 817 | yyMemoryExhausted (yyGLRStack* yystack) |
63cb01d6 | 818 | { |
c89b4c03 | 819 | YYLONGJMP (yystack->yyexception_buffer, 2); |
63cb01d6 PE |
820 | } |
821 | ||
01241d47 | 822 | #if YYDEBUG || YYERROR_VERBOSE |
63cb01d6 | 823 | /** A printable representation of TOKEN. */ |
fb8135fa AD |
824 | static inline const char* |
825 | yytokenName (yySymbol yytoken) | |
01241d47 | 826 | { |
d0d5aa64 PE |
827 | if (yytoken == YYEMPTY) |
828 | return ""; | |
829 | ||
01241d47 PH |
830 | return yytname[yytoken]; |
831 | } | |
832 | #endif | |
833 | ||
f868dc04 PH |
834 | /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting |
835 | * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred | |
44e7ead1 | 836 | * containing the pointer to the next state in the chain. */ |
135bc829 | 837 | static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__)); |
6a84279c PE |
838 | static void |
839 | yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) | |
f868dc04 PH |
840 | { |
841 | yyGLRState* s; | |
842 | int i; | |
c4749565 | 843 | s = yyvsp[yylow0].yystate.yypred; |
f868dc04 PH |
844 | for (i = yylow0-1; i >= yylow1; i -= 1) |
845 | { | |
64c4fd52 | 846 | YYASSERT (s->yyresolved); |
f868dc04 PH |
847 | yyvsp[i].yystate.yyresolved = yytrue; |
848 | yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval; | |
849 | yyvsp[i].yystate.yyloc = s->yyloc; | |
850 | s = yyvsp[i].yystate.yypred = s->yypred; | |
851 | } | |
6a84279c PE |
852 | } |
853 | ||
854 | /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in | |
44e7ead1 PH |
855 | * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. |
856 | * For convenience, always return YYLOW1. */ | |
6a84279c | 857 | static inline int yyfill (yyGLRStackItem *, int *, int, yybool) |
135bc829 | 858 | __attribute__ ((__unused__)); |
6a84279c PE |
859 | static inline int |
860 | yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) | |
861 | { | |
862 | if (!yynormal && yylow1 < *yylow) | |
863 | { | |
864 | yyfillin (yyvsp, *yylow, yylow1); | |
865 | *yylow = yylow1; | |
866 | } | |
f868dc04 PH |
867 | return yylow1; |
868 | } | |
869 | ||
01241d47 PH |
870 | /** Perform user action for rule number YYN, with RHS length YYRHSLEN, |
871 | * and top stack item YYVSP. YYLVALP points to place to put semantic | |
872 | * value ($$), and yylocp points to place for location information | |
947427ae | 873 | * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, |
01241d47 | 874 | * yyerr for YYERROR, yyabort for YYABORT. */ |
12ce2df6 | 875 | /*ARGSUSED*/ static YYRESULTTAG |
fb8135fa | 876 | yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, |
80a18357 | 877 | YYSTYPE* yyvalp, |
43d3b664 | 878 | YYLTYPE* YYOPTIONAL_LOC (yylocp), |
80a18357 | 879 | yyGLRStack* yystack |
69ce078b | 880 | ]b4_user_formals[) |
01241d47 | 881 | { |
135bc829 PE |
882 | yybool yynormal __attribute__ ((__unused__)) = |
883 | (yystack->yysplitPoint == NULL); | |
f868dc04 | 884 | int yylow; |
613d8952 AD |
885 | ]b4_parse_param_use[]dnl |
886 | [# undef yyerrok | |
01241d47 PH |
887 | # define yyerrok (yystack->yyerrState = 0) |
888 | # undef YYACCEPT | |
889 | # define YYACCEPT return yyaccept | |
890 | # undef YYABORT | |
891 | # define YYABORT return yyabort | |
892 | # undef YYERROR | |
5cc16ecc | 893 | # define YYERROR return yyerrok, yyerr |
01241d47 PH |
894 | # undef YYRECOVERING |
895 | # define YYRECOVERING (yystack->yyerrState != 0) | |
896 | # undef yyclearin | |
897 | # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY) | |
f868dc04 | 898 | # undef YYFILL |
6a84279c | 899 | # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal) |
01241d47 PH |
900 | # undef YYBACKUP |
901 | # define YYBACKUP(Token, Value) \ | |
30757c8c | 902 | return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ |
5cc16ecc | 903 | yyerrok, yyerr |
01241d47 | 904 | |
25005f6a PH |
905 | yylow = 1; |
906 | if (yyrhslen == 0) | |
b4a20338 | 907 | *yyvalp = yyval_default; |
25005f6a | 908 | else |
b4a20338 AD |
909 | *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval; |
910 | YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen); | |
d741bd1b PE |
911 | ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = *yylocp; |
912 | ]]) | |
25005f6a PH |
913 | switch (yyn) |
914 | { | |
915 | b4_actions | |
95f22ad2 | 916 | default: break; |
25005f6a | 917 | } |
01241d47 | 918 | |
25005f6a | 919 | return yyok; |
01241d47 PH |
920 | # undef yyerrok |
921 | # undef YYABORT | |
922 | # undef YYACCEPT | |
923 | # undef YYERROR | |
924 | # undef YYBACKUP | |
925 | # undef yyclearin | |
926 | # undef YYRECOVERING | |
996b1c7e | 927 | /* Line __line__ of glr.c. */ |
947427ae | 928 | b4_syncline([@oline@], [@ofile@]) |
01241d47 PH |
929 | } |
930 | \f | |
931 | ||
12ce2df6 | 932 | /*ARGSUSED*/ static void |
01241d47 PH |
933 | yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) |
934 | { | |
2a4647a3 PE |
935 | YYUSE (yy0); |
936 | YYUSE (yy1); | |
1154cced | 937 | |
fb8135fa | 938 | switch (yyn) |
01241d47 PH |
939 | { |
940 | b4_mergers | |
e2688cd9 | 941 | default: break; |
01241d47 | 942 | } |
01241d47 PH |
943 | } |
944 | [ | |
2a8d363a | 945 | /* Bison grammar-table manipulation. */ |
01241d47 | 946 | |
7bd6c77e AD |
947 | ]b4_yydestruct_generate([b4_c_ansi_function_def])[ |
948 | ||
42a6501d PE |
949 | /** Number of symbols composing the right hand side of rule #RULE. */ |
950 | static inline int | |
951 | yyrhsLength (yyRuleNum yyrule) | |
952 | { | |
953 | return yyr2[yyrule]; | |
954 | } | |
955 | ||
a4cf101a | 956 | static void |
4b367315 | 957 | yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) |
a4cf101a PE |
958 | { |
959 | if (yys->yyresolved) | |
960 | yydestruct (yymsg, yystos[yys->yylrState], | |
4b367315 | 961 | &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[); |
a4cf101a PE |
962 | else |
963 | { | |
964 | #if YYDEBUG | |
965 | if (yydebug) | |
966 | { | |
967 | YYFPRINTF (stderr, "%s unresolved ", yymsg); | |
968 | yysymprint (stderr, yystos[yys->yylrState], | |
4b367315 | 969 | &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[); |
2f4f028d | 970 | YYFPRINTF (stderr, "\n"); |
a4cf101a PE |
971 | } |
972 | #endif | |
a4cf101a | 973 | |
42a6501d | 974 | if (yys->yysemantics.yyfirstVal) |
69ce078b PE |
975 | { |
976 | yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; | |
977 | yyGLRState *yyrh; | |
978 | int yyn; | |
979 | for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); | |
980 | yyn > 0; | |
981 | yyrh = yyrh->yypred, yyn -= 1) | |
982 | yydestroyGLRState (yymsg, yyrh]b4_user_args[); | |
983 | } | |
42a6501d | 984 | } |
01241d47 PH |
985 | } |
986 | ||
987 | /** Left-hand-side symbol for rule #RULE. */ | |
988 | static inline yySymbol | |
fb8135fa | 989 | yylhsNonterm (yyRuleNum yyrule) |
01241d47 PH |
990 | { |
991 | return yyr1[yyrule]; | |
992 | } | |
993 | ||
944ed9f4 | 994 | #define yyis_pact_ninf(yystate) \ |
62b08cfc AD |
995 | ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1], |
996 | [0], | |
997 | [((yystate) == YYPACT_NINF)])[ | |
944ed9f4 | 998 | |
01241d47 PH |
999 | /** True iff LR state STATE has only a default reduction (regardless |
1000 | * of token). */ | |
f7c398aa | 1001 | static inline yybool |
01241d47 PH |
1002 | yyisDefaultedState (yyStateNum yystate) |
1003 | { | |
944ed9f4 | 1004 | return yyis_pact_ninf (yypact[yystate]); |
01241d47 | 1005 | } |
fb8135fa | 1006 | |
01241d47 PH |
1007 | /** The default reduction for STATE, assuming it has one. */ |
1008 | static inline yyRuleNum | |
1009 | yydefaultAction (yyStateNum yystate) | |
1010 | { | |
1011 | return yydefact[yystate]; | |
1012 | } | |
1013 | ||
df38312a | 1014 | #define yyis_table_ninf(yytable_value) \ |
62b08cfc AD |
1015 | ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1], |
1016 | [0], | |
1017 | [((yytable_value) == YYTABLE_NINF)])[ | |
944ed9f4 | 1018 | |
2a1fe6ed | 1019 | /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. |
01241d47 PH |
1020 | * Result R means |
1021 | * R < 0: Reduce on rule -R. | |
1022 | * R = 0: Error. | |
fb8135fa AD |
1023 | * R > 0: Shift to state R. |
1024 | * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of | |
01241d47 PH |
1025 | * conflicting reductions. |
1026 | */ | |
1027 | static inline void | |
fb8135fa | 1028 | yygetLRActions (yyStateNum yystate, int yytoken, |
69ce078b | 1029 | int* yyaction, const short int** yyconflicts) |
01241d47 PH |
1030 | { |
1031 | int yyindex = yypact[yystate] + yytoken; | |
f50adbbd | 1032 | if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) |
01241d47 PH |
1033 | { |
1034 | *yyaction = -yydefact[yystate]; | |
1035 | *yyconflicts = yyconfl; | |
1036 | } | |
df38312a | 1037 | else if (! yyis_table_ninf (yytable[yyindex])) |
01241d47 PH |
1038 | { |
1039 | *yyaction = yytable[yyindex]; | |
1040 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
1041 | } | |
f50adbbd AD |
1042 | else |
1043 | { | |
1044 | *yyaction = 0; | |
1045 | *yyconflicts = yyconfl + yyconflp[yyindex]; | |
1046 | } | |
01241d47 PH |
1047 | } |
1048 | ||
1049 | static inline yyStateNum | |
1050 | yyLRgotoState (yyStateNum yystate, yySymbol yylhs) | |
1051 | { | |
1052 | int yyr; | |
1053 | yyr = yypgoto[yylhs - YYNTOKENS] + yystate; | |
f50adbbd | 1054 | if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) |
01241d47 PH |
1055 | return yytable[yyr]; |
1056 | else | |
1057 | return yydefgoto[yylhs - YYNTOKENS]; | |
1058 | } | |
1059 | ||
f7c398aa | 1060 | static inline yybool |
fb8135fa | 1061 | yyisShiftAction (int yyaction) |
01241d47 | 1062 | { |
39912f52 | 1063 | return 0 < yyaction; |
01241d47 PH |
1064 | } |
1065 | ||
f7c398aa | 1066 | static inline yybool |
fb8135fa | 1067 | yyisErrorAction (int yyaction) |
01241d47 | 1068 | { |
f50adbbd | 1069 | return yyaction == 0; |
01241d47 PH |
1070 | } |
1071 | ||
1072 | /* GLRStates */ | |
1073 | ||
02998094 AD |
1074 | /** Return a fresh GLRStackItem. Callers should call |
1075 | * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient | |
1076 | * headroom. */ | |
1077 | ||
1078 | static inline yyGLRStackItem* | |
1079 | yynewGLRStackItem (yyGLRStack* yystack, yybool yyisState) | |
1080 | { | |
1081 | yyGLRStackItem* yynewItem = yystack->yynextFree; | |
1082 | yystack->yyspaceLeft -= 1; | |
1083 | yystack->yynextFree += 1; | |
1084 | yynewItem->yystate.yyisState = yyisState; | |
1085 | return yynewItem; | |
1086 | } | |
1087 | ||
1154cced AD |
1088 | static void |
1089 | yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, | |
df9a1ba4 | 1090 | yyGLRState* rhs, yyRuleNum yyrule) |
01241d47 | 1091 | { |
02998094 AD |
1092 | yySemanticOption* yynewOption = |
1093 | &yynewGLRStackItem (yystack, yyfalse)->yyoption; | |
1094 | yynewOption->yystate = rhs; | |
1095 | yynewOption->yyrule = yyrule; | |
1096 | yynewOption->yynext = yystate->yysemantics.yyfirstVal; | |
1097 | yystate->yysemantics.yyfirstVal = yynewOption; | |
1098 | ||
1099 | YY_RESERVE_GLRSTACK (yystack); | |
01241d47 PH |
1100 | } |
1101 | ||
1102 | /* GLRStacks */ | |
1103 | ||
1104 | /** Initialize SET to a singleton set containing an empty stack. */ | |
63cb01d6 | 1105 | static yybool |
01241d47 PH |
1106 | yyinitStateSet (yyGLRStateSet* yyset) |
1107 | { | |
1108 | yyset->yysize = 1; | |
1109 | yyset->yycapacity = 16; | |
be16239b | 1110 | yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]); |
63cb01d6 PE |
1111 | if (! yyset->yystates) |
1112 | return yyfalse; | |
01241d47 | 1113 | yyset->yystates[0] = NULL; |
63cb01d6 | 1114 | return yytrue; |
01241d47 PH |
1115 | } |
1116 | ||
fb8135fa | 1117 | static void yyfreeStateSet (yyGLRStateSet* yyset) |
01241d47 | 1118 | { |
a525b568 | 1119 | YYFREE (yyset->yystates); |
01241d47 PH |
1120 | } |
1121 | ||
1122 | /** Initialize STACK to a single empty stack, with total maximum | |
1123 | * capacity for all stacks of SIZE. */ | |
63cb01d6 | 1124 | static yybool |
01241d47 PH |
1125 | yyinitGLRStack (yyGLRStack* yystack, size_t yysize) |
1126 | { | |
01241d47 PH |
1127 | yystack->yyerrState = 0; |
1128 | yynerrs = 0; | |
1129 | yystack->yyspaceLeft = yysize; | |
3922956a | 1130 | yystack->yyitems = |
be16239b | 1131 | (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystack->yynextFree[0]); |
3922956a PE |
1132 | if (!yystack->yyitems) |
1133 | return yyfalse; | |
1134 | yystack->yynextFree = yystack->yyitems; | |
01241d47 PH |
1135 | yystack->yysplitPoint = NULL; |
1136 | yystack->yylastDeleted = NULL; | |
3922956a | 1137 | return yyinitStateSet (&yystack->yytops); |
01241d47 PH |
1138 | } |
1139 | ||
02998094 AD |
1140 | |
1141 | #if YYSTACKEXPANDABLE | |
1142 | # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ | |
01241d47 PH |
1143 | &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE |
1144 | ||
1145 | /** If STACK is expandable, extend it. WARNING: Pointers into the | |
1146 | stack from outside should be considered invalid after this call. | |
1147 | We always expand when there are 1 or fewer items left AFTER an | |
1148 | allocation, so that we can avoid having external pointers exist | |
1149 | across an allocation. */ | |
1150 | static void | |
df9a1ba4 | 1151 | yyexpandGLRStack (yyGLRStack* yystack) |
01241d47 | 1152 | { |
63cb01d6 | 1153 | yyGLRStackItem* yynewItems; |
01241d47 PH |
1154 | yyGLRStackItem* yyp0, *yyp1; |
1155 | size_t yysize, yynewSize; | |
1156 | size_t yyn; | |
1157 | yysize = yystack->yynextFree - yystack->yyitems; | |
39912f52 | 1158 | if (YYMAXDEPTH <= yysize) |
1a059451 | 1159 | yyMemoryExhausted (yystack); |
01241d47 | 1160 | yynewSize = 2*yysize; |
39912f52 | 1161 | if (YYMAXDEPTH < yynewSize) |
01241d47 | 1162 | yynewSize = YYMAXDEPTH; |
63cb01d6 PE |
1163 | yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]); |
1164 | if (! yynewItems) | |
1a059451 | 1165 | yyMemoryExhausted (yystack); |
63cb01d6 | 1166 | for (yyp0 = yystack->yyitems, yyp1 = yynewItems, yyn = yysize; |
39912f52 | 1167 | 0 < yyn; |
fb8135fa | 1168 | yyn -= 1, yyp0 += 1, yyp1 += 1) |
01241d47 PH |
1169 | { |
1170 | *yyp1 = *yyp0; | |
f7c398aa | 1171 | if (*(yybool *) yyp0) |
fb8135fa | 1172 | { |
01241d47 PH |
1173 | yyGLRState* yys0 = &yyp0->yystate; |
1174 | yyGLRState* yys1 = &yyp1->yystate; | |
fb8135fa AD |
1175 | if (yys0->yypred != NULL) |
1176 | yys1->yypred = | |
01241d47 PH |
1177 | YYRELOC (yyp0, yyp1, yys0->yypred, yystate); |
1178 | if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL) | |
fb8135fa | 1179 | yys1->yysemantics.yyfirstVal = |
01241d47 PH |
1180 | YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); |
1181 | } | |
fb8135fa | 1182 | else |
01241d47 PH |
1183 | { |
1184 | yySemanticOption* yyv0 = &yyp0->yyoption; | |
1185 | yySemanticOption* yyv1 = &yyp1->yyoption; | |
1186 | if (yyv0->yystate != NULL) | |
1187 | yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); | |
1188 | if (yyv0->yynext != NULL) | |
1189 | yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); | |
1190 | } | |
1191 | } | |
1192 | if (yystack->yysplitPoint != NULL) | |
63cb01d6 | 1193 | yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewItems, |
01241d47 | 1194 | yystack->yysplitPoint, yystate); |
fb8135fa AD |
1195 | |
1196 | for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1) | |
01241d47 | 1197 | if (yystack->yytops.yystates[yyn] != NULL) |
fb8135fa | 1198 | yystack->yytops.yystates[yyn] = |
63cb01d6 | 1199 | YYRELOC (yystack->yyitems, yynewItems, |
01241d47 | 1200 | yystack->yytops.yystates[yyn], yystate); |
a525b568 | 1201 | YYFREE (yystack->yyitems); |
63cb01d6 PE |
1202 | yystack->yyitems = yynewItems; |
1203 | yystack->yynextFree = yynewItems + yysize; | |
1204 | yystack->yyspaceLeft = yynewSize - yysize; | |
01241d47 | 1205 | } |
02998094 | 1206 | #endif |
01241d47 PH |
1207 | |
1208 | static void | |
fb8135fa | 1209 | yyfreeGLRStack (yyGLRStack* yystack) |
01241d47 | 1210 | { |
a525b568 | 1211 | YYFREE (yystack->yyitems); |
01241d47 PH |
1212 | yyfreeStateSet (&yystack->yytops); |
1213 | } | |
1214 | ||
1215 | /** Assuming that S is a GLRState somewhere on STACK, update the | |
fb8135fa | 1216 | * splitpoint of STACK, if needed, so that it is at least as deep as |
01241d47 PH |
1217 | * S. */ |
1218 | static inline void | |
fb8135fa | 1219 | yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys) |
01241d47 | 1220 | { |
fb8135fa | 1221 | if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys) |
01241d47 PH |
1222 | yystack->yysplitPoint = yys; |
1223 | } | |
1224 | ||
1225 | /** Invalidate stack #K in STACK. */ | |
1226 | static inline void | |
63cb01d6 | 1227 | yymarkStackDeleted (yyGLRStack* yystack, size_t yyk) |
01241d47 PH |
1228 | { |
1229 | if (yystack->yytops.yystates[yyk] != NULL) | |
1230 | yystack->yylastDeleted = yystack->yytops.yystates[yyk]; | |
1231 | yystack->yytops.yystates[yyk] = NULL; | |
1232 | } | |
1233 | ||
fb8135fa | 1234 | /** Undelete the last stack that was marked as deleted. Can only be |
01241d47 PH |
1235 | done once after a deletion, and only when all other stacks have |
1236 | been deleted. */ | |
1237 | static void | |
1238 | yyundeleteLastStack (yyGLRStack* yystack) | |
1239 | { | |
1240 | if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0) | |
1241 | return; | |
fb8135fa | 1242 | yystack->yytops.yystates[0] = yystack->yylastDeleted; |
01241d47 | 1243 | yystack->yytops.yysize = 1; |
2f4f028d | 1244 | YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); |
01241d47 PH |
1245 | yystack->yylastDeleted = NULL; |
1246 | } | |
1247 | ||
1248 | static inline void | |
1249 | yyremoveDeletes (yyGLRStack* yystack) | |
1250 | { | |
1154cced | 1251 | size_t yyi, yyj; |
01241d47 | 1252 | yyi = yyj = 0; |
fb8135fa | 1253 | while (yyj < yystack->yytops.yysize) |
01241d47 PH |
1254 | { |
1255 | if (yystack->yytops.yystates[yyi] == NULL) | |
1256 | { | |
1154cced | 1257 | if (yyi == yyj) |
ee16363f | 1258 | { |
2f4f028d | 1259 | YYDPRINTF ((stderr, "Removing dead stacks.\n")); |
ee16363f | 1260 | } |
01241d47 PH |
1261 | yystack->yytops.yysize -= 1; |
1262 | } | |
fb8135fa | 1263 | else |
01241d47 PH |
1264 | { |
1265 | yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi]; | |
1266 | if (yyj != yyi) | |
ee16363f | 1267 | { |
08fc98e5 PE |
1268 | YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n", |
1269 | (unsigned long int) yyi, (unsigned long int) yyj)); | |
ee16363f | 1270 | } |
01241d47 PH |
1271 | yyj += 1; |
1272 | } | |
1273 | yyi += 1; | |
1274 | } | |
1275 | } | |
1276 | ||
fb8135fa | 1277 | /** Shift to a new state on stack #K of STACK, corresponding to LR state |
01241d47 PH |
1278 | * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */ |
1279 | static inline void | |
63cb01d6 PE |
1280 | yyglrShift (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState, |
1281 | size_t yyposn, | |
df9a1ba4 | 1282 | YYSTYPE yysval, YYLTYPE* yylocp) |
01241d47 | 1283 | { |
02998094 | 1284 | yyGLRState* yynewState = &yynewGLRStackItem (yystack, yytrue)->yystate; |
01241d47 | 1285 | |
02998094 AD |
1286 | yynewState->yylrState = yylrState; |
1287 | yynewState->yyposn = yyposn; | |
1288 | yynewState->yyresolved = yytrue; | |
1289 | yynewState->yypred = yystack->yytops.yystates[yyk]; | |
1290 | yynewState->yysemantics.yysval = yysval; | |
1291 | yynewState->yyloc = *yylocp; | |
1292 | yystack->yytops.yystates[yyk] = yynewState; | |
1293 | ||
1294 | YY_RESERVE_GLRSTACK (yystack); | |
01241d47 PH |
1295 | } |
1296 | ||
f868dc04 | 1297 | /** Shift stack #K of YYSTACK, to a new state corresponding to LR |
c4749565 | 1298 | * state YYLRSTATE, at input position YYPOSN, with the (unresolved) |
f868dc04 | 1299 | * semantic value of YYRHS under the action for YYRULE. */ |
01241d47 | 1300 | static inline void |
63cb01d6 | 1301 | yyglrShiftDefer (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState, |
df9a1ba4 | 1302 | size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule) |
01241d47 | 1303 | { |
02998094 AD |
1304 | yyGLRState* yynewState = &yynewGLRStackItem (yystack, yytrue)->yystate; |
1305 | ||
1306 | yynewState->yylrState = yylrState; | |
1307 | yynewState->yyposn = yyposn; | |
1308 | yynewState->yyresolved = yyfalse; | |
1309 | yynewState->yypred = yystack->yytops.yystates[yyk]; | |
1310 | yynewState->yysemantics.yyfirstVal = NULL; | |
1311 | yystack->yytops.yystates[yyk] = yynewState; | |
1312 | ||
1313 | /* Invokes YY_RESERVE_GLRSTACK. */ | |
1314 | yyaddDeferredAction (yystack, yynewState, rhs, yyrule); | |
01241d47 PH |
1315 | } |
1316 | ||
1317 | /** Pop the symbols consumed by reduction #RULE from the top of stack | |
fb8135fa AD |
1318 | * #K of STACK, and perform the appropriate semantic action on their |
1319 | * semantic values. Assumes that all ambiguities in semantic values | |
01241d47 PH |
1320 | * have been previously resolved. Set *VALP to the resulting value, |
1321 | * and *LOCP to the computed location (if any). Return value is as | |
1322 | * for userAction. */ | |
ff032592 | 1323 | static inline YYRESULTTAG |
63cb01d6 | 1324 | yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, |
5cc16ecc | 1325 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1326 | { |
1327 | int yynrhs = yyrhsLength (yyrule); | |
1328 | ||
fb8135fa | 1329 | if (yystack->yysplitPoint == NULL) |
01241d47 PH |
1330 | { |
1331 | /* Standard special case: single stack. */ | |
6fed0802 | 1332 | yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk]; |
64c4fd52 | 1333 | YYASSERT (yyk == 0); |
01241d47 PH |
1334 | yystack->yynextFree -= yynrhs; |
1335 | yystack->yyspaceLeft += yynrhs; | |
1336 | yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate; | |
e7cb57c0 | 1337 | return yyuserAction (yyrule, yynrhs, rhs, |
2a8d363a | 1338 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 | 1339 | } |
fb8135fa | 1340 | else |
01241d47 | 1341 | { |
44e7ead1 PH |
1342 | /* At present, doAction is never called in nondeterministic |
1343 | * mode, so this branch is never taken. It is here in | |
1344 | * anticipation of a future feature that will allow immediate | |
1345 | * evaluation of selected actions in nondeterministic mode. */ | |
01241d47 PH |
1346 | int yyi; |
1347 | yyGLRState* yys; | |
25005f6a | 1348 | yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; |
5cc16ecc | 1349 | yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred |
44e7ead1 PH |
1350 | = yystack->yytops.yystates[yyk];]b4_location_if([[ |
1351 | if (yynrhs == 0) | |
1352 | /* Set default location. */ | |
69ce078b | 1353 | yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[ |
f868dc04 | 1354 | for (yyi = 0; yyi < yynrhs; yyi += 1) |
01241d47 | 1355 | { |
f868dc04 | 1356 | yys = yys->yypred; |
64c4fd52 | 1357 | YYASSERT (yys); |
01241d47 PH |
1358 | } |
1359 | yyupdateSplit (yystack, yys); | |
1360 | yystack->yytops.yystates[yyk] = yys; | |
25005f6a | 1361 | return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, |
2a8d363a | 1362 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 PH |
1363 | } |
1364 | } | |
1365 | ||
e7cb57c0 | 1366 | #if !YYDEBUG |
62b08cfc | 1367 | # define YY_REDUCE_PRINT(Args) |
e7cb57c0 | 1368 | #else |
62b08cfc | 1369 | # define YY_REDUCE_PRINT(Args) \ |
e7cb57c0 AD |
1370 | do { \ |
1371 | if (yydebug) \ | |
62b08cfc | 1372 | yy_reduce_print Args; \ |
12ce2df6 | 1373 | } while (YYID (0)) |
e7cb57c0 AD |
1374 | |
1375 | /*----------------------------------------------------------. | |
1376 | | Report that the RULE is going to be reduced on stack #K. | | |
1377 | `----------------------------------------------------------*/ | |
1378 | ||
12ce2df6 | 1379 | /*ARGSUSED*/ static inline void |
62b08cfc AD |
1380 | yy_reduce_print (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, |
1381 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) | |
e7cb57c0 | 1382 | { |
62b08cfc AD |
1383 | int yynrhs = yyrhsLength (yyrule); |
1384 | yybool yynormal __attribute__ ((__unused__)) = | |
1385 | (yystack->yysplitPoint == NULL); | |
1386 | yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystack->yytops.yystates[yyk]; | |
1387 | int yylow = 1; | |
e7cb57c0 | 1388 | int yyi; |
613d8952 AD |
1389 | YYUSE (yyvalp); |
1390 | YYUSE (yylocp); | |
1391 | ]b4_parse_param_use[]dnl | |
1392 | [ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n", | |
08fc98e5 PE |
1393 | (unsigned long int) yyk, yyrule - 1, |
1394 | (unsigned long int) yyrline[yyrule]); | |
6de5398d | 1395 | /* The symbols being reduced. */ |
62b08cfc AD |
1396 | for (yyi = 0; yyi < yynrhs; yyi++) |
1397 | { | |
a1373f55 | 1398 | fprintf (stderr, " $%d = ", yyi + 1); |
62b08cfc | 1399 | yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi], |
69ce078b PE |
1400 | &]b4_rhs_value(yynrhs, yyi + 1)[ |
1401 | ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl | |
1402 | b4_user_args[); | |
62b08cfc AD |
1403 | fprintf (stderr, "\n"); |
1404 | } | |
e7cb57c0 AD |
1405 | } |
1406 | #endif | |
1407 | ||
01241d47 PH |
1408 | /** Pop items off stack #K of STACK according to grammar rule RULE, |
1409 | * and push back on the resulting nonterminal symbol. Perform the | |
fb8135fa | 1410 | * semantic action associated with RULE and store its value with the |
01241d47 PH |
1411 | * newly pushed state, if FORCEEVAL or if STACK is currently |
1412 | * unambiguous. Otherwise, store the deferred semantic action with | |
1413 | * the new state. If the new state would have an identical input | |
1414 | * position, LR state, and predecessor to an existing state on the stack, | |
fb8135fa AD |
1415 | * it is identified with that existing state, eliminating stack #K from |
1416 | * the STACK. In this case, the (necessarily deferred) semantic value is | |
1417 | * added to the options for the existing state's semantic value. | |
01241d47 PH |
1418 | */ |
1419 | static inline YYRESULTTAG | |
1154cced | 1420 | yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, |
69ce078b | 1421 | yybool yyforceEval]b4_user_formals[) |
01241d47 | 1422 | { |
1154cced | 1423 | size_t yyposn = yystack->yytops.yystates[yyk]->yyposn; |
01241d47 | 1424 | |
fb8135fa | 1425 | if (yyforceEval || yystack->yysplitPoint == NULL) |
01241d47 PH |
1426 | { |
1427 | YYSTYPE yysval; | |
1428 | YYLTYPE yyloc; | |
fb8135fa | 1429 | |
62b08cfc | 1430 | YY_REDUCE_PRINT ((yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); |
2a8d363a | 1431 | YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); |
62b08cfc | 1432 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc); |
fb8135fa AD |
1433 | yyglrShift (yystack, yyk, |
1434 | yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState, | |
01241d47 | 1435 | yylhsNonterm (yyrule)), |
df9a1ba4 | 1436 | yyposn, yysval, &yyloc); |
01241d47 | 1437 | } |
fb8135fa | 1438 | else |
01241d47 | 1439 | { |
1154cced AD |
1440 | size_t yyi; |
1441 | int yyn; | |
01241d47 PH |
1442 | yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk]; |
1443 | yyStateNum yynewLRState; | |
1444 | ||
fb8135fa | 1445 | for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); |
39912f52 | 1446 | 0 < yyn; yyn -= 1) |
01241d47 PH |
1447 | { |
1448 | yys = yys->yypred; | |
64c4fd52 | 1449 | YYASSERT (yys); |
01241d47 PH |
1450 | } |
1451 | yyupdateSplit (yystack, yys); | |
1452 | yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); | |
fb8135fa | 1453 | YYDPRINTF ((stderr, |
dfc8a220 | 1454 | "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n", |
08fc98e5 | 1455 | (unsigned long int) yyk, yyrule - 1, yynewLRState)); |
01241d47 | 1456 | for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1) |
fb8135fa | 1457 | if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL) |
01241d47 PH |
1458 | { |
1459 | yyGLRState* yyp, *yysplit = yystack->yysplitPoint; | |
1460 | yyp = yystack->yytops.yystates[yyi]; | |
fb8135fa | 1461 | while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) |
01241d47 | 1462 | { |
fb8135fa | 1463 | if (yyp->yylrState == yynewLRState && yyp->yypred == yys) |
01241d47 | 1464 | { |
df9a1ba4 | 1465 | yyaddDeferredAction (yystack, yyp, yys0, yyrule); |
01241d47 | 1466 | yymarkStackDeleted (yystack, yyk); |
08fc98e5 PE |
1467 | YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n", |
1468 | (unsigned long int) yyk, | |
1469 | (unsigned long int) yyi)); | |
ff032592 | 1470 | return yyok; |
01241d47 PH |
1471 | } |
1472 | yyp = yyp->yypred; | |
1473 | } | |
1474 | } | |
1475 | yystack->yytops.yystates[yyk] = yys; | |
df9a1ba4 | 1476 | yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule); |
fb8135fa | 1477 | } |
ff032592 | 1478 | return yyok; |
01241d47 PH |
1479 | } |
1480 | ||
63cb01d6 | 1481 | static size_t |
df9a1ba4 | 1482 | yysplitStack (yyGLRStack* yystack, size_t yyk) |
01241d47 | 1483 | { |
fb8135fa | 1484 | if (yystack->yysplitPoint == NULL) |
01241d47 | 1485 | { |
64c4fd52 | 1486 | YYASSERT (yyk == 0); |
01241d47 PH |
1487 | yystack->yysplitPoint = yystack->yytops.yystates[yyk]; |
1488 | } | |
fb8135fa | 1489 | if (yystack->yytops.yysize >= yystack->yytops.yycapacity) |
01241d47 | 1490 | { |
63cb01d6 PE |
1491 | yyGLRState** yynewStates; |
1492 | if (! ((yystack->yytops.yycapacity | |
1493 | <= (YYSIZEMAX / (2 * sizeof yynewStates[0]))) | |
1494 | && (yynewStates = | |
1495 | (yyGLRState**) YYREALLOC (yystack->yytops.yystates, | |
1496 | ((yystack->yytops.yycapacity *= 2) | |
1497 | * sizeof yynewStates[0]))))) | |
1a059451 | 1498 | yyMemoryExhausted (yystack); |
63cb01d6 | 1499 | yystack->yytops.yystates = yynewStates; |
01241d47 | 1500 | } |
fb8135fa | 1501 | yystack->yytops.yystates[yystack->yytops.yysize] |
01241d47 PH |
1502 | = yystack->yytops.yystates[yyk]; |
1503 | yystack->yytops.yysize += 1; | |
1504 | return yystack->yytops.yysize-1; | |
1505 | } | |
1506 | ||
1507 | /** True iff Y0 and Y1 represent identical options at the top level. | |
1508 | * That is, they represent the same rule applied to RHS symbols | |
1509 | * that produce the same terminal symbols. */ | |
f7c398aa | 1510 | static yybool |
01241d47 PH |
1511 | yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) |
1512 | { | |
fb8135fa | 1513 | if (yyy0->yyrule == yyy1->yyrule) |
01241d47 PH |
1514 | { |
1515 | yyGLRState *yys0, *yys1; | |
1516 | int yyn; | |
fb8135fa | 1517 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, |
01241d47 PH |
1518 | yyn = yyrhsLength (yyy0->yyrule); |
1519 | yyn > 0; | |
1520 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
1521 | if (yys0->yyposn != yys1->yyposn) | |
1522 | return yyfalse; | |
1523 | return yytrue; | |
1524 | } | |
1525 | else | |
1526 | return yyfalse; | |
1527 | } | |
1528 | ||
5e6f62f2 PH |
1529 | /** Assuming identicalOptions (Y0,Y1), destructively merge the |
1530 | * alternative semantic values for the RHS-symbols of Y1 and Y0. */ | |
01241d47 PH |
1531 | static void |
1532 | yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) | |
1533 | { | |
1534 | yyGLRState *yys0, *yys1; | |
1535 | int yyn; | |
fb8135fa | 1536 | for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, |
01241d47 PH |
1537 | yyn = yyrhsLength (yyy0->yyrule); |
1538 | yyn > 0; | |
1539 | yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) | |
5e6f62f2 PH |
1540 | { |
1541 | if (yys0 == yys1) | |
1542 | break; | |
010f91c3 | 1543 | else if (yys0->yyresolved) |
5e6f62f2 PH |
1544 | { |
1545 | yys1->yyresolved = yytrue; | |
1546 | yys1->yysemantics.yysval = yys0->yysemantics.yysval; | |
1547 | } | |
1548 | else if (yys1->yyresolved) | |
1549 | { | |
1550 | yys0->yyresolved = yytrue; | |
1551 | yys0->yysemantics.yysval = yys1->yysemantics.yysval; | |
1552 | } | |
010f91c3 | 1553 | else |
5e6f62f2 PH |
1554 | { |
1555 | yySemanticOption** yyz0p; | |
1556 | yySemanticOption* yyz1; | |
1557 | yyz0p = &yys0->yysemantics.yyfirstVal; | |
1558 | yyz1 = yys1->yysemantics.yyfirstVal; | |
1559 | while (yytrue) | |
1560 | { | |
1561 | if (yyz1 == *yyz0p || yyz1 == NULL) | |
1562 | break; | |
1563 | else if (*yyz0p == NULL) | |
1564 | { | |
1565 | *yyz0p = yyz1; | |
1566 | break; | |
1567 | } | |
1568 | else if (*yyz0p < yyz1) | |
1569 | { | |
1570 | yySemanticOption* yyz = *yyz0p; | |
1571 | *yyz0p = yyz1; | |
1572 | yyz1 = yyz1->yynext; | |
1573 | (*yyz0p)->yynext = yyz; | |
1574 | } | |
1575 | yyz0p = &(*yyz0p)->yynext; | |
1576 | } | |
1577 | yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal; | |
1578 | } | |
1579 | } | |
01241d47 PH |
1580 | } |
1581 | ||
1582 | /** Y0 and Y1 represent two possible actions to take in a given | |
1583 | * parsing state; return 0 if no combination is possible, | |
1584 | * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ | |
1585 | static int | |
1154cced | 1586 | yypreference (yySemanticOption* y0, yySemanticOption* y1) |
01241d47 | 1587 | { |
1154cced AD |
1588 | yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; |
1589 | int p0 = yydprec[r0], p1 = yydprec[r1]; | |
01241d47 | 1590 | |
1154cced | 1591 | if (p0 == p1) |
01241d47 | 1592 | { |
1154cced | 1593 | if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) |
01241d47 PH |
1594 | return 0; |
1595 | else | |
1596 | return 1; | |
1597 | } | |
1154cced | 1598 | if (p0 == 0 || p1 == 0) |
01241d47 | 1599 | return 0; |
1154cced | 1600 | if (p0 < p1) |
01241d47 | 1601 | return 3; |
39912f52 | 1602 | if (p1 < p0) |
01241d47 PH |
1603 | return 2; |
1604 | return 0; | |
1605 | } | |
1606 | ||
fb8135fa AD |
1607 | static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList, |
1608 | yyGLRStack* yystack, YYSTYPE* yyvalp, | |
2a8d363a | 1609 | YYLTYPE* yylocp]b4_user_formals[); |
01241d47 PH |
1610 | |
1611 | static YYRESULTTAG | |
2a8d363a | 1612 | yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[) |
01241d47 PH |
1613 | { |
1614 | YYRESULTTAG yyflag; | |
39912f52 | 1615 | if (0 < yyn) |
01241d47 | 1616 | { |
64c4fd52 | 1617 | YYASSERT (yys->yypred); |
2a8d363a | 1618 | yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[); |
01241d47 PH |
1619 | if (yyflag != yyok) |
1620 | return yyflag; | |
fb8135fa | 1621 | if (! yys->yyresolved) |
01241d47 PH |
1622 | { |
1623 | yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack, | |
e7cb57c0 | 1624 | &yys->yysemantics.yysval, &yys->yyloc |
2a8d363a | 1625 | ]b4_user_args[); |
01241d47 PH |
1626 | if (yyflag != yyok) |
1627 | return yyflag; | |
1628 | yys->yyresolved = yytrue; | |
1629 | } | |
1630 | } | |
1631 | return yyok; | |
1632 | } | |
1633 | ||
1634 | static YYRESULTTAG | |
fb8135fa | 1635 | yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, |
69ce078b | 1636 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 | 1637 | { |
25005f6a | 1638 | yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; |
f868dc04 | 1639 | int yynrhs; |
01241d47 PH |
1640 | |
1641 | yynrhs = yyrhsLength (yyopt->yyrule); | |
2a8d363a | 1642 | YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[)); |
44e7ead1 PH |
1643 | yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_location_if([[ |
1644 | if (yynrhs == 0) | |
1645 | /* Set default location. */ | |
1646 | yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[ | |
5cc16ecc | 1647 | return yyuserAction (yyopt->yyrule, yynrhs, |
25005f6a | 1648 | yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, |
2a8d363a | 1649 | yyvalp, yylocp, yystack]b4_user_args[); |
01241d47 PH |
1650 | } |
1651 | ||
1652 | #if YYDEBUG | |
e7cb57c0 AD |
1653 | static void |
1654 | yyreportTree (yySemanticOption* yyx, int yyindent) | |
01241d47 PH |
1655 | { |
1656 | int yynrhs = yyrhsLength (yyx->yyrule); | |
1657 | int yyi; | |
1658 | yyGLRState* yys; | |
1659 | yyGLRState* yystates[YYMAXRHS]; | |
782a05f9 | 1660 | yyGLRState yyleftmost_state; |
01241d47 | 1661 | |
39912f52 | 1662 | for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) |
01241d47 PH |
1663 | yystates[yyi] = yys; |
1664 | if (yys == NULL) | |
782a05f9 PE |
1665 | { |
1666 | yyleftmost_state.yyposn = 0; | |
1667 | yystates[0] = &yyleftmost_state; | |
1668 | } | |
01241d47 PH |
1669 | else |
1670 | yystates[0] = yys; | |
1671 | ||
39912f52 | 1672 | if (yyx->yystate->yyposn < yys->yyposn + 1) |
01241d47 | 1673 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n", |
fb8135fa | 1674 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), |
01241d47 PH |
1675 | yyx->yyrule); |
1676 | else | |
08fc98e5 | 1677 | YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n", |
01241d47 | 1678 | yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), |
08fc98e5 PE |
1679 | yyx->yyrule, (unsigned long int) (yys->yyposn + 1), |
1680 | (unsigned long int) yyx->yystate->yyposn); | |
fb8135fa | 1681 | for (yyi = 1; yyi <= yynrhs; yyi += 1) |
01241d47 | 1682 | { |
fb8135fa | 1683 | if (yystates[yyi]->yyresolved) |
01241d47 PH |
1684 | { |
1685 | if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) | |
1686 | YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "", | |
1687 | yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1])); | |
1688 | else | |
08fc98e5 | 1689 | YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "", |
01241d47 | 1690 | yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]), |
08fc98e5 PE |
1691 | (unsigned long int) (yystates[yyi - 1]->yyposn + 1), |
1692 | (unsigned long int) yystates[yyi]->yyposn); | |
01241d47 | 1693 | } |
fb8135fa | 1694 | else |
01241d47 PH |
1695 | yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); |
1696 | } | |
1697 | } | |
fb8135fa | 1698 | #endif |
01241d47 | 1699 | |
135bc829 PE |
1700 | static void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, |
1701 | yyGLRStack* yystack]b4_pure_formals[) | |
1702 | __attribute__ ((__noreturn__)); | |
01241d47 PH |
1703 | static void |
1704 | yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, | |
2a8d363a | 1705 | yyGLRStack* yystack]b4_pure_formals[) |
01241d47 | 1706 | { |
2a4647a3 PE |
1707 | YYUSE (yyx0); |
1708 | YYUSE (yyx1); | |
1154cced | 1709 | |
01241d47 | 1710 | #if YYDEBUG |
2f4f028d PE |
1711 | YYFPRINTF (stderr, "Ambiguity detected.\n"); |
1712 | YYFPRINTF (stderr, "Option 1,\n"); | |
01241d47 | 1713 | yyreportTree (yyx0, 2); |
2f4f028d | 1714 | YYFPRINTF (stderr, "\nOption 2,\n"); |
01241d47 | 1715 | yyreportTree (yyx1, 2); |
2f4f028d | 1716 | YYFPRINTF (stderr, "\n"); |
01241d47 | 1717 | #endif |
1a059451 | 1718 | yyFail (yystack][]b4_pure_args[, YY_("syntax is ambiguous")); |
01241d47 PH |
1719 | } |
1720 | ||
1721 | ||
1722 | /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated | |
1723 | * actions, and return the result. */ | |
1724 | static YYRESULTTAG | |
fb8135fa | 1725 | yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, |
2a8d363a | 1726 | YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) |
01241d47 PH |
1727 | { |
1728 | yySemanticOption* yybest; | |
f9315de5 | 1729 | yySemanticOption** yypp; |
63cb01d6 | 1730 | yybool yymerge; |
01241d47 | 1731 | |
fb8135fa | 1732 | yybest = yyoptionList; |
63cb01d6 | 1733 | yymerge = yyfalse; |
f9315de5 | 1734 | for (yypp = &yyoptionList->yynext; *yypp != NULL; ) |
01241d47 | 1735 | { |
f9315de5 PE |
1736 | yySemanticOption* yyp = *yypp; |
1737 | ||
01241d47 | 1738 | if (yyidenticalOptions (yybest, yyp)) |
f9315de5 PE |
1739 | { |
1740 | yymergeOptionSets (yybest, yyp); | |
1741 | *yypp = yyp->yynext; | |
1742 | } | |
01241d47 | 1743 | else |
f9315de5 PE |
1744 | { |
1745 | switch (yypreference (yybest, yyp)) | |
1746 | { | |
1747 | case 0: | |
1748 | yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[); | |
1749 | break; | |
1750 | case 1: | |
1751 | yymerge = yytrue; | |
1752 | break; | |
1753 | case 2: | |
1754 | break; | |
1755 | case 3: | |
1756 | yybest = yyp; | |
1757 | yymerge = yyfalse; | |
1758 | break; | |
ae199bf1 | 1759 | default: |
d1101454 | 1760 | /* This cannot happen so it is not worth a YYASSERT (yyfalse), |
69ce078b | 1761 | but some compilers complain if the default case is |
ae199bf1 PE |
1762 | omitted. */ |
1763 | break; | |
f9315de5 PE |
1764 | } |
1765 | yypp = &yyp->yynext; | |
1766 | } | |
01241d47 PH |
1767 | } |
1768 | ||
fb8135fa | 1769 | if (yymerge) |
01241d47 | 1770 | { |
f9315de5 | 1771 | yySemanticOption* yyp; |
01241d47 | 1772 | int yyprec = yydprec[yybest->yyrule]; |
2a8d363a | 1773 | YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[)); |
fb8135fa | 1774 | for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext) |
01241d47 | 1775 | { |
fb8135fa | 1776 | if (yyprec == yydprec[yyp->yyrule]) |
01241d47 PH |
1777 | { |
1778 | YYSTYPE yyval1; | |
1779 | YYLTYPE yydummy; | |
2a8d363a | 1780 | YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[)); |
7b98f503 | 1781 | yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1); |
01241d47 PH |
1782 | } |
1783 | } | |
1784 | return yyok; | |
1785 | } | |
1786 | else | |
2a8d363a | 1787 | return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[); |
01241d47 PH |
1788 | } |
1789 | ||
1790 | static YYRESULTTAG | |
2a8d363a | 1791 | yyresolveStack (yyGLRStack* yystack]b4_user_formals[) |
01241d47 | 1792 | { |
fb8135fa | 1793 | if (yystack->yysplitPoint != NULL) |
01241d47 PH |
1794 | { |
1795 | yyGLRState* yys; | |
1796 | int yyn; | |
1797 | ||
fb8135fa AD |
1798 | for (yyn = 0, yys = yystack->yytops.yystates[0]; |
1799 | yys != yystack->yysplitPoint; | |
01241d47 | 1800 | yys = yys->yypred, yyn += 1) |
ee16363f | 1801 | continue; |
e7cb57c0 | 1802 | YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack |
2a8d363a | 1803 | ]b4_user_args[)); |
01241d47 PH |
1804 | } |
1805 | return yyok; | |
1806 | } | |
1807 | ||
1808 | static void | |
fb8135fa | 1809 | yycompressStack (yyGLRStack* yystack) |
01241d47 PH |
1810 | { |
1811 | yyGLRState* yyp, *yyq, *yyr; | |
1812 | ||
1813 | if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL) | |
1814 | return; | |
1815 | ||
fb8135fa AD |
1816 | for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL; |
1817 | yyp != yystack->yysplitPoint; | |
01241d47 PH |
1818 | yyr = yyp, yyp = yyq, yyq = yyp->yypred) |
1819 | yyp->yypred = yyr; | |
fb8135fa | 1820 | |
01241d47 PH |
1821 | yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems; |
1822 | yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1; | |
1823 | yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems; | |
1824 | yystack->yysplitPoint = NULL; | |
1825 | yystack->yylastDeleted = NULL; | |
fb8135fa AD |
1826 | |
1827 | while (yyr != NULL) | |
1828 | { | |
01241d47 PH |
1829 | yystack->yynextFree->yystate = *yyr; |
1830 | yyr = yyr->yypred; | |
1831 | yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate; | |
1832 | yystack->yytops.yystates[0] = &yystack->yynextFree->yystate; | |
1833 | yystack->yynextFree += 1; | |
1834 | yystack->yyspaceLeft -= 1; | |
1835 | } | |
1836 | } | |
1837 | ||
1838 | static YYRESULTTAG | |
63cb01d6 | 1839 | yyprocessOneStack (yyGLRStack* yystack, size_t yyk, |
69ce078b | 1840 | size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp |
63cb01d6 | 1841 | ]b4_pure_formals[) |
01241d47 PH |
1842 | { |
1843 | int yyaction; | |
779e7ceb | 1844 | const short int* yyconflicts; |
01241d47 PH |
1845 | yyRuleNum yyrule; |
1846 | yySymbol* const yytokenp = yystack->yytokenp; | |
1847 | ||
fb8135fa | 1848 | while (yystack->yytops.yystates[yyk] != NULL) |
01241d47 PH |
1849 | { |
1850 | yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState; | |
63cb01d6 PE |
1851 | YYDPRINTF ((stderr, "Stack %lu Entering state %d\n", |
1852 | (unsigned long int) yyk, yystate)); | |
01241d47 | 1853 | |
64c4fd52 PE |
1854 | YYASSERT (yystate != YYFINAL); |
1855 | ||
fb8135fa | 1856 | if (yyisDefaultedState (yystate)) |
01241d47 PH |
1857 | { |
1858 | yyrule = yydefaultAction (yystate); | |
fb8135fa | 1859 | if (yyrule == 0) |
01241d47 | 1860 | { |
63cb01d6 PE |
1861 | YYDPRINTF ((stderr, "Stack %lu dies.\n", |
1862 | (unsigned long int) yyk)); | |
01241d47 PH |
1863 | yymarkStackDeleted (yystack, yyk); |
1864 | return yyok; | |
1865 | } | |
df9a1ba4 | 1866 | YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_user_args[)); |
01241d47 | 1867 | } |
fb8135fa | 1868 | else |
01241d47 | 1869 | { |
fb8135fa | 1870 | if (*yytokenp == YYEMPTY) |
01241d47 | 1871 | { |
2f4f028d | 1872 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 | 1873 | yychar = YYLEX; |
b0400cc6 | 1874 | *yytokenp = YYTRANSLATE (yychar); |
284acc8b | 1875 | YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp); |
01241d47 PH |
1876 | } |
1877 | yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts); | |
1878 | ||
fb8135fa | 1879 | while (*yyconflicts != 0) |
01241d47 | 1880 | { |
df9a1ba4 | 1881 | size_t yynewStack = yysplitStack (yystack, yyk); |
63cb01d6 PE |
1882 | YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n", |
1883 | (unsigned long int) yynewStack, | |
1884 | (unsigned long int) yyk)); | |
e7cb57c0 | 1885 | YYCHK (yyglrReduce (yystack, yynewStack, |
df9a1ba4 | 1886 | *yyconflicts, yyfalse]b4_user_args[)); |
fb8135fa | 1887 | YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn, |
63cb01d6 | 1888 | yylvalp, yyllocp]b4_pure_args[)); |
01241d47 PH |
1889 | yyconflicts += 1; |
1890 | } | |
fb8135fa AD |
1891 | |
1892 | if (yyisShiftAction (yyaction)) | |
69ce078b | 1893 | break; |
fb8135fa | 1894 | else if (yyisErrorAction (yyaction)) |
01241d47 | 1895 | { |
63cb01d6 PE |
1896 | YYDPRINTF ((stderr, "Stack %lu dies.\n", |
1897 | (unsigned long int) yyk)); | |
01241d47 PH |
1898 | yymarkStackDeleted (yystack, yyk); |
1899 | break; | |
1900 | } | |
1901 | else | |
df9a1ba4 | 1902 | YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_user_args[)); |
01241d47 PH |
1903 | } |
1904 | } | |
1905 | return yyok; | |
1906 | } | |
1907 | ||
1908 | static void | |
ee16363f PE |
1909 | yyreportSyntaxError (yyGLRStack* yystack, |
1910 | YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) | |
01241d47 | 1911 | { |
2a4647a3 PE |
1912 | YYUSE (yylvalp); |
1913 | YYUSE (yyllocp); | |
01241d47 PH |
1914 | |
1915 | if (yystack->yyerrState == 0) | |
1916 | { | |
fb8135fa | 1917 | #if YYERROR_VERBOSE |
1154cced | 1918 | yySymbol* const yytokenp = yystack->yytokenp; |
93a0df69 | 1919 | int yyn; |
01241d47 | 1920 | yyn = yypact[yystack->yytops.yystates[0]->yylrState]; |
12b0043a | 1921 | if (YYPACT_NINF < yyn && yyn < YYLAST) |
01241d47 | 1922 | { |
9e0876fb | 1923 | size_t yysize0 = yytnamerr (NULL, yytokenName (*yytokenp)); |
63cb01d6 PE |
1924 | size_t yysize = yysize0; |
1925 | size_t yysize1; | |
1926 | yybool yysize_overflow = yyfalse; | |
1927 | char* yymsg = NULL; | |
1928 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; | |
1929 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; | |
93a0df69 | 1930 | int yyx; |
63cb01d6 PE |
1931 | char *yyfmt; |
1932 | char const *yyf; | |
1933 | static char const yyunexpected[] = "syntax error, unexpected %s"; | |
1934 | static char const yyexpecting[] = ", expecting %s"; | |
1935 | static char const yyor[] = " or %s"; | |
1936 | char yyformat[sizeof yyunexpected | |
1937 | + sizeof yyexpecting - 1 | |
1938 | + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) | |
1939 | * (sizeof yyor - 1))]; | |
1940 | char const *yyprefix = yyexpecting; | |
93a0df69 | 1941 | |
01241d47 PH |
1942 | /* Start YYX at -YYN if negative to avoid negative indexes in |
1943 | YYCHECK. */ | |
c4749565 | 1944 | int yyxbegin = yyn < 0 ? -yyn : 0; |
93a0df69 PE |
1945 | |
1946 | /* Stay within bounds of both yycheck and yytname. */ | |
1947 | int yychecklim = YYLAST - yyn; | |
c4749565 | 1948 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; |
63cb01d6 PE |
1949 | int yycount = 1; |
1950 | ||
1951 | yyarg[0] = yytokenName (*yytokenp); | |
1952 | yyfmt = yystpcpy (yyformat, yyunexpected); | |
93a0df69 | 1953 | |
c4749565 | 1954 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
217598da | 1955 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
93a0df69 | 1956 | { |
63cb01d6 | 1957 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) |
01241d47 | 1958 | { |
63cb01d6 PE |
1959 | yycount = 1; |
1960 | yysize = yysize0; | |
1961 | yyformat[sizeof yyunexpected - 1] = '\0'; | |
93a0df69 | 1962 | break; |
01241d47 | 1963 | } |
63cb01d6 | 1964 | yyarg[yycount++] = yytokenName (yyx); |
9e0876fb | 1965 | yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx)); |
63cb01d6 PE |
1966 | yysize_overflow |= yysize1 < yysize; |
1967 | yysize = yysize1; | |
1968 | yyfmt = yystpcpy (yyfmt, yyprefix); | |
1969 | yyprefix = yyor; | |
93a0df69 | 1970 | } |
63cb01d6 | 1971 | |
30757c8c PE |
1972 | yyf = YY_(yyformat); |
1973 | yysize1 = yysize + strlen (yyf); | |
63cb01d6 PE |
1974 | yysize_overflow |= yysize1 < yysize; |
1975 | yysize = yysize1; | |
1976 | ||
1977 | if (!yysize_overflow) | |
1978 | yymsg = (char *) YYMALLOC (yysize); | |
1979 | ||
1980 | if (yymsg) | |
93a0df69 | 1981 | { |
63cb01d6 PE |
1982 | char *yyp = yymsg; |
1983 | int yyi = 0; | |
1984 | while ((*yyp = *yyf)) | |
93a0df69 | 1985 | { |
63cb01d6 PE |
1986 | if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) |
1987 | { | |
9e0876fb | 1988 | yyp += yytnamerr (yyp, yyarg[yyi++]); |
63cb01d6 PE |
1989 | yyf += 2; |
1990 | } | |
1991 | else | |
1992 | { | |
1993 | yyp++; | |
1994 | yyf++; | |
1995 | } | |
93a0df69 PE |
1996 | } |
1997 | yyerror (]b4_lyyerror_args[yymsg); | |
a525b568 | 1998 | YYFREE (yymsg); |
01241d47 | 1999 | } |
93a0df69 | 2000 | else |
1a059451 PE |
2001 | { |
2002 | yyerror (]b4_lyyerror_args[YY_("syntax error")); | |
2003 | yyMemoryExhausted (yystack); | |
2004 | } | |
01241d47 PH |
2005 | } |
2006 | else | |
93a0df69 | 2007 | #endif /* YYERROR_VERBOSE */ |
30757c8c | 2008 | yyerror (]b4_lyyerror_args[YY_("syntax error")); |
01241d47 PH |
2009 | yynerrs += 1; |
2010 | } | |
2011 | } | |
2012 | ||
f50adbbd | 2013 | /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP, |
01241d47 | 2014 | YYLVALP, and YYLLOCP point to the syntactic category, semantic |
8dd162d3 | 2015 | value, and location of the look-ahead. */ |
12ce2df6 | 2016 | /*ARGSUSED*/ static void |
ee16363f | 2017 | yyrecoverSyntaxError (yyGLRStack* yystack, |
80a18357 | 2018 | YYSTYPE* yylvalp, |
43d3b664 | 2019 | YYLTYPE* YYOPTIONAL_LOC (yyllocp) |
80a18357 | 2020 | ]b4_user_formals[) |
01241d47 PH |
2021 | { |
2022 | yySymbol* const yytokenp = yystack->yytokenp; | |
1154cced AD |
2023 | size_t yyk; |
2024 | int yyj; | |
01241d47 | 2025 | |
25005f6a | 2026 | if (yystack->yyerrState == 3) |
2a1fe6ed AD |
2027 | /* We just shifted the error token and (perhaps) took some |
2028 | reductions. Skip tokens until we can proceed. */ | |
2029 | while (yytrue) | |
2030 | { | |
01241d47 | 2031 | if (*yytokenp == YYEOF) |
258b75ca | 2032 | yyFail (yystack][]b4_lpure_args[, NULL); |
01241d47 | 2033 | if (*yytokenp != YYEMPTY) |
e342c3be AD |
2034 | {]b4_location_if([[ |
2035 | /* We throw away the lookahead, but the error range | |
2036 | of the shifted error token must take it into account. */ | |
2037 | yyGLRState *yys = yystack->yytops.yystates[0]; | |
63d72da7 PE |
2038 | yyGLRStackItem yyerror_range[3]; |
2039 | yyerror_range[1].yystate.yyloc = yys->yyloc; | |
2040 | yyerror_range[2].yystate.yyloc = *yyllocp; | |
2041 | YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[ | |
e342c3be | 2042 | yydestruct ("Error: discarding", |
4b367315 | 2043 | *yytokenp, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); |
e342c3be | 2044 | } |
2f4f028d | 2045 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 PH |
2046 | yychar = YYLEX; |
2047 | *yytokenp = YYTRANSLATE (yychar); | |
284acc8b | 2048 | YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp); |
01241d47 | 2049 | yyj = yypact[yystack->yytops.yystates[0]->yylrState]; |
944ed9f4 | 2050 | if (yyis_pact_ninf (yyj)) |
25005f6a | 2051 | return; |
01241d47 | 2052 | yyj += *yytokenp; |
ea99527d | 2053 | if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp) |
01241d47 PH |
2054 | { |
2055 | if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0) | |
2056 | return; | |
2057 | } | |
944ed9f4 | 2058 | else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj])) |
01241d47 | 2059 | return; |
2a1fe6ed | 2060 | } |
fb8135fa | 2061 | |
2a1fe6ed | 2062 | /* Reduce to one stack. */ |
01241d47 PH |
2063 | for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1) |
2064 | if (yystack->yytops.yystates[yyk] != NULL) | |
2065 | break; | |
2066 | if (yyk >= yystack->yytops.yysize) | |
2a8d363a | 2067 | yyFail (yystack][]b4_lpure_args[, NULL); |
01241d47 PH |
2068 | for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1) |
2069 | yymarkStackDeleted (yystack, yyk); | |
2070 | yyremoveDeletes (yystack); | |
2071 | yycompressStack (yystack); | |
2072 | ||
2073 | /* Now pop stack until we find a state that shifts the error token. */ | |
25005f6a | 2074 | yystack->yyerrState = 3; |
fb8135fa | 2075 | while (yystack->yytops.yystates[0] != NULL) |
01241d47 | 2076 | { |
7bd6c77e AD |
2077 | yyGLRState *yys = yystack->yytops.yystates[0]; |
2078 | yyj = yypact[yys->yylrState]; | |
944ed9f4 | 2079 | if (! yyis_pact_ninf (yyj)) |
01241d47 | 2080 | { |
944ed9f4 PE |
2081 | yyj += YYTERROR; |
2082 | if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR | |
2083 | && yyisShiftAction (yytable[yyj])) | |
2084 | { | |
e342c3be AD |
2085 | /* Shift the error token having adjusted its location. */ |
2086 | YYLTYPE yyerrloc;]b4_location_if([[ | |
63d72da7 PE |
2087 | yystack->yyerror_range[2].yystate.yyloc = *yyllocp; |
2088 | YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[ | |
1576d44d | 2089 | YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]], |
e342c3be | 2090 | yylvalp, &yyerrloc); |
944ed9f4 | 2091 | yyglrShift (yystack, 0, yytable[yyj], |
df9a1ba4 | 2092 | yys->yyposn, *yylvalp, &yyerrloc); |
e342c3be | 2093 | yys = yystack->yytops.yystates[0]; |
944ed9f4 PE |
2094 | break; |
2095 | } | |
01241d47 | 2096 | } |
63d72da7 | 2097 | ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ |
4b367315 | 2098 | yydestroyGLRState ("Error: popping", yys]b4_user_args[); |
7bd6c77e | 2099 | yystack->yytops.yystates[0] = yys->yypred; |
01241d47 PH |
2100 | yystack->yynextFree -= 1; |
2101 | yystack->yyspaceLeft += 1; | |
2102 | } | |
2103 | if (yystack->yytops.yystates[0] == NULL) | |
2a8d363a | 2104 | yyFail (yystack][]b4_lpure_args[, NULL); |
fb8135fa AD |
2105 | } |
2106 | ||
01241d47 PH |
2107 | #define YYCHK1(YYE) \ |
2108 | do { \ | |
2109 | switch (YYE) { \ | |
127287e9 | 2110 | case yyok: \ |
01241d47 PH |
2111 | break; \ |
2112 | case yyabort: \ | |
6100a9aa | 2113 | goto yyabortlab; \ |
01241d47 | 2114 | case yyaccept: \ |
6100a9aa | 2115 | goto yyacceptlab; \ |
01241d47 PH |
2116 | case yyerr: \ |
2117 | goto yyuser_error; \ | |
127287e9 PE |
2118 | default: \ |
2119 | goto yybuglab; \ | |
01241d47 | 2120 | } \ |
12ce2df6 | 2121 | } while (YYID (0)) |
01241d47 | 2122 | |
0245f82d AD |
2123 | |
2124 | /*----------. | |
2125 | | yyparse. | | |
2126 | `----------*/ | |
2127 | ||
2128 | ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[ | |
01241d47 | 2129 | { |
6100a9aa | 2130 | int yyresult; |
fd2df2ed | 2131 | yySymbol yytoken; |
01241d47 PH |
2132 | yyGLRStack yystack; |
2133 | size_t yyposn; | |
2134 | ]b4_pure_if( | |
2135 | [ | |
2136 | YYSTYPE yylval; | |
2137 | YYLTYPE yylloc; | |
2138 | #undef yychar | |
2139 | #define yychar (yystack.yyrawchar) | |
2140 | ])[ | |
2141 | ||
2142 | YYSTYPE* const yylvalp = &yylval; | |
2143 | YYLTYPE* const yyllocp = &yylloc; | |
fb8135fa | 2144 | |
2f4f028d | 2145 | YYDPRINTF ((stderr, "Starting parse\n")); |
2a1fe6ed | 2146 | |
fd2df2ed | 2147 | yytoken = YYEMPTY; |
b8458aa5 AD |
2148 | yylval = yyval_default; |
2149 | ]b4_location_if([ | |
2150 | #if YYLTYPE_IS_TRIVIAL | |
2151 | yylloc.first_line = yylloc.last_line = 1; | |
2152 | yylloc.first_column = yylloc.last_column = 0; | |
2153 | #endif | |
2154 | ]) | |
2155 | m4_ifdef([b4_initial_action], [ | |
1c02d4bf AD |
2156 | m4_pushdef([b4_at_dollar], [yylloc])dnl |
2157 | m4_pushdef([b4_dollar_dollar], [yylval])dnl | |
b8458aa5 AD |
2158 | /* User initialization code. */ |
2159 | b4_initial_action | |
2160 | m4_popdef([b4_dollar_dollar])dnl | |
2161 | m4_popdef([b4_at_dollar])dnl | |
2162 | /* Line __line__ of glr.c. */ | |
2163 | b4_syncline([@oline@], [@ofile@])])dnl | |
2164 | [ | |
15f40952 | 2165 | if (! yyinitGLRStack (&yystack, YYINITDEPTH)) |
1a059451 | 2166 | goto yyexhaustedlab; |
c89b4c03 | 2167 | switch (YYSETJMP (yystack.yyexception_buffer)) |
6100a9aa | 2168 | { |
c89b4c03 | 2169 | case 0: break; |
6100a9aa | 2170 | case 1: goto yyabortlab; |
1a059451 | 2171 | case 2: goto yyexhaustedlab; |
c89b4c03 | 2172 | default: goto yybuglab; |
6100a9aa | 2173 | } |
15f40952 | 2174 | yystack.yytokenp = &yytoken; |
df9a1ba4 | 2175 | yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc); |
01241d47 PH |
2176 | yyposn = 0; |
2177 | ||
fb8135fa | 2178 | while (yytrue) |
01241d47 | 2179 | { |
21964f43 AD |
2180 | /* For efficiency, we have two loops, the first of which is |
2181 | specialized to deterministic operation (single stack, no | |
2182 | potential ambiguity). */ | |
01241d47 | 2183 | /* Standard mode */ |
fb8135fa | 2184 | while (yytrue) |
01241d47 PH |
2185 | { |
2186 | yyRuleNum yyrule; | |
2187 | int yyaction; | |
779e7ceb | 2188 | const short int* yyconflicts; |
01241d47 PH |
2189 | |
2190 | yyStateNum yystate = yystack.yytops.yystates[0]->yylrState; | |
69ce078b | 2191 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
01241d47 | 2192 | if (yystate == YYFINAL) |
6100a9aa | 2193 | goto yyacceptlab; |
fb8135fa | 2194 | if (yyisDefaultedState (yystate)) |
01241d47 PH |
2195 | { |
2196 | yyrule = yydefaultAction (yystate); | |
fb8135fa | 2197 | if (yyrule == 0) |
01241d47 | 2198 | { |
63d72da7 | 2199 | ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[ |
ee16363f | 2200 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
2201 | goto yyuser_error; |
2202 | } | |
df9a1ba4 | 2203 | YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[)); |
01241d47 | 2204 | } |
fb8135fa | 2205 | else |
01241d47 | 2206 | { |
fb8135fa | 2207 | if (yytoken == YYEMPTY) |
01241d47 | 2208 | { |
2f4f028d | 2209 | YYDPRINTF ((stderr, "Reading a token: ")); |
01241d47 PH |
2210 | yychar = YYLEX; |
2211 | yytoken = YYTRANSLATE (yychar); | |
69ce078b | 2212 | YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp); |
01241d47 PH |
2213 | } |
2214 | yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); | |
2215 | if (*yyconflicts != 0) | |
2216 | break; | |
fb8135fa | 2217 | if (yyisShiftAction (yyaction)) |
01241d47 | 2218 | { |
1576d44d | 2219 | YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp); |
01241d47 PH |
2220 | if (yytoken != YYEOF) |
2221 | yytoken = YYEMPTY; | |
2222 | yyposn += 1; | |
df9a1ba4 | 2223 | yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp); |
39912f52 | 2224 | if (0 < yystack.yyerrState) |
01241d47 | 2225 | yystack.yyerrState -= 1; |
01241d47 PH |
2226 | } |
2227 | else if (yyisErrorAction (yyaction)) | |
2228 | { | |
63d72da7 | 2229 | ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[ |
ee16363f | 2230 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
2231 | goto yyuser_error; |
2232 | } | |
2233 | else | |
df9a1ba4 | 2234 | YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[)); |
01241d47 PH |
2235 | } |
2236 | } | |
2237 | ||
fb8135fa | 2238 | while (yytrue) |
01241d47 | 2239 | { |
69ce078b | 2240 | yySymbol yytoken_to_shift; |
63cb01d6 PE |
2241 | size_t yys; |
2242 | size_t yyn = yystack.yytops.yysize; | |
69ce078b PE |
2243 | |
2244 | /* yyprocessOneStack returns one of three things: | |
2245 | ||
2246 | - An error flag. If the caller is yyprocessOneStack, it | |
2247 | immediately returns as well. When the caller is finally | |
2248 | yyparse, it jumps to an error label via YYCHK1. | |
2249 | ||
2250 | - yyok, but yyprocessOneStack has invoked yymarkStackDeleted | |
2251 | (&yystack, yys), which sets the top state of yys to NULL. Thus, | |
2252 | yyparse's following invocation of yyremoveDeletes will remove | |
2253 | the stack. | |
2254 | ||
2255 | - yyok, when ready to shift a token. | |
2256 | ||
2257 | Except in the first case, yyparse will invoke yyremoveDeletes and | |
2258 | then shift the next token onto all remaining stacks. This | |
2259 | synchronization of the shift (that is, after all preceding | |
2260 | reductions on all stacks) helps prevents double destructor calls | |
2261 | on yylval in the event of memory exhaustion. */ | |
2262 | ||
01241d47 PH |
2263 | for (yys = 0; yys < yyn; yys += 1) |
2264 | YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, | |
63cb01d6 | 2265 | yylvalp, yyllocp]b4_lpure_args[)); |
69ce078b PE |
2266 | yyremoveDeletes (&yystack); |
2267 | yyn = yystack.yytops.yysize; | |
2268 | ||
2269 | /* If any yyglrShift call fails, it will fail after shifting. Thus, | |
2270 | a copy of yylval will already be on stack 0 in the event of a | |
2271 | failure in the following loop. Thus, yytoken is set to YYEMPTY | |
2272 | before the loop to make sure the user destructor for yylval isn't | |
2273 | called twice. */ | |
2274 | yytoken_to_shift = yytoken; | |
01241d47 PH |
2275 | yytoken = YYEMPTY; |
2276 | yyposn += 1; | |
69ce078b PE |
2277 | for (yys = 0; yys < yyn; yys += 1) |
2278 | { | |
2279 | int yyaction; | |
2280 | const short int* yyconflicts; | |
2281 | yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState; | |
2282 | yygetLRActions (yystate, yytoken_to_shift, &yyaction, | |
2283 | &yyconflicts); | |
2284 | /* Note that yyconflicts were handled by yyprocessOneStack. */ | |
2285 | YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys)); | |
2286 | YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, yylvalp, yyllocp); | |
2287 | yyglrShift (&yystack, yys, yyaction, yyposn, | |
2288 | *yylvalp, yyllocp); | |
2289 | YYDPRINTF ((stderr, "Stack %lu now in state #%d\n", | |
2290 | (unsigned long int) yys, | |
2291 | yystack.yytops.yystates[yys]->yylrState)); | |
2292 | } | |
01241d47 PH |
2293 | if (yystack.yytops.yysize == 0) |
2294 | { | |
2295 | yyundeleteLastStack (&yystack); | |
2296 | if (yystack.yytops.yysize == 0) | |
30757c8c | 2297 | yyFail (&yystack][]b4_lpure_args[, YY_("syntax error")); |
2a8d363a | 2298 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); |
2f4f028d | 2299 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); |
63d72da7 | 2300 | ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[ |
ee16363f | 2301 | yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
2302 | goto yyuser_error; |
2303 | } | |
fb8135fa | 2304 | else if (yystack.yytops.yysize == 1) |
01241d47 | 2305 | { |
2a8d363a | 2306 | YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); |
2f4f028d | 2307 | YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); |
01241d47 PH |
2308 | yycompressStack (&yystack); |
2309 | break; | |
2310 | } | |
2311 | } | |
2312 | continue; | |
2313 | yyuser_error: | |
ee16363f | 2314 | yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); |
01241d47 PH |
2315 | yyposn = yystack.yytops.yystates[0]->yyposn; |
2316 | } | |
6100a9aa PE |
2317 | |
2318 | yyacceptlab: | |
2319 | yyresult = 0; | |
2320 | goto yyreturn; | |
2321 | ||
127287e9 PE |
2322 | yybuglab: |
2323 | YYASSERT (yyfalse); | |
2324 | /* Fall through. */ | |
2325 | ||
6100a9aa PE |
2326 | yyabortlab: |
2327 | yyresult = 1; | |
2328 | goto yyreturn; | |
2329 | ||
1a059451 PE |
2330 | yyexhaustedlab: |
2331 | yyerror (]b4_lyyerror_args[YY_("memory exhausted")); | |
6100a9aa PE |
2332 | yyresult = 2; |
2333 | /* Fall through. */ | |
2334 | ||
2335 | yyreturn: | |
2336 | if (yytoken != YYEOF && yytoken != YYEMPTY) | |
dd5f2af2 | 2337 | yydestruct ("Cleanup: discarding lookahead", |
69ce078b | 2338 | yytoken, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); |
01241d47 | 2339 | |
3922956a PE |
2340 | /* If the stack is well-formed, pop the stack until it is empty, |
2341 | destroying its entries as we go. But free the stack regardless | |
2342 | of whether it is well-formed. */ | |
2343 | if (yystack.yyitems) | |
2344 | { | |
2345 | yyGLRState** yystates = yystack.yytops.yystates; | |
2346 | if (yystates) | |
69ce078b PE |
2347 | { |
2348 | size_t yysize = yystack.yytops.yysize; | |
2349 | size_t yyk; | |
2350 | for (yyk = 0; yyk < yysize; yyk += 1) | |
2351 | if (yystates[yyk]) | |
2352 | { | |
2353 | while (yystates[yyk]) | |
2354 | { | |
2355 | yyGLRState *yys = yystates[yyk]; | |
2356 | ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] | |
2357 | )[ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); | |
2358 | yystates[yyk] = yys->yypred; | |
2359 | yystack.yynextFree -= 1; | |
2360 | yystack.yyspaceLeft += 1; | |
2361 | } | |
2362 | break; | |
2363 | } | |
2364 | } | |
3922956a PE |
2365 | yyfreeGLRStack (&yystack); |
2366 | } | |
258b75ca | 2367 | |
6100a9aa | 2368 | return yyresult; |
01241d47 PH |
2369 | } |
2370 | ||
2371 | /* DEBUGGING ONLY */ | |
417141dd | 2372 | #ifdef YYDEBUG |
135bc829 PE |
2373 | static void yypstack (yyGLRStack* yystack, size_t yyk) |
2374 | __attribute__ ((__unused__)); | |
2375 | static void yypdumpstack (yyGLRStack* yystack) __attribute__ ((__unused__)); | |
01241d47 | 2376 | |
1154cced | 2377 | static void |
cf126971 | 2378 | yy_yypstack (yyGLRState* yys) |
01241d47 | 2379 | { |
cf126971 | 2380 | if (yys->yypred) |
01241d47 | 2381 | { |
cf126971 | 2382 | yy_yypstack (yys->yypred); |
2f4f028d | 2383 | fprintf (stderr, " -> "); |
01241d47 | 2384 | } |
779e7ceb | 2385 | fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn); |
cf126971 | 2386 | } |
01241d47 | 2387 | |
cf126971 PE |
2388 | static void |
2389 | yypstates (yyGLRState* yyst) | |
2390 | { | |
fb8135fa | 2391 | if (yyst == NULL) |
2f4f028d | 2392 | fprintf (stderr, "<null>"); |
fb8135fa | 2393 | else |
01241d47 | 2394 | yy_yypstack (yyst); |
2f4f028d | 2395 | fprintf (stderr, "\n"); |
01241d47 PH |
2396 | } |
2397 | ||
1154cced | 2398 | static void |
63cb01d6 | 2399 | yypstack (yyGLRStack* yystack, size_t yyk) |
01241d47 PH |
2400 | { |
2401 | yypstates (yystack->yytops.yystates[yyk]); | |
2402 | } | |
2403 | ||
5cc16ecc | 2404 | #define YYINDEX(YYX) \ |
01241d47 PH |
2405 | ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems) |
2406 | ||
2407 | ||
1154cced | 2408 | static void |
fb8135fa | 2409 | yypdumpstack (yyGLRStack* yystack) |
01241d47 PH |
2410 | { |
2411 | yyGLRStackItem* yyp; | |
1154cced | 2412 | size_t yyi; |
fb8135fa | 2413 | for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1) |
01241d47 | 2414 | { |
779e7ceb | 2415 | fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystack->yyitems)); |
f7c398aa | 2416 | if (*(yybool *) yyp) |
01241d47 | 2417 | { |
cf126971 | 2418 | fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", |
fb8135fa | 2419 | yyp->yystate.yyresolved, yyp->yystate.yylrState, |
779e7ceb PE |
2420 | (unsigned long int) yyp->yystate.yyposn, |
2421 | (long int) YYINDEX (yyp->yystate.yypred)); | |
fb8135fa | 2422 | if (! yyp->yystate.yyresolved) |
cf126971 | 2423 | fprintf (stderr, ", firstVal: %ld", |
779e7ceb | 2424 | (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal)); |
01241d47 | 2425 | } |
fb8135fa | 2426 | else |
01241d47 | 2427 | { |
cf126971 PE |
2428 | fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld", |
2429 | yyp->yyoption.yyrule, | |
779e7ceb PE |
2430 | (long int) YYINDEX (yyp->yyoption.yystate), |
2431 | (long int) YYINDEX (yyp->yyoption.yynext)); | |
01241d47 | 2432 | } |
2f4f028d | 2433 | fprintf (stderr, "\n"); |
01241d47 | 2434 | } |
2f4f028d | 2435 | fprintf (stderr, "Tops:"); |
01241d47 | 2436 | for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1) |
779e7ceb PE |
2437 | fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi, |
2438 | (long int) YYINDEX (yystack->yytops.yystates[yyi])); | |
2f4f028d | 2439 | fprintf (stderr, "\n"); |
01241d47 | 2440 | } |
417141dd | 2441 | #endif |
01241d47 PH |
2442 | ] |
2443 | ||
2444 | b4_epilogue | |
2445 | m4_if(b4_defines_flag, 0, [], | |
947427ae | 2446 | [@output @output_header_name@ |
010f91c3 | 2447 | b4_copyright([Skeleton parser for GLR parsing with Bison], |
69ce078b | 2448 | [2002, 2003, 2004, 2005])[ |
af3412cd PE |
2449 | |
2450 | /* As a special exception, when this parser skeleton is copied by | |
2451 | Bison into a Bison output file, you may use that output file | |
2452 | without restriction. This special exception was added by the Free | |
2453 | Software Foundation for C GLR parsers in version 2.2 of Bison. */ | |
2454 | ||
2455 | /* C GLR parser skeleton written by Paul Hilfinger. */ | |
2456 | ] | |
01241d47 | 2457 | |
5059b5c8 | 2458 | b4_shared_declarations |
01241d47 | 2459 | |
5059b5c8 | 2460 | extern YYSTYPE b4_prefix[]lval; |
01241d47 | 2461 | |
e342c3be | 2462 | b4_location_if([b4_pure_if([], |
01241d47 PH |
2463 | [extern YYLTYPE b4_prefix[]lloc;]) |
2464 | ]) | |
01241d47 | 2465 | ]) |