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