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