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