]> git.saurik.com Git - bison.git/blame - data/lalr1.java
Pass the token type to yysyntax_error.
[bison.git] / data / lalr1.java
CommitLineData
8405b70c
PB
1# Java skeleton for Bison -*- autoconf -*-
2
620b5727 3# Copyright (C) 2007, 2008, 2009 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],
38609c34 28 [2007, 2008, 2009])
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)
105 return new ]b4_location_type[ (rhs.locationAt (1).begin, rhs.locationAt (n).end);
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 () {
258 height--;
259 }
260
261 public final void pop (int num) {
262 // Avoid memory leaks... garbage collection is a white lie!
263 if (num > 0) {
264 java.util.Arrays.fill (valueStack, height - num + 1, height, null);
265 ]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height, null);]])[
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
8405b70c
PB
287 for (int i = 0; i < height; i++)
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
311 /**
312 * Returned by a Bison action in order to print an error message and start
313 * error recovery. */
314 public static final int YYFAIL = 3;
315
316 private static final int YYNEWSTATE = 4;
317 private static final int YYDEFAULT = 5;
318 private static final int YYREDUCE = 6;
319 private static final int YYERRLAB1 = 7;
320 private static final int YYRETURN = 8;
321
322 private int yyerrstatus_ = 0;
323
324 /**
325 * Return whether error recovery is being done. In this state, the parser
326 * reads token until it reaches a known state, and then restarts normal
327 * operation. */
d3b12988 328 public final boolean recovering ()
8405b70c
PB
329 {
330 return yyerrstatus_ == 0;
331 }
332
e254a580 333 private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
8405b70c 334 {
01b477c6 335 ]b4_yystype[ yyval;
8405b70c
PB
336 ]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
337
338 /* If YYLEN is nonzero, implement the default value of the action:
339 `$$ = $1'. Otherwise, use the top of the stack.
0d2b2ab0 340
8405b70c
PB
341 Otherwise, the following line sets YYVAL to garbage.
342 This behavior is undocumented and Bison
343 users should not rely upon it. */
344 if (yylen > 0)
345 yyval = yystack.valueAt (yylen - 1);
346 else
347 yyval = yystack.valueAt (0);
0d2b2ab0 348
8405b70c
PB
349 yy_reduce_print (yyn, yystack);
350
351 switch (yyn)
352 {
353 ]b4_user_actions[
354 default: break;
355 }
356
357 yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
358
359 yystack.pop (yylen);
360 yylen = 0;
361
362 /* Shift the result of the reduction. */
363 yyn = yyr1_[yyn];
364 int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0);
365 if (0 <= yystate && yystate <= yylast_
366 && yycheck_[yystate] == yystack.stateAt (0))
367 yystate = yytable_[yystate];
368 else
369 yystate = yydefgoto_[yyn - yyntokens_];
370
371 yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
372 return YYNEWSTATE;
373 }
374
375 /* Return YYSTR after stripping away unnecessary quotes and
376 backslashes, so that it's suitable for yyerror. The heuristic is
377 that double-quoting is unnecessary unless the string contains an
378 apostrophe, a comma, or backslash (other than backslash-backslash).
379 YYSTR is taken from yytname. */
380 private final String yytnamerr_ (String yystr)
381 {
382 if (yystr.charAt (0) == '"')
383 {
384 StringBuffer yyr = new StringBuffer ();
385 strip_quotes: for (int i = 1; i < yystr.length (); i++)
386 switch (yystr.charAt (i))
387 {
388 case '\'':
389 case ',':
390 break strip_quotes;
391
392 case '\\':
393 if (yystr.charAt(++i) != '\\')
394 break strip_quotes;
395 /* Fall through. */
396 default:
397 yyr.append (yystr.charAt (i));
398 break;
399
400 case '"':
401 return yyr.toString ();
402 }
403 }
404 else if (yystr.equals ("$end"))
405 return "end of input";
406
407 return yystr;
408 }
409
410 /*--------------------------------.
411 | Print this symbol on YYOUTPUT. |
412 `--------------------------------*/
413
414 private void yy_symbol_print (String s, int yytype,
01b477c6 415 ]b4_yystype[ yyvaluep]dnl
8405b70c
PB
416 b4_locations_if([, Object yylocationp])[)
417 {
418 if (yydebug > 0)
419 yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
420 + yytname_[yytype] + " ("]b4_locations_if([
421 + yylocationp + ": "])[
ddf17a6e 422 + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
8405b70c
PB
423 }
424
425 /**
426 * Parse input from the scanner that was specified at object construction
427 * time. Return whether the end of the input was reached successfully.
428 *
429 * @@return <tt>true</tt> if the parsing succeeds. Note that this does not
430 * imply that there were no syntax errors.
431 */
e254a580 432 public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
8405b70c
PB
433 {
434 /// Lookahead and lookahead in internal form.
435 int yychar = yyempty_;
436 int yytoken = 0;
437
438 /* State. */
439 int yyn = 0;
440 int yylen = 0;
441 int yystate = 0;
442
d3b12988 443 YYStack yystack = new YYStack ();
8405b70c
PB
444
445 /* Error handling. */
446 int yynerrs_ = 0;
447 ]b4_locations_if([/// The location where the error started.
448 ]b4_location_type[ yyerrloc = null;
449
450 /// ]b4_location_type[ of the lookahead.
451 ]b4_location_type[ yylloc = new ]b4_location_type[ (null, null);
452
453 /// @@$.
454 ]b4_location_type[ yyloc;])
455
456 /// Semantic value of the lookahead.
01b477c6 457 b4_yystype[ yylval = null;
8405b70c
PB
458
459 int yyresult;
460
461 yycdebug ("Starting parse\n");
462 yyerrstatus_ = 0;
463
464]m4_ifdef([b4_initial_action], [
465m4_pushdef([b4_at_dollar], [yylloc])dnl
466m4_pushdef([b4_dollar_dollar], [yylval])dnl
467 /* User initialization code. */
468 b4_user_initial_action
469m4_popdef([b4_dollar_dollar])dnl
470m4_popdef([b4_at_dollar])])dnl
471
472 [ /* Initialize the stack. */
473 yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
474
475 int label = YYNEWSTATE;
476 for (;;)
477 switch (label)
478 {
479 /* New state. Unlike in the C/C++ skeletons, the state is already
480 pushed when we come here. */
481 case YYNEWSTATE:
482 yycdebug ("Entering state " + yystate + "\n");
483 if (yydebug > 0)
d3b12988 484 yystack.print (yyDebugStream);
0d2b2ab0 485
8405b70c
PB
486 /* Accept? */
487 if (yystate == yyfinal_)
488 return true;
0d2b2ab0 489
8405b70c
PB
490 /* Take a decision. First try without lookahead. */
491 yyn = yypact_[yystate];
d5eb0826 492 if (yy_pact_value_is_default_ (yyn))
8405b70c
PB
493 {
494 label = YYDEFAULT;
495 break;
496 }
0d2b2ab0 497
8405b70c
PB
498 /* Read a lookahead token. */
499 if (yychar == yyempty_)
500 {
501 yycdebug ("Reading a token: ");
01b477c6
PB
502 yychar = yylex ();]
503 b4_locations_if([[
504 yylloc = new ]b4_location_type[(yylexer.getStartPos (),
0d2b2ab0 505 yylexer.getEndPos ());]])
01b477c6 506 yylval = yylexer.getLVal ();[
8405b70c 507 }
0d2b2ab0 508
8405b70c
PB
509 /* Convert token to internal form. */
510 if (yychar <= EOF)
511 {
512 yychar = yytoken = EOF;
513 yycdebug ("Now at end of input.\n");
514 }
515 else
516 {
517 yytoken = yytranslate_ (yychar);
518 yy_symbol_print ("Next token is", yytoken,
0d2b2ab0 519 yylval]b4_locations_if([, yylloc])[);
8405b70c 520 }
0d2b2ab0 521
8405b70c
PB
522 /* If the proper action on seeing token YYTOKEN is to reduce or to
523 detect an error, take that action. */
524 yyn += yytoken;
525 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
526 label = YYDEFAULT;
0d2b2ab0 527
8405b70c
PB
528 /* <= 0 means reduce or error. */
529 else if ((yyn = yytable_[yyn]) <= 0)
530 {
d5eb0826 531 if (yy_table_value_is_error_ (yyn))
8405b70c
PB
532 label = YYFAIL;
533 else
534 {
535 yyn = -yyn;
536 label = YYREDUCE;
537 }
538 }
0d2b2ab0 539
8405b70c
PB
540 else
541 {
542 /* Shift the lookahead token. */
543 yy_symbol_print ("Shifting", yytoken,
0d2b2ab0
AD
544 yylval]b4_locations_if([, yylloc])[);
545
8405b70c
PB
546 /* Discard the token being shifted. */
547 yychar = yyempty_;
0d2b2ab0 548
8405b70c
PB
549 /* Count tokens shifted since error; after three, turn off error
550 status. */
551 if (yyerrstatus_ > 0)
552 --yyerrstatus_;
0d2b2ab0 553
8405b70c
PB
554 yystate = yyn;
555 yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
556 label = YYNEWSTATE;
557 }
558 break;
0d2b2ab0 559
8405b70c
PB
560 /*-----------------------------------------------------------.
561 | yydefault -- do the default action for the current state. |
562 `-----------------------------------------------------------*/
563 case YYDEFAULT:
564 yyn = yydefact_[yystate];
565 if (yyn == 0)
566 label = YYFAIL;
567 else
568 label = YYREDUCE;
569 break;
0d2b2ab0 570
8405b70c
PB
571 /*-----------------------------.
572 | yyreduce -- Do a reduction. |
573 `-----------------------------*/
574 case YYREDUCE:
575 yylen = yyr2_[yyn];
576 label = yyaction (yyn, yystack, yylen);
577 yystate = yystack.stateAt (0);
578 break;
0d2b2ab0 579
8405b70c
PB
580 /*------------------------------------.
581 | yyerrlab -- here on detecting error |
582 `------------------------------------*/
583 case YYFAIL:
584 /* If not already recovering from an error, report this error. */
585 if (yyerrstatus_ == 0)
586 {
587 ++yynerrs_;
588 yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
589 }
0d2b2ab0 590
8405b70c
PB
591 ]b4_locations_if([yyerrloc = yylloc;])[
592 if (yyerrstatus_ == 3)
593 {
594 /* If just tried and failed to reuse lookahead token after an
595 error, discard it. */
0d2b2ab0 596
8405b70c
PB
597 if (yychar <= EOF)
598 {
599 /* Return failure if at end of input. */
600 if (yychar == EOF)
601 return false;
602 }
603 else
604 yychar = yyempty_;
605 }
0d2b2ab0 606
8405b70c
PB
607 /* Else will try to reuse lookahead token after shifting the error
608 token. */
609 label = YYERRLAB1;
610 break;
0d2b2ab0 611
8405b70c
PB
612 /*---------------------------------------------------.
613 | errorlab -- error raised explicitly by YYERROR. |
614 `---------------------------------------------------*/
615 case YYERROR:
0d2b2ab0 616
8405b70c
PB
617 ]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
618 /* Do not reclaim the symbols of the rule which action triggered
619 this YYERROR. */
620 yystack.pop (yylen);
621 yylen = 0;
622 yystate = yystack.stateAt (0);
623 label = YYERRLAB1;
624 break;
0d2b2ab0 625
8405b70c
PB
626 /*-------------------------------------------------------------.
627 | yyerrlab1 -- common code for both syntax error and YYERROR. |
628 `-------------------------------------------------------------*/
629 case YYERRLAB1:
630 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
0d2b2ab0 631
8405b70c
PB
632 for (;;)
633 {
634 yyn = yypact_[yystate];
d5eb0826 635 if (!yy_pact_value_is_default_ (yyn))
8405b70c
PB
636 {
637 yyn += yyterror_;
638 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
639 {
640 yyn = yytable_[yyn];
641 if (0 < yyn)
642 break;
643 }
644 }
0d2b2ab0 645
8405b70c
PB
646 /* Pop the current state because it cannot handle the error token. */
647 if (yystack.height == 1)
648 return false;
0d2b2ab0 649
8405b70c
PB
650 ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
651 yystack.pop ();
652 yystate = yystack.stateAt (0);
653 if (yydebug > 0)
d3b12988 654 yystack.print (yyDebugStream);
8405b70c 655 }
0d2b2ab0 656
8405b70c
PB
657 ]b4_locations_if([
658 /* Muck with the stack to setup for yylloc. */
659 yystack.push (0, null, yylloc);
660 yystack.push (0, null, yyerrloc);
661 yyloc = yylloc (yystack, 2);
662 yystack.pop (2);])[
663
664 /* Shift the error token. */
665 yy_symbol_print ("Shifting", yystos_[yyn],
666 yylval]b4_locations_if([, yyloc])[);
0d2b2ab0 667
8405b70c
PB
668 yystate = yyn;
669 yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
670 label = YYNEWSTATE;
671 break;
0d2b2ab0 672
8405b70c
PB
673 /* Accept. */
674 case YYACCEPT:
675 return true;
0d2b2ab0 676
8405b70c
PB
677 /* Abort. */
678 case YYABORT:
679 return false;
680 }
681 }
682
683 // Generate an error message.
684 private String yysyntax_error (int yystate, int tok)
685 {
686 if (errorVerbose)
687 {
688 int yyn = yypact_[yystate];
689 if (yypact_ninf_ < yyn && yyn <= yylast_)
690 {
691 StringBuffer res;
692
693 /* Start YYX at -YYN if negative to avoid negative indexes in
77373efa
JD
694 YYCHECK. In other words, skip the first -YYN actions for this
695 state because they are default actions. */
8405b70c
PB
696 int yyxbegin = yyn < 0 ? -yyn : 0;
697
698 /* Stay within bounds of both yycheck and yytname. */
699 int yychecklim = yylast_ - yyn + 1;
700 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
701 int count = 0;
702 for (int x = yyxbegin; x < yyxend; ++x)
1fa30307 703 if (yycheck_[x + yyn] == x && x != yyterror_
e4bcae3c 704 && !yy_table_value_is_error_ (yytable_[x + yyn]))
8405b70c
PB
705 ++count;
706
707 // FIXME: This method of building the message is not compatible
708 // with internationalization.
709 res = new StringBuffer ("syntax error, unexpected ");
710 res.append (yytnamerr_ (yytname_[tok]));
711 if (count < 5)
712 {
713 count = 0;
714 for (int x = yyxbegin; x < yyxend; ++x)
1fa30307 715 if (yycheck_[x + yyn] == x && x != yyterror_
e4bcae3c 716 && !yy_table_value_is_error_ (yytable_[x + yyn]))
8405b70c
PB
717 {
718 res.append (count++ == 0 ? ", expecting " : " or ");
719 res.append (yytnamerr_ (yytname_[x]));
720 }
721 }
722 return res.toString ();
723 }
724 }
725
726 return "syntax error";
727 }
728
d5eb0826
JD
729 /**
730 * Whether the given <code>yypact_</code> value indicates a defaulted state.
731 * @@param yyvalue the value to check
732 */
733 private static boolean yy_pact_value_is_default_ (int yyvalue)
734 {
735 return yyvalue == yypact_ninf_;
736 }
737
738 /**
739 * Whether the given <code>yytable_</code> value indicates a syntax error.
740 * @@param yyvalue the value to check
741 */
742 private static boolean yy_table_value_is_error_ (int yyvalue)
743 {
e4bcae3c 744 return yyvalue == yytable_ninf_;
d5eb0826 745 }
8405b70c
PB
746
747 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
748 STATE-NUM. */
749 private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
750 private static final ]b4_int_type_for([b4_pact])[ yypact_[] =
751 {
752 ]b4_pact[
753 };
754
620b5727
JD
755 /* YYDEFACT[S] -- default reduction number in state S. Performed when
756 YYTABLE doesn't specify something else to do. Zero means the
757 default is an error. */
8405b70c
PB
758 private static final ]b4_int_type_for([b4_defact])[ yydefact_[] =
759 {
760 ]b4_defact[
761 };
762
763 /* YYPGOTO[NTERM-NUM]. */
764 private static final ]b4_int_type_for([b4_pgoto])[ yypgoto_[] =
765 {
766 ]b4_pgoto[
767 };
768
769 /* YYDEFGOTO[NTERM-NUM]. */
770 private static final ]b4_int_type_for([b4_defgoto])[
771 yydefgoto_[] =
772 {
773 ]b4_defgoto[
774 };
775
776 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
777 positive, shift that token. If negative, reduce the rule which
e4bcae3c 778 number is the opposite. If YYTABLE_NINF_, syntax error. */
8405b70c
PB
779 private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
780 private static final ]b4_int_type_for([b4_table])[
781 yytable_[] =
782 {
783 ]b4_table[
784 };
785
786 /* YYCHECK. */
787 private static final ]b4_int_type_for([b4_check])[
788 yycheck_[] =
789 {
790 ]b4_check[
791 };
792
793 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
794 symbol of state STATE-NUM. */
795 private static final ]b4_int_type_for([b4_stos])[
796 yystos_[] =
797 {
798 ]b4_stos[
799 };
800
801 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
802 to YYLEX-NUM. */
803 private static final ]b4_int_type_for([b4_toknum])[
804 yytoken_number_[] =
805 {
806 ]b4_toknum[
807 };
808
809 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
810 private static final ]b4_int_type_for([b4_r1])[
811 yyr1_[] =
812 {
813 ]b4_r1[
814 };
815
816 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
817 private static final ]b4_int_type_for([b4_r2])[
818 yyr2_[] =
819 {
820 ]b4_r2[
821 };
822
823 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
824 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
825 private static final String yytname_[] =
826 {
827 ]b4_tname[
828 };
829
830 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
831 private static final ]b4_int_type_for([b4_rhs])[ yyrhs_[] =
832 {
833 ]b4_rhs[
834 };
835
836 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
837 YYRHS. */
838 private static final ]b4_int_type_for([b4_prhs])[ yyprhs_[] =
839 {
840 ]b4_prhs[
841 };
842
843 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
844 private static final ]b4_int_type_for([b4_rline])[ yyrline_[] =
845 {
846 ]b4_rline[
847 };
848
849 // Report on the debug stream that the rule yyrule is going to be reduced.
d3b12988 850 private void yy_reduce_print (int yyrule, YYStack yystack)
8405b70c
PB
851 {
852 if (yydebug == 0)
853 return;
854
855 int yylno = yyrline_[yyrule];
856 int yynrhs = yyr2_[yyrule];
857 /* Print the symbols being reduced, and their result. */
858 yycdebug ("Reducing stack by rule " + (yyrule - 1)
859 + " (line " + yylno + "), ");
860
861 /* The symbols being reduced. */
862 for (int yyi = 0; yyi < yynrhs; yyi++)
863 yy_symbol_print (" $" + (yyi + 1) + " =",
864 yyrhs_[yyprhs_[yyrule] + yyi],
0d2b2ab0 865 ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
8405b70c
PB
866 b4_rhs_location(yynrhs, yyi + 1)])[);
867 }
868
869 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
870 private static final ]b4_int_type_for([b4_translate])[ yytranslate_table_[] =
871 {
872 ]b4_translate[
873 };
874
875 private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
876 {
877 if (t >= 0 && t <= yyuser_token_number_max_)
878 return yytranslate_table_[t];
879 else
880 return yyundef_token_;
881 }
882
883 private static final int yylast_ = ]b4_last[;
884 private static final int yynnts_ = ]b4_nterms_number[;
885 private static final int yyempty_ = -2;
886 private static final int yyfinal_ = ]b4_final_state_number[;
887 private static final int yyterror_ = 1;
888 private static final int yyerrcode_ = 256;
889 private static final int yyntokens_ = ]b4_tokens_number[;
890
891 private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[;
892 private static final int yyundef_token_ = ]b4_undef_token_number[;
893
894]/* User implementation code. */
895b4_percent_code_get[]dnl
896
897}
898
899b4_epilogue
900m4_divert_pop(0)dnl