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