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