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