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