]> git.saurik.com Git - bison.git/blob - data/lalr1.java
Replace m4/warning.m4 with warnings module.
[bison.git] / data / lalr1.java
1 # Java skeleton for Bison -*- autoconf -*-
2
3 # Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 m4_include(b4_pkgdatadir/[java.m4])
19
20 b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java], [b4_skeleton])])
21 m4_ifval(m4_defn([b4_symbol_destructors]),
22 [b4_fatal([%s: %%destructor does not make sense in Java], [b4_skeleton])],
23 [])
24
25 m4_divert_push(0)dnl
26 @output(b4_parser_file_name@)@
27 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
28 [2007, 2008])
29
30 b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
31 ])[/* First part of user declarations. */
32 ]b4_user_pre_prologue
33 b4_user_post_prologue
34 b4_percent_code_get([[imports]])
35 [/**
36 * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
37 *
38 * @@author LALR (1) parser skeleton written by Paolo Bonzini.
39 */
40 ]b4_percent_define_get3([annotations], [], [ ])dnl
41 b4_public_if([public ])dnl
42 b4_abstract_if([abstract ])dnl
43 b4_final_if([final ])dnl
44 b4_strictfp_if([strictfp ])dnl
45 [class ]b4_parser_class_name[]dnl
46 b4_percent_define_get3([extends], [ extends ])dnl
47 b4_percent_define_get3([implements], [ implements ])[
48 {
49 ]b4_identification[
50 ]b4_error_verbose_if([[
51 /** True if verbose error messages are enabled. */
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 ]])
66
67 b4_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 /**
81 * Create a <code>]b4_location_type[</code> denoting an empty range located at
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.
91 * @@param end The first position beyond the range. */
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
111 b4_locations_if([[
112 private ]b4_location_type[ yylloc (YYStack rhs, int n)
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);
118 }]])[
119
120 /**
121 * Communication interface between the scanner and the Bison-generated
122 * parser <tt>]b4_parser_class_name[</tt>.
123 */
124 public interface Lexer {
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
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. */
143 ]b4_yystype[ getLVal ();
144
145 /**
146 * Entry point for the scanner. Returns the token identifier corresponding
147 * to the next token and prepares to return the semantic value
148 * ]b4_locations_if([and beginning/ending positions ])[of the token.
149 * @@return the token identifier corresponding to the next token. */
150 int yylex () ]b4_maybe_throws([b4_lex_throws])[;
151
152 /**
153 * Entry point for error reporting. Emits an error
154 * ]b4_locations_if([referring to the given location ])[in a user-defined way.
155 *
156 * ]b4_locations_if([[@@param loc The location of the element to which the
157 * error message is related]])[
158 * @@param msg The string for the error message. */
159 void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);]
160 }
161
162 b4_lexer_if([[private class YYLexer implements Lexer {
163 ]b4_percent_code_get([[lexer]])[
164 }
165
166 ]])[/** The object doing lexical analysis for us. */
167 private Lexer yylexer;
168 ]
169 b4_parse_param_vars
170
171 b4_lexer_if([[
172 /**
173 * Instantiates the Bison-generated parser.
174 */
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]])[
178 this.yylexer = new YYLexer(]b4_lex_param_call[);
179 ]b4_parse_param_cons[
180 }
181 ]])
182
183 /**
184 * Instantiates the Bison-generated parser.
185 * @@param yylexer The scanner that will supply tokens to the parser.
186 */
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]])[
190 this.yylexer = yylexer;
191 ]b4_parse_param_cons[
192 }
193
194 private java.io.PrintStream yyDebugStream = System.err;
195
196 /**
197 * Return the <tt>PrintStream</tt> on which the debugging output is
198 * printed.
199 */
200 public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
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 */
206 public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; }
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
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);
231 }
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);
241 }
242
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 }]])
252
253 [protected final void yycdebug (String s) {
254 if (yydebug > 0)
255 yyDebugStream.println (s);
256 }
257
258 private final class YYStack {
259 private int[] stateStack = new int[16];
260 ]b4_locations_if([[private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[
261 private ]b4_yystype[[] valueStack = new ]b4_yystype[[16];
262
263 public int size = 16;
264 public int height = -1;
265
266 public final void push (int state, ]b4_yystype[ value]dnl
267 b4_locations_if([, ]b4_location_type[ loc])[) {
268 height++;
269 if (size == height)
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;]])
278
279 b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
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
312 ]])[public final ]b4_yystype[ valueAt (int i) {
313 return valueStack[height - i];
314 }
315
316 // Print the state stack on the debug stream.
317 public void print (java.io.PrintStream out)
318 {
319 out.print ("Stack now");
320
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. */
362 public final boolean recovering ()
363 {
364 return yyerrstatus_ == 0;
365 }
366
367 private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
368 {
369 ]b4_yystype[ yyval;
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.
374
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);
382
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
409 ]b4_error_verbose_if([[
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 }
444 ]])[
445
446 /*--------------------------------.
447 | Print this symbol on YYOUTPUT. |
448 `--------------------------------*/
449
450 private void yy_symbol_print (String s, int yytype,
451 ]b4_yystype[ yyvaluep]dnl
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 + ": "])[
458 + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
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 */
468 public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
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
479 YYStack yystack = new YYStack ();
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.
493 b4_yystype[ yylval = null;
494
495 int yyresult;
496
497 yycdebug ("Starting parse\n");
498 yyerrstatus_ = 0;
499
500 ]m4_ifdef([b4_initial_action], [
501 m4_pushdef([b4_at_dollar], [yylloc])dnl
502 m4_pushdef([b4_dollar_dollar], [yylval])dnl
503 /* User initialization code. */
504 b4_user_initial_action
505 m4_popdef([b4_dollar_dollar])dnl
506 m4_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)
520 yystack.print (yyDebugStream);
521
522 /* Accept? */
523 if (yystate == yyfinal_)
524 return true;
525
526 /* Take a decision. First try without lookahead. */
527 yyn = yypact_[yystate];
528 if (yyn == yypact_ninf_)
529 {
530 label = YYDEFAULT;
531 break;
532 }
533
534 /* Read a lookahead token. */
535 if (yychar == yyempty_)
536 {
537 yycdebug ("Reading a token: ");
538 yychar = yylexer.yylex ();]
539 b4_locations_if([[
540 yylloc = new ]b4_location_type[(yylexer.getStartPos (),
541 yylexer.getEndPos ());]])
542 yylval = yylexer.getLVal ();[
543 }
544
545 /* Convert token to internal form. */
546 if (yychar <= Lexer.EOF)
547 {
548 yychar = yytoken = Lexer.EOF;
549 yycdebug ("Now at end of input.\n");
550 }
551 else
552 {
553 yytoken = yytranslate_ (yychar);
554 yy_symbol_print ("Next token is", yytoken,
555 yylval]b4_locations_if([, yylloc])[);
556 }
557
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;
563
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 }
575
576 else
577 {
578 /* Shift the lookahead token. */
579 yy_symbol_print ("Shifting", yytoken,
580 yylval]b4_locations_if([, yylloc])[);
581
582 /* Discard the token being shifted. */
583 yychar = yyempty_;
584
585 /* Count tokens shifted since error; after three, turn off error
586 status. */
587 if (yyerrstatus_ > 0)
588 --yyerrstatus_;
589
590 yystate = yyn;
591 yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
592 label = YYNEWSTATE;
593 }
594 break;
595
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;
606
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;
615
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 }
626
627 ]b4_locations_if([yyerrloc = yylloc;])[
628 if (yyerrstatus_ == 3)
629 {
630 /* If just tried and failed to reuse lookahead token after an
631 error, discard it. */
632
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
640 yychar = yyempty_;
641 }
642
643 /* Else will try to reuse lookahead token after shifting the error
644 token. */
645 label = YYERRLAB1;
646 break;
647
648 /*---------------------------------------------------.
649 | errorlab -- error raised explicitly by YYERROR. |
650 `---------------------------------------------------*/
651 case YYERROR:
652
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;
661
662 /*-------------------------------------------------------------.
663 | yyerrlab1 -- common code for both syntax error and YYERROR. |
664 `-------------------------------------------------------------*/
665 case YYERRLAB1:
666 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
667
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 }
681
682 /* Pop the current state because it cannot handle the error token. */
683 if (yystack.height == 1)
684 return false;
685
686 ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
687 yystack.pop ();
688 yystate = yystack.stateAt (0);
689 if (yydebug > 0)
690 yystack.print (yyDebugStream);
691 }
692
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])[);
703
704 yystate = yyn;
705 yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
706 label = YYNEWSTATE;
707 break;
708
709 /* Accept. */
710 case YYACCEPT:
711 return true;
712
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)
721 {]b4_error_verbose_if([[
722 if (yyErrorVerbose)
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 }
755 return res.toString ();
756 }
757 }
758 ]])[
759 return "syntax error";
760 }
761
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[;
765 ]b4_integral_parser_table([yypact_], [b4_pact])[
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. */
770 ]b4_integral_parser_table([yydefact_], [b4_defact])[
771
772 /* YYPGOTO[NTERM-NUM]. */
773 ]b4_integral_parser_table([yypgoto_], [b4_pgoto])[
774
775 /* YYDEFGOTO[NTERM-NUM]. */
776 ]b4_integral_parser_table([yydefgoto_], [b4_defgoto])[
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[;
782 ]b4_integral_parser_table([yytable_], [b4_table])[
783
784 /* YYCHECK. */
785 ]b4_integral_parser_table([yycheck_], [b4_check])[
786
787 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
788 symbol of state STATE-NUM. */
789 ]b4_integral_parser_table([yystos_], [b4_stos])[
790
791 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
792 to YYLEX-NUM. */
793 ]b4_integral_parser_table([yytoken_number_], [b4_toknum])[
794
795 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
796 ]b4_integral_parser_table([yyr1_], [b4_r1])[
797
798 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
799 ]b4_integral_parser_table([yyr2_], [b4_r2])[
800
801 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
802 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
803 ]b4_typed_parser_table([String], [yytname_], [b4_tname])[
804
805 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
806 ]b4_integral_parser_table([yyrhs_], [b4_rhs])[
807
808 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
809 YYRHS. */
810 ]b4_integral_parser_table([yyprhs_], [b4_prhs])[
811
812 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
813 ]b4_integral_parser_table([yyrline_], [b4_rline])[
814
815 // Report on the debug stream that the rule yyrule is going to be reduced.
816 private void yy_reduce_print (int yyrule, YYStack yystack)
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],
831 ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
832 b4_rhs_location(yynrhs, yyi + 1)])[);
833 }
834
835 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
836 ]b4_integral_parser_table([yytranslate_table_], [b4_translate])[
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. */
858 b4_percent_code_get[]dnl
859
860 }
861
862 b4_epilogue
863 m4_divert_pop(0)dnl