]> git.saurik.com Git - bison.git/blame - data/lalr1.java
api.prefix: incompatible with %name-prefix.
[bison.git] / data / lalr1.java
CommitLineData
8405b70c
PB
1# Java skeleton for Bison -*- autoconf -*-
2
c932d613 3# Copyright (C) 2007-2012 Free Software Foundation, Inc.
8405b70c 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
8405b70c 6# it under the terms of the GNU General Public License as published by
f16b0819 7# the Free Software Foundation, either version 3 of the License, or
8405b70c 8# (at your option) any later version.
f16b0819 9#
8405b70c
PB
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
f16b0819 14#
8405b70c 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
8405b70c
PB
17
18m4_include(b4_pkgdatadir/[java.m4])
19
20b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java], [b4_skeleton])])
21m4_ifval(m4_defn([b4_symbol_destructors]),
22 [b4_fatal([%s: %%destructor does not make sense in Java], [b4_skeleton])],
23 [])
24
25m4_divert_push(0)dnl
0d2b2ab0 26@output(b4_parser_file_name@)@
8405b70c 27b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
681dda24 28 [2007-2012])
8405b70c
PB
29
30b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
31])[/* First part of user declarations. */
32]b4_pre_prologue
33b4_percent_code_get([[imports]])
34[/**
74d6c0fe 35 * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
8405b70c
PB
36 *
37 * @@author LALR (1) parser skeleton written by Paolo Bonzini.
38 */
e254a580
DJ
39]b4_public_if([public ])dnl
40b4_abstract_if([abstract ])dnl
41b4_final_if([final ])dnl
42b4_strictfp_if([strictfp ])dnl
43[class ]b4_parser_class_name[]dnl
44b4_percent_define_get3([extends], [ extends ])dnl
45b4_percent_define_get3([implements], [ implements ])[
8405b70c
PB
46{
47 ]b4_identification[
48
49 /** True if verbose error messages are enabled. */
50 public boolean errorVerbose = ]b4_flag_value([error_verbose]);
51
52b4_locations_if([[
53 /**
54 * A class defining a pair of positions. Positions, defined by the
55 * <code>]b4_position_type[</code> class, denote a point in the input.
56 * Locations represent a part of the input through the beginning
57 * and ending positions. */
58 public class ]b4_location_type[ {
59 /** The first, inclusive, position in the range. */
60 public ]b4_position_type[ begin;
61
62 /** The first position beyond the range. */
63 public ]b4_position_type[ end;
64
65 /**
e254a580 66 * Create a <code>]b4_location_type[</code> denoting an empty range located at
8405b70c
PB
67 * a given point.
68 * @@param loc The position at which the range is anchored. */
69 public ]b4_location_type[ (]b4_position_type[ loc) {
70 this.begin = this.end = loc;
71 }
72
73 /**
74 * Create a <code>]b4_location_type[</code> from the endpoints of the range.
75 * @@param begin The first position included in the range.
74d6c0fe 76 * @@param end The first position beyond the range. */
8405b70c
PB
77 public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) {
78 this.begin = begin;
79 this.end = end;
80 }
81
82 /**
83 * Print a representation of the location. For this to be correct,
84 * <code>]b4_position_type[</code> should override the <code>equals</code>
85 * method. */
86 public String toString () {
87 if (begin.equals (end))
88 return begin.toString ();
89 else
90 return begin.toString () + "-" + end.toString ();
91 }
92 }
93
94]])
95
96[ /** Token returned by the scanner to signal the end of its input. */
97 public static final int EOF = 0;]
98
99b4_token_enums(b4_tokens)
100
101 b4_locations_if([[
d3b12988 102 private ]b4_location_type[ yylloc (YYStack rhs, int n)
8405b70c
PB
103 {
104 if (n > 0)
8db68289 105 return new ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end);
8405b70c
PB
106 else
107 return new ]b4_location_type[ (rhs.locationAt (0).end);
74d6c0fe 108 }]])[
8405b70c 109
01b477c6 110 /**
8405b70c
PB
111 * Communication interface between the scanner and the Bison-generated
112 * parser <tt>]b4_parser_class_name[</tt>.
113 */
114 public interface Lexer {
115 ]b4_locations_if([[/**
116 * Method to retrieve the beginning position of the last scanned token.
117 * @@return the position at which the last scanned token starts. */
118 ]b4_position_type[ getStartPos ();
119
120 /**
121 * Method to retrieve the ending position of the last scanned token.
122 * @@return the first position beyond the last scanned token. */
123 ]b4_position_type[ getEndPos ();]])[
124
125 /**
126 * Method to retrieve the semantic value of the last scanned token.
127 * @@return the semantic value of the last scanned token. */
d0ee4105 128 ]b4_yystype[ getLVal ();
8405b70c
PB
129
130 /**
8405b70c 131 * Entry point for the scanner. Returns the token identifier corresponding
d0ee4105 132 * to the next token and prepares to return the semantic value
0d2b2ab0 133 * ]b4_locations_if([and beginning/ending positions ])[of the token.
8405b70c 134 * @@return the token identifier corresponding to the next token. */
01b477c6 135 int yylex () ]b4_maybe_throws([b4_lex_throws])[;
8405b70c
PB
136
137 /**
138 * Entry point for error reporting. Emits an error
e254a580 139 * ]b4_locations_if([referring to the given location ])[in a user-defined way.
8405b70c 140 *
74d6c0fe 141 * ]b4_locations_if([[@@param loc The location of the element to which the
8405b70c
PB
142 * error message is related]])[
143 * @@param s The string for the error message. */
01b477c6
PB
144 void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String s);]
145 }
146
147 b4_lexer_if([[private class YYLexer implements Lexer {
148]b4_percent_code_get([[lexer]])[
149 }
8405b70c 150
01b477c6
PB
151 ]])[/** The object doing lexical analysis for us. */
152 private Lexer yylexer;
153 ]
154 b4_parse_param_vars
8405b70c 155
01b477c6 156b4_lexer_if([[
8405b70c 157 /**
01b477c6 158 * Instantiates the Bison-generated parser.
8405b70c 159 */
01b477c6
PB
160 public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) {
161 this.yylexer = new YYLexer(]b4_lex_param_call[);
162 ]b4_parse_param_cons[
163 }
164]])
165
166 /**
167 * Instantiates the Bison-generated parser.
74d6c0fe 168 * @@param yylexer The scanner that will supply tokens to the parser.
01b477c6
PB
169 */
170 b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ (]b4_parse_param_decl([[Lexer yylexer]])[) {
171 this.yylexer = yylexer;
172 ]b4_parse_param_cons[
8405b70c
PB
173 }
174
d3b12988 175 private java.io.PrintStream yyDebugStream = System.err;
8405b70c
PB
176
177 /**
178 * Return the <tt>PrintStream</tt> on which the debugging output is
179 * printed.
180 */
d3b12988 181 public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
8405b70c
PB
182
183 /**
184 * Set the <tt>PrintStream</tt> on which the debug output is printed.
185 * @@param s The stream that is used for debugging output.
186 */
d3b12988 187 public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; }
8405b70c
PB
188
189 private int yydebug = 0;
190
191 /**
192 * Answer the verbosity of the debugging output; 0 means that all kinds of
193 * output from the parser are suppressed.
194 */
195 public final int getDebugLevel() { return yydebug; }
196
197 /**
198 * Set the verbosity of the debugging output; 0 means that all kinds of
199 * output from the parser are suppressed.
200 * @@param level The verbosity level for debugging output.
201 */
202 public final void setDebugLevel(int level) { yydebug = level; }
203
01b477c6
PB
204 private final int yylex () ]b4_maybe_throws([b4_lex_throws]) [{
205 return yylexer.yylex ();
8405b70c
PB
206 }
207 protected final void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String s) {
01b477c6
PB
208 yylexer.yyerror (]b4_locations_if([loc, ])[s);
209 }
210
211 ]b4_locations_if([
8405b70c 212 protected final void yyerror (String s) {
ddf17a6e 213 yylexer.yyerror ((]b4_location_type[)null, s);
8405b70c
PB
214 }
215 protected final void yyerror (]b4_position_type[ loc, String s) {
01b477c6 216 yylexer.yyerror (new ]b4_location_type[ (loc), s);
8405b70c
PB
217 }])
218
219 [protected final void yycdebug (String s) {
220 if (yydebug > 0)
d3b12988 221 yyDebugStream.println (s);
8405b70c
PB
222 }
223
d3b12988 224 private final class YYStack {
8405b70c
PB
225 private int[] stateStack = new int[16];
226 ]b4_locations_if([[private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[
01b477c6 227 private ]b4_yystype[[] valueStack = new ]b4_yystype[[16];
8405b70c 228
8a93f8e6
PB
229 public int size = 16;
230 public int height = -1;
0d2b2ab0 231
01b477c6 232 public final void push (int state, ]b4_yystype[ value]dnl
0d2b2ab0 233 b4_locations_if([, ]b4_location_type[ loc])[) {
8405b70c 234 height++;
0d2b2ab0 235 if (size == height)
8405b70c
PB
236 {
237 int[] newStateStack = new int[size * 2];
238 System.arraycopy (stateStack, 0, newStateStack, 0, height);
239 stateStack = newStateStack;
240 ]b4_locations_if([[
241 ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
242 System.arraycopy (locStack, 0, newLocStack, 0, height);
243 locStack = newLocStack;]])
0d2b2ab0 244
01b477c6 245 b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
8405b70c
PB
246 System.arraycopy (valueStack, 0, newValueStack, 0, height);
247 valueStack = newValueStack;
248
249 size *= 2;
250 }
251
252 stateStack[height] = state;
253 ]b4_locations_if([[locStack[height] = loc;]])[
254 valueStack[height] = value;
255 }
256
257 public final void pop () {
4c2a6e42 258 pop (1);
8405b70c
PB
259 }
260
261 public final void pop (int num) {
262 // Avoid memory leaks... garbage collection is a white lie!
263 if (num > 0) {
6f75992b 264 java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);
4c2a6e42 265 ]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
8405b70c
PB
266 }
267 height -= num;
268 }
269
270 public final int stateAt (int i) {
271 return stateStack[height - i];
272 }
273
274 ]b4_locations_if([[public final ]b4_location_type[ locationAt (int i) {
275 return locStack[height - i];
276 }
277
01b477c6 278 ]])[public final ]b4_yystype[ valueAt (int i) {
8405b70c
PB
279 return valueStack[height - i];
280 }
281
282 // Print the state stack on the debug stream.
8a93f8e6 283 public void print (java.io.PrintStream out)
8405b70c
PB
284 {
285 out.print ("Stack now");
0d2b2ab0 286
f0e2c228 287 for (int i = 0; i <= height; i++)
8405b70c
PB
288 {
289 out.print (' ');
290 out.print (stateStack[i]);
291 }
292 out.println ();
293 }
294 }
295
296 /**
297 * Returned by a Bison action in order to stop the parsing process and
298 * return success (<tt>true</tt>). */
299 public static final int YYACCEPT = 0;
300
301 /**
302 * Returned by a Bison action in order to stop the parsing process and
303 * return failure (<tt>false</tt>). */
304 public static final int YYABORT = 1;
305
306 /**
307 * Returned by a Bison action in order to start error recovery without
308 * printing an error message. */
309 public static final int YYERROR = 2;
310
62efdd2a
JD
311 // Internal return codes that are not supported for user semantic
312 // actions.
313 private static final int YYERRLAB = 3;
8405b70c
PB
314 private static final int YYNEWSTATE = 4;
315 private static final int YYDEFAULT = 5;
316 private static final int YYREDUCE = 6;
317 private static final int YYERRLAB1 = 7;
318 private static final int YYRETURN = 8;
319
320 private int yyerrstatus_ = 0;
321
322 /**
323 * Return whether error recovery is being done. In this state, the parser
324 * reads token until it reaches a known state, and then restarts normal
325 * operation. */
d3b12988 326 public final boolean recovering ()
8405b70c
PB
327 {
328 return yyerrstatus_ == 0;
329 }
330
e254a580 331 private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
8405b70c 332 {
01b477c6 333 ]b4_yystype[ yyval;
8405b70c
PB
334 ]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
335
336 /* If YYLEN is nonzero, implement the default value of the action:
337 `$$ = $1'. Otherwise, use the top of the stack.
0d2b2ab0 338
8405b70c
PB
339 Otherwise, the following line sets YYVAL to garbage.
340 This behavior is undocumented and Bison
341 users should not rely upon it. */
342 if (yylen > 0)
343 yyval = yystack.valueAt (yylen - 1);
344 else
345 yyval = yystack.valueAt (0);
0d2b2ab0 346
8405b70c
PB
347 yy_reduce_print (yyn, yystack);
348
349 switch (yyn)
350 {
351 ]b4_user_actions[
352 default: break;
353 }
354
355 yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
356
357 yystack.pop (yylen);
358 yylen = 0;
359
360 /* Shift the result of the reduction. */
361 yyn = yyr1_[yyn];
362 int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0);
363 if (0 <= yystate && yystate <= yylast_
364 && yycheck_[yystate] == yystack.stateAt (0))
365 yystate = yytable_[yystate];
366 else
367 yystate = yydefgoto_[yyn - yyntokens_];
368
369 yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
370 return YYNEWSTATE;
371 }
372
373 /* Return YYSTR after stripping away unnecessary quotes and
374 backslashes, so that it's suitable for yyerror. The heuristic is
375 that double-quoting is unnecessary unless the string contains an
376 apostrophe, a comma, or backslash (other than backslash-backslash).
377 YYSTR is taken from yytname. */
378 private final String yytnamerr_ (String yystr)
379 {
380 if (yystr.charAt (0) == '"')
381 {
382 StringBuffer yyr = new StringBuffer ();
383 strip_quotes: for (int i = 1; i < yystr.length (); i++)
384 switch (yystr.charAt (i))
385 {
386 case '\'':
387 case ',':
388 break strip_quotes;
389
390 case '\\':
391 if (yystr.charAt(++i) != '\\')
392 break strip_quotes;
393 /* Fall through. */
394 default:
395 yyr.append (yystr.charAt (i));
396 break;
397
398 case '"':
399 return yyr.toString ();
400 }
401 }
402 else if (yystr.equals ("$end"))
403 return "end of input";
404
405 return yystr;
406 }
407
408 /*--------------------------------.
409 | Print this symbol on YYOUTPUT. |
410 `--------------------------------*/
411
412 private void yy_symbol_print (String s, int yytype,
01b477c6 413 ]b4_yystype[ yyvaluep]dnl
8405b70c
PB
414 b4_locations_if([, Object yylocationp])[)
415 {
416 if (yydebug > 0)
417 yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
418 + yytname_[yytype] + " ("]b4_locations_if([
419 + yylocationp + ": "])[
ddf17a6e 420 + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
8405b70c
PB
421 }
422
423 /**
424 * Parse input from the scanner that was specified at object construction
425 * time. Return whether the end of the input was reached successfully.
426 *
427 * @@return <tt>true</tt> if the parsing succeeds. Note that this does not
428 * imply that there were no syntax errors.
429 */
e254a580 430 public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
8405b70c
PB
431 {
432 /// Lookahead and lookahead in internal form.
433 int yychar = yyempty_;
434 int yytoken = 0;
435
436 /* State. */
437 int yyn = 0;
438 int yylen = 0;
439 int yystate = 0;
440
d3b12988 441 YYStack yystack = new YYStack ();
8405b70c
PB
442
443 /* Error handling. */
444 int yynerrs_ = 0;
445 ]b4_locations_if([/// The location where the error started.
446 ]b4_location_type[ yyerrloc = null;
447
448 /// ]b4_location_type[ of the lookahead.
449 ]b4_location_type[ yylloc = new ]b4_location_type[ (null, null);
450
451 /// @@$.
452 ]b4_location_type[ yyloc;])
453
454 /// Semantic value of the lookahead.
01b477c6 455 b4_yystype[ yylval = null;
8405b70c 456
8405b70c
PB
457 yycdebug ("Starting parse\n");
458 yyerrstatus_ = 0;
459
460]m4_ifdef([b4_initial_action], [
461m4_pushdef([b4_at_dollar], [yylloc])dnl
462m4_pushdef([b4_dollar_dollar], [yylval])dnl
463 /* User initialization code. */
464 b4_user_initial_action
465m4_popdef([b4_dollar_dollar])dnl
466m4_popdef([b4_at_dollar])])dnl
467
468 [ /* Initialize the stack. */
469 yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
470
471 int label = YYNEWSTATE;
472 for (;;)
473 switch (label)
474 {
475 /* New state. Unlike in the C/C++ skeletons, the state is already
476 pushed when we come here. */
477 case YYNEWSTATE:
478 yycdebug ("Entering state " + yystate + "\n");
479 if (yydebug > 0)
d3b12988 480 yystack.print (yyDebugStream);
0d2b2ab0 481
8405b70c
PB
482 /* Accept? */
483 if (yystate == yyfinal_)
484 return true;
0d2b2ab0 485
8405b70c
PB
486 /* Take a decision. First try without lookahead. */
487 yyn = yypact_[yystate];
d5eb0826 488 if (yy_pact_value_is_default_ (yyn))
8405b70c
PB
489 {
490 label = YYDEFAULT;
491 break;
492 }
0d2b2ab0 493
8405b70c
PB
494 /* Read a lookahead token. */
495 if (yychar == yyempty_)
496 {
497 yycdebug ("Reading a token: ");
01b477c6
PB
498 yychar = yylex ();]
499 b4_locations_if([[
500 yylloc = new ]b4_location_type[(yylexer.getStartPos (),
0d2b2ab0 501 yylexer.getEndPos ());]])
01b477c6 502 yylval = yylexer.getLVal ();[
8405b70c 503 }
0d2b2ab0 504
8405b70c
PB
505 /* Convert token to internal form. */
506 if (yychar <= EOF)
507 {
508 yychar = yytoken = EOF;
509 yycdebug ("Now at end of input.\n");
510 }
511 else
512 {
513 yytoken = yytranslate_ (yychar);
514 yy_symbol_print ("Next token is", yytoken,
0d2b2ab0 515 yylval]b4_locations_if([, yylloc])[);
8405b70c 516 }
0d2b2ab0 517
8405b70c
PB
518 /* If the proper action on seeing token YYTOKEN is to reduce or to
519 detect an error, take that action. */
520 yyn += yytoken;
521 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
522 label = YYDEFAULT;
0d2b2ab0 523
8405b70c
PB
524 /* <= 0 means reduce or error. */
525 else if ((yyn = yytable_[yyn]) <= 0)
526 {
d5eb0826 527 if (yy_table_value_is_error_ (yyn))
62efdd2a 528 label = YYERRLAB;
8405b70c
PB
529 else
530 {
531 yyn = -yyn;
532 label = YYREDUCE;
533 }
534 }
0d2b2ab0 535
8405b70c
PB
536 else
537 {
538 /* Shift the lookahead token. */
539 yy_symbol_print ("Shifting", yytoken,
0d2b2ab0
AD
540 yylval]b4_locations_if([, yylloc])[);
541
8405b70c
PB
542 /* Discard the token being shifted. */
543 yychar = yyempty_;
0d2b2ab0 544
8405b70c
PB
545 /* Count tokens shifted since error; after three, turn off error
546 status. */
547 if (yyerrstatus_ > 0)
548 --yyerrstatus_;
0d2b2ab0 549
8405b70c
PB
550 yystate = yyn;
551 yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
552 label = YYNEWSTATE;
553 }
554 break;
0d2b2ab0 555
8405b70c
PB
556 /*-----------------------------------------------------------.
557 | yydefault -- do the default action for the current state. |
558 `-----------------------------------------------------------*/
559 case YYDEFAULT:
560 yyn = yydefact_[yystate];
561 if (yyn == 0)
62efdd2a 562 label = YYERRLAB;
8405b70c
PB
563 else
564 label = YYREDUCE;
565 break;
0d2b2ab0 566
8405b70c
PB
567 /*-----------------------------.
568 | yyreduce -- Do a reduction. |
569 `-----------------------------*/
570 case YYREDUCE:
571 yylen = yyr2_[yyn];
572 label = yyaction (yyn, yystack, yylen);
573 yystate = yystack.stateAt (0);
574 break;
0d2b2ab0 575
8405b70c
PB
576 /*------------------------------------.
577 | yyerrlab -- here on detecting error |
578 `------------------------------------*/
62efdd2a 579 case YYERRLAB:
8405b70c
PB
580 /* If not already recovering from an error, report this error. */
581 if (yyerrstatus_ == 0)
582 {
095a1d11
JD
583 ++yynerrs_;
584 if (yychar == yyempty_)
585 yytoken = yyempty_;
586 yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
8405b70c 587 }
0d2b2ab0 588
8405b70c
PB
589 ]b4_locations_if([yyerrloc = yylloc;])[
590 if (yyerrstatus_ == 3)
591 {
592 /* If just tried and failed to reuse lookahead token after an
593 error, discard it. */
0d2b2ab0 594
8405b70c
PB
595 if (yychar <= EOF)
596 {
597 /* Return failure if at end of input. */
598 if (yychar == EOF)
599 return false;
600 }
601 else
602 yychar = yyempty_;
603 }
0d2b2ab0 604
8405b70c
PB
605 /* Else will try to reuse lookahead token after shifting the error
606 token. */
607 label = YYERRLAB1;
608 break;
0d2b2ab0 609
8405b70c
PB
610 /*---------------------------------------------------.
611 | errorlab -- error raised explicitly by YYERROR. |
612 `---------------------------------------------------*/
613 case YYERROR:
0d2b2ab0 614
8405b70c
PB
615 ]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
616 /* Do not reclaim the symbols of the rule which action triggered
617 this YYERROR. */
618 yystack.pop (yylen);
619 yylen = 0;
620 yystate = yystack.stateAt (0);
621 label = YYERRLAB1;
622 break;
0d2b2ab0 623
8405b70c
PB
624 /*-------------------------------------------------------------.
625 | yyerrlab1 -- common code for both syntax error and YYERROR. |
626 `-------------------------------------------------------------*/
627 case YYERRLAB1:
628 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
0d2b2ab0 629
8405b70c
PB
630 for (;;)
631 {
632 yyn = yypact_[yystate];
d5eb0826 633 if (!yy_pact_value_is_default_ (yyn))
8405b70c
PB
634 {
635 yyn += yyterror_;
636 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
637 {
638 yyn = yytable_[yyn];
639 if (0 < yyn)
640 break;
641 }
642 }
0d2b2ab0 643
8405b70c 644 /* Pop the current state because it cannot handle the error token. */
e34e97bc 645 if (yystack.height == 0)
8405b70c 646 return false;
0d2b2ab0 647
8405b70c
PB
648 ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
649 yystack.pop ();
650 yystate = yystack.stateAt (0);
651 if (yydebug > 0)
d3b12988 652 yystack.print (yyDebugStream);
8405b70c 653 }
0d2b2ab0 654
8405b70c
PB
655 ]b4_locations_if([
656 /* Muck with the stack to setup for yylloc. */
657 yystack.push (0, null, yylloc);
658 yystack.push (0, null, yyerrloc);
659 yyloc = yylloc (yystack, 2);
660 yystack.pop (2);])[
661
662 /* Shift the error token. */
663 yy_symbol_print ("Shifting", yystos_[yyn],
664 yylval]b4_locations_if([, yyloc])[);
0d2b2ab0 665
8405b70c
PB
666 yystate = yyn;
667 yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
668 label = YYNEWSTATE;
669 break;
0d2b2ab0 670
8405b70c
PB
671 /* Accept. */
672 case YYACCEPT:
673 return true;
0d2b2ab0 674
8405b70c
PB
675 /* Abort. */
676 case YYABORT:
677 return false;
678 }
679 }
680
681 // Generate an error message.
682 private String yysyntax_error (int yystate, int tok)
683 {
684 if (errorVerbose)
685 {
095a1d11
JD
686 /* There are many possibilities here to consider:
687 - Assume YYFAIL is not used. It's too flawed to consider.
688 See
689 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
690 for details. YYERROR is fine as it does not invoke this
691 function.
692 - If this state is a consistent state with a default action,
693 then the only way this function was invoked is if the
694 default action is an error action. In that case, don't
695 check for expected tokens because there are none.
696 - The only way there can be no lookahead present (in tok) is
697 if this state is a consistent state with a default action.
698 Thus, detecting the absence of a lookahead is sufficient to
699 determine that there is no unexpected or expected token to
700 report. In that case, just report a simple "syntax error".
701 - Don't assume there isn't a lookahead just because this
702 state is a consistent state with a default action. There
703 might have been a previous inconsistent state, consistent
704 state with a non-default action, or user semantic action
705 that manipulated yychar. (However, yychar is currently out
706 of scope during semantic actions.)
707 - Of course, the expected token list depends on states to
708 have correct lookahead information, and it depends on the
709 parser not to perform extra reductions after fetching a
710 lookahead from the scanner and before detecting a syntax
711 error. Thus, state merging (from LALR or IELR) and default
712 reductions corrupt the expected token list. However, the
713 list is correct for canonical LR with one exception: it
714 will still contain any token that will not be accepted due
715 to an error action in a later state.
716 */
717 if (tok != yyempty_)
8405b70c 718 {
095a1d11
JD
719 // FIXME: This method of building the message is not compatible
720 // with internationalization.
721 StringBuffer res =
722 new StringBuffer ("syntax error, unexpected ");
723 res.append (yytnamerr_ (yytname_[tok]));
724 int yyn = yypact_[yystate];
725 if (!yy_pact_value_is_default_ (yyn))
726 {
f953cb20
JD
727 /* Start YYX at -YYN if negative to avoid negative
728 indexes in YYCHECK. In other words, skip the first
729 -YYN actions for this state because they are default
730 actions. */
731 int yyxbegin = yyn < 0 ? -yyn : 0;
f953cb20
JD
732 /* Stay within bounds of both yycheck and yytname. */
733 int yychecklim = yylast_ - yyn + 1;
734 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
735 int count = 0;
736 for (int x = yyxbegin; x < yyxend; ++x)
737 if (yycheck_[x + yyn] == x && x != yyterror_
738 && !yy_table_value_is_error_ (yytable_[x + yyn]))
739 ++count;
f953cb20
JD
740 if (count < 5)
741 {
742 count = 0;
743 for (int x = yyxbegin; x < yyxend; ++x)
744 if (yycheck_[x + yyn] == x && x != yyterror_
745 && !yy_table_value_is_error_ (yytable_[x + yyn]))
746 {
747 res.append (count++ == 0 ? ", expecting " : " or ");
748 res.append (yytnamerr_ (yytname_[x]));
749 }
750 }
095a1d11 751 }
bb57985c 752 return res.toString ();
8405b70c
PB
753 }
754 }
755
756 return "syntax error";
757 }
758
d5eb0826
JD
759 /**
760 * Whether the given <code>yypact_</code> value indicates a defaulted state.
761 * @@param yyvalue the value to check
762 */
763 private static boolean yy_pact_value_is_default_ (int yyvalue)
764 {
765 return yyvalue == yypact_ninf_;
766 }
767
768 /**
769 * Whether the given <code>yytable_</code> value indicates a syntax error.
770 * @@param yyvalue the value to check
771 */
772 private static boolean yy_table_value_is_error_ (int yyvalue)
773 {
e4bcae3c 774 return yyvalue == yytable_ninf_;
d5eb0826 775 }
8405b70c
PB
776
777 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
778 STATE-NUM. */
779 private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
780 private static final ]b4_int_type_for([b4_pact])[ yypact_[] =
781 {
782 ]b4_pact[
783 };
784
620b5727
JD
785 /* YYDEFACT[S] -- default reduction number in state S. Performed when
786 YYTABLE doesn't specify something else to do. Zero means the
787 default is an error. */
8405b70c
PB
788 private static final ]b4_int_type_for([b4_defact])[ yydefact_[] =
789 {
790 ]b4_defact[
791 };
792
793 /* YYPGOTO[NTERM-NUM]. */
794 private static final ]b4_int_type_for([b4_pgoto])[ yypgoto_[] =
795 {
796 ]b4_pgoto[
797 };
798
799 /* YYDEFGOTO[NTERM-NUM]. */
800 private static final ]b4_int_type_for([b4_defgoto])[
801 yydefgoto_[] =
802 {
803 ]b4_defgoto[
804 };
805
806 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
807 positive, shift that token. If negative, reduce the rule which
e4bcae3c 808 number is the opposite. If YYTABLE_NINF_, syntax error. */
8405b70c
PB
809 private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
810 private static final ]b4_int_type_for([b4_table])[
811 yytable_[] =
812 {
813 ]b4_table[
814 };
815
816 /* YYCHECK. */
817 private static final ]b4_int_type_for([b4_check])[
818 yycheck_[] =
819 {
820 ]b4_check[
821 };
822
823 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
824 symbol of state STATE-NUM. */
825 private static final ]b4_int_type_for([b4_stos])[
826 yystos_[] =
827 {
828 ]b4_stos[
829 };
830
831 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
832 to YYLEX-NUM. */
833 private static final ]b4_int_type_for([b4_toknum])[
834 yytoken_number_[] =
835 {
836 ]b4_toknum[
837 };
838
839 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
840 private static final ]b4_int_type_for([b4_r1])[
841 yyr1_[] =
842 {
843 ]b4_r1[
844 };
845
846 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
847 private static final ]b4_int_type_for([b4_r2])[
848 yyr2_[] =
849 {
850 ]b4_r2[
851 };
852
853 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
854 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
855 private static final String yytname_[] =
856 {
857 ]b4_tname[
858 };
859
860 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
861 private static final ]b4_int_type_for([b4_rhs])[ yyrhs_[] =
862 {
863 ]b4_rhs[
864 };
865
866 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
867 YYRHS. */
868 private static final ]b4_int_type_for([b4_prhs])[ yyprhs_[] =
869 {
870 ]b4_prhs[
871 };
872
873 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
874 private static final ]b4_int_type_for([b4_rline])[ yyrline_[] =
875 {
876 ]b4_rline[
877 };
878
879 // Report on the debug stream that the rule yyrule is going to be reduced.
d3b12988 880 private void yy_reduce_print (int yyrule, YYStack yystack)
8405b70c
PB
881 {
882 if (yydebug == 0)
883 return;
884
885 int yylno = yyrline_[yyrule];
886 int yynrhs = yyr2_[yyrule];
887 /* Print the symbols being reduced, and their result. */
888 yycdebug ("Reducing stack by rule " + (yyrule - 1)
889 + " (line " + yylno + "), ");
890
891 /* The symbols being reduced. */
892 for (int yyi = 0; yyi < yynrhs; yyi++)
893 yy_symbol_print (" $" + (yyi + 1) + " =",
894 yyrhs_[yyprhs_[yyrule] + yyi],
0d2b2ab0 895 ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
8405b70c
PB
896 b4_rhs_location(yynrhs, yyi + 1)])[);
897 }
898
899 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
900 private static final ]b4_int_type_for([b4_translate])[ yytranslate_table_[] =
901 {
902 ]b4_translate[
903 };
904
905 private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
906 {
907 if (t >= 0 && t <= yyuser_token_number_max_)
908 return yytranslate_table_[t];
909 else
910 return yyundef_token_;
911 }
912
913 private static final int yylast_ = ]b4_last[;
914 private static final int yynnts_ = ]b4_nterms_number[;
915 private static final int yyempty_ = -2;
916 private static final int yyfinal_ = ]b4_final_state_number[;
917 private static final int yyterror_ = 1;
918 private static final int yyerrcode_ = 256;
919 private static final int yyntokens_ = ]b4_tokens_number[;
920
921 private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[;
922 private static final int yyundef_token_ = ]b4_undef_token_number[;
923
924]/* User implementation code. */
925b4_percent_code_get[]dnl
926
927}
928
929b4_epilogue
930m4_divert_pop(0)dnl