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