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