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