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