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