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