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