]>
Commit | Line | Data |
---|---|---|
8405b70c PB |
1 | # Java skeleton for Bison -*- autoconf -*- |
2 | ||
0ce61575 | 3 | # Copyright (C) 2007, 2008, 2009 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 PB |
32 | |
33 | m4_divert_push(0)dnl | |
a0d4650a | 34 | @output(b4_parser_file_name@)@ |
8405b70c | 35 | b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], |
3bb21113 | 36 | [2007, 2008]) |
8405b70c PB |
37 | |
38 | b4_percent_define_ifdef([package], [package b4_percent_define_get([package]); | |
39 | ])[/* First part of user declarations. */ | |
1979121c DJ |
40 | ]b4_user_pre_prologue |
41 | b4_user_post_prologue | |
8405b70c PB |
42 | b4_percent_code_get([[imports]]) |
43 | [/** | |
74d6c0fe | 44 | * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>. |
8405b70c PB |
45 | * |
46 | * @@author LALR (1) parser skeleton written by Paolo Bonzini. | |
47 | */ | |
1979121c DJ |
48 | ]b4_percent_define_get3([annotations], [], [ ])dnl |
49 | b4_public_if([public ])dnl | |
e254a580 DJ |
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 ])[ | |
8405b70c PB |
56 | { |
57 | ]b4_identification[ | |
1979121c | 58 | ]b4_error_verbose_if([[ |
8405b70c | 59 | /** True if verbose error messages are enabled. */ |
1979121c DJ |
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 | ]]) | |
8405b70c PB |
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 | /** | |
e254a580 | 89 | * Create a <code>]b4_location_type[</code> denoting an empty range located at |
8405b70c PB |
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. | |
74d6c0fe | 99 | * @@param end The first position beyond the range. */ |
8405b70c PB |
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 | ||
8405b70c | 119 | b4_locations_if([[ |
d3b12988 | 120 | private ]b4_location_type[ yylloc (YYStack rhs, int n) |
8405b70c PB |
121 | { |
122 | if (n > 0) | |
123 | return new ]b4_location_type[ (rhs.locationAt (1).begin, rhs.locationAt (n).end); | |
124 | else | |
125 | return new ]b4_location_type[ (rhs.locationAt (0).end); | |
74d6c0fe | 126 | }]])[ |
8405b70c | 127 | |
01b477c6 | 128 | /** |
8405b70c PB |
129 | * Communication interface between the scanner and the Bison-generated |
130 | * parser <tt>]b4_parser_class_name[</tt>. | |
131 | */ | |
132 | public interface Lexer { | |
1979121c DJ |
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(b4_tokens)[ | |
137 | ||
8405b70c PB |
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. */ | |
d0ee4105 | 151 | ]b4_yystype[ getLVal (); |
8405b70c PB |
152 | |
153 | /** | |
8405b70c | 154 | * Entry point for the scanner. Returns the token identifier corresponding |
d0ee4105 | 155 | * to the next token and prepares to return the semantic value |
a0d4650a | 156 | * ]b4_locations_if([and beginning/ending positions ])[of the token. |
8405b70c | 157 | * @@return the token identifier corresponding to the next token. */ |
01b477c6 | 158 | int yylex () ]b4_maybe_throws([b4_lex_throws])[; |
8405b70c PB |
159 | |
160 | /** | |
161 | * Entry point for error reporting. Emits an error | |
e254a580 | 162 | * ]b4_locations_if([referring to the given location ])[in a user-defined way. |
8405b70c | 163 | * |
74d6c0fe | 164 | * ]b4_locations_if([[@@param loc The location of the element to which the |
8405b70c | 165 | * error message is related]])[ |
1979121c DJ |
166 | * @@param msg The string for the error message. */ |
167 | void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);] | |
01b477c6 PB |
168 | } |
169 | ||
170 | b4_lexer_if([[private class YYLexer implements Lexer { | |
171 | ]b4_percent_code_get([[lexer]])[ | |
172 | } | |
8405b70c | 173 | |
01b477c6 PB |
174 | ]])[/** The object doing lexical analysis for us. */ |
175 | private Lexer yylexer; | |
176 | ] | |
177 | b4_parse_param_vars | |
8405b70c | 178 | |
01b477c6 | 179 | b4_lexer_if([[ |
8405b70c | 180 | /** |
01b477c6 | 181 | * Instantiates the Bison-generated parser. |
8405b70c | 182 | */ |
1979121c DJ |
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]])[ | |
01b477c6 PB |
186 | this.yylexer = new YYLexer(]b4_lex_param_call[); |
187 | ]b4_parse_param_cons[ | |
188 | } | |
189 | ]]) | |
190 | ||
191 | /** | |
192 | * Instantiates the Bison-generated parser. | |
74d6c0fe | 193 | * @@param yylexer The scanner that will supply tokens to the parser. |
01b477c6 | 194 | */ |
1979121c DJ |
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]])[ | |
01b477c6 PB |
198 | this.yylexer = yylexer; |
199 | ]b4_parse_param_cons[ | |
8405b70c PB |
200 | } |
201 | ||
d3b12988 | 202 | private java.io.PrintStream yyDebugStream = System.err; |
8405b70c PB |
203 | |
204 | /** | |
205 | * Return the <tt>PrintStream</tt> on which the debugging output is | |
206 | * printed. | |
207 | */ | |
d3b12988 | 208 | public final java.io.PrintStream getDebugStream () { return yyDebugStream; } |
8405b70c PB |
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 | */ | |
d3b12988 | 214 | public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; } |
8405b70c PB |
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 | ||
1979121c DJ |
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); | |
8405b70c | 239 | } |
1979121c DJ |
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); | |
01b477c6 PB |
249 | } |
250 | ||
1979121c DJ |
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 | }]]) | |
8405b70c PB |
260 | |
261 | [protected final void yycdebug (String s) { | |
262 | if (yydebug > 0) | |
d3b12988 | 263 | yyDebugStream.println (s); |
8405b70c PB |
264 | } |
265 | ||
d3b12988 | 266 | private final class YYStack { |
8405b70c PB |
267 | private int[] stateStack = new int[16]; |
268 | ]b4_locations_if([[private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[ | |
01b477c6 | 269 | private ]b4_yystype[[] valueStack = new ]b4_yystype[[16]; |
8405b70c | 270 | |
8a93f8e6 PB |
271 | public int size = 16; |
272 | public int height = -1; | |
a0d4650a | 273 | |
01b477c6 | 274 | public final void push (int state, ]b4_yystype[ value]dnl |
11707b2b | 275 | b4_locations_if([, ]b4_location_type[ loc])[) { |
8405b70c | 276 | height++; |
a0d4650a | 277 | if (size == height) |
8405b70c | 278 | { |
11707b2b AD |
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 | } | |
8405b70c PB |
293 | |
294 | stateStack[height] = state; | |
295 | ]b4_locations_if([[locStack[height] = loc;]])[ | |
296 | valueStack[height] = value; | |
297 | } | |
298 | ||
299 | public final void pop () { | |
300 | height--; | |
301 | } | |
302 | ||
303 | public final void pop (int num) { | |
304 | // Avoid memory leaks... garbage collection is a white lie! | |
305 | if (num > 0) { | |
11707b2b | 306 | java.util.Arrays.fill (valueStack, height - num + 1, height, null); |
8405b70c PB |
307 | ]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height, 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 | ||
01b477c6 | 320 | ]])[public final ]b4_yystype[ valueAt (int i) { |
8405b70c PB |
321 | return valueStack[height - i]; |
322 | } | |
323 | ||
324 | // Print the state stack on the debug stream. | |
8a93f8e6 | 325 | public void print (java.io.PrintStream out) |
8405b70c PB |
326 | { |
327 | out.print ("Stack now"); | |
a0d4650a | 328 | |
8405b70c PB |
329 | for (int i = 0; i < height; i++) |
330 | { | |
11707b2b AD |
331 | out.print (' '); |
332 | out.print (stateStack[i]); | |
8405b70c PB |
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 | /** | |
354 | * Returned by a Bison action in order to print an error message and start | |
355 | * error recovery. */ | |
356 | public static final int YYFAIL = 3; | |
357 | ||
358 | private static final int YYNEWSTATE = 4; | |
359 | private static final int YYDEFAULT = 5; | |
360 | private static final int YYREDUCE = 6; | |
361 | private static final int YYERRLAB1 = 7; | |
362 | private static final int YYRETURN = 8; | |
363 | ||
364 | private int yyerrstatus_ = 0; | |
365 | ||
366 | /** | |
367 | * Return whether error recovery is being done. In this state, the parser | |
368 | * reads token until it reaches a known state, and then restarts normal | |
369 | * operation. */ | |
d3b12988 | 370 | public final boolean recovering () |
8405b70c PB |
371 | { |
372 | return yyerrstatus_ == 0; | |
373 | } | |
374 | ||
e254a580 | 375 | private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[ |
8405b70c | 376 | { |
01b477c6 | 377 | ]b4_yystype[ yyval; |
8405b70c PB |
378 | ]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[ |
379 | ||
380 | /* If YYLEN is nonzero, implement the default value of the action: | |
381 | `$$ = $1'. Otherwise, use the top of the stack. | |
a0d4650a | 382 | |
8405b70c PB |
383 | Otherwise, the following line sets YYVAL to garbage. |
384 | This behavior is undocumented and Bison | |
385 | users should not rely upon it. */ | |
386 | if (yylen > 0) | |
387 | yyval = yystack.valueAt (yylen - 1); | |
388 | else | |
389 | yyval = yystack.valueAt (0); | |
a0d4650a | 390 | |
8405b70c PB |
391 | yy_reduce_print (yyn, yystack); |
392 | ||
393 | switch (yyn) | |
394 | { | |
11707b2b AD |
395 | ]b4_user_actions[ |
396 | default: break; | |
8405b70c PB |
397 | } |
398 | ||
399 | yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[); | |
400 | ||
401 | yystack.pop (yylen); | |
402 | yylen = 0; | |
403 | ||
404 | /* Shift the result of the reduction. */ | |
405 | yyn = yyr1_[yyn]; | |
406 | int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0); | |
407 | if (0 <= yystate && yystate <= yylast_ | |
11707b2b | 408 | && yycheck_[yystate] == yystack.stateAt (0)) |
8405b70c PB |
409 | yystate = yytable_[yystate]; |
410 | else | |
411 | yystate = yydefgoto_[yyn - yyntokens_]; | |
412 | ||
413 | yystack.push (yystate, yyval]b4_locations_if([, yyloc])[); | |
414 | return YYNEWSTATE; | |
415 | } | |
416 | ||
1979121c | 417 | ]b4_error_verbose_if([[ |
8405b70c PB |
418 | /* Return YYSTR after stripping away unnecessary quotes and |
419 | backslashes, so that it's suitable for yyerror. The heuristic is | |
420 | that double-quoting is unnecessary unless the string contains an | |
421 | apostrophe, a comma, or backslash (other than backslash-backslash). | |
422 | YYSTR is taken from yytname. */ | |
423 | private final String yytnamerr_ (String yystr) | |
424 | { | |
425 | if (yystr.charAt (0) == '"') | |
426 | { | |
427 | StringBuffer yyr = new StringBuffer (); | |
428 | strip_quotes: for (int i = 1; i < yystr.length (); i++) | |
429 | switch (yystr.charAt (i)) | |
430 | { | |
431 | case '\'': | |
432 | case ',': | |
433 | break strip_quotes; | |
434 | ||
435 | case '\\': | |
11707b2b | 436 | if (yystr.charAt(++i) != '\\') |
8405b70c PB |
437 | break strip_quotes; |
438 | /* Fall through. */ | |
439 | default: | |
440 | yyr.append (yystr.charAt (i)); | |
441 | break; | |
442 | ||
443 | case '"': | |
444 | return yyr.toString (); | |
445 | } | |
446 | } | |
447 | else if (yystr.equals ("$end")) | |
448 | return "end of input"; | |
449 | ||
450 | return yystr; | |
451 | } | |
1979121c | 452 | ]])[ |
8405b70c PB |
453 | |
454 | /*--------------------------------. | |
455 | | Print this symbol on YYOUTPUT. | | |
456 | `--------------------------------*/ | |
457 | ||
458 | private void yy_symbol_print (String s, int yytype, | |
11707b2b AD |
459 | ]b4_yystype[ yyvaluep]dnl |
460 | b4_locations_if([, Object yylocationp])[) | |
8405b70c PB |
461 | { |
462 | if (yydebug > 0) | |
463 | yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ") | |
11707b2b AD |
464 | + yytname_[yytype] + " ("]b4_locations_if([ |
465 | + yylocationp + ": "])[ | |
466 | + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")"); | |
8405b70c PB |
467 | } |
468 | ||
469 | /** | |
470 | * Parse input from the scanner that was specified at object construction | |
471 | * time. Return whether the end of the input was reached successfully. | |
472 | * | |
473 | * @@return <tt>true</tt> if the parsing succeeds. Note that this does not | |
474 | * imply that there were no syntax errors. | |
475 | */ | |
e254a580 | 476 | public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ |
8405b70c PB |
477 | { |
478 | /// Lookahead and lookahead in internal form. | |
479 | int yychar = yyempty_; | |
480 | int yytoken = 0; | |
481 | ||
482 | /* State. */ | |
483 | int yyn = 0; | |
484 | int yylen = 0; | |
485 | int yystate = 0; | |
486 | ||
d3b12988 | 487 | YYStack yystack = new YYStack (); |
8405b70c PB |
488 | |
489 | /* Error handling. */ | |
490 | int yynerrs_ = 0; | |
491 | ]b4_locations_if([/// The location where the error started. | |
492 | ]b4_location_type[ yyerrloc = null; | |
493 | ||
494 | /// ]b4_location_type[ of the lookahead. | |
495 | ]b4_location_type[ yylloc = new ]b4_location_type[ (null, null); | |
496 | ||
497 | /// @@$. | |
498 | ]b4_location_type[ yyloc;]) | |
499 | ||
500 | /// Semantic value of the lookahead. | |
01b477c6 | 501 | b4_yystype[ yylval = null; |
8405b70c PB |
502 | |
503 | int yyresult; | |
504 | ||
505 | yycdebug ("Starting parse\n"); | |
506 | yyerrstatus_ = 0; | |
507 | ||
508 | ]m4_ifdef([b4_initial_action], [ | |
509 | m4_pushdef([b4_at_dollar], [yylloc])dnl | |
510 | m4_pushdef([b4_dollar_dollar], [yylval])dnl | |
511 | /* User initialization code. */ | |
512 | b4_user_initial_action | |
513 | m4_popdef([b4_dollar_dollar])dnl | |
514 | m4_popdef([b4_at_dollar])])dnl | |
515 | ||
516 | [ /* Initialize the stack. */ | |
517 | yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); | |
518 | ||
519 | int label = YYNEWSTATE; | |
520 | for (;;) | |
521 | switch (label) | |
522 | { | |
523 | /* New state. Unlike in the C/C++ skeletons, the state is already | |
11707b2b | 524 | pushed when we come here. */ |
8405b70c PB |
525 | case YYNEWSTATE: |
526 | yycdebug ("Entering state " + yystate + "\n"); | |
527 | if (yydebug > 0) | |
d3b12988 | 528 | yystack.print (yyDebugStream); |
a0d4650a | 529 | |
8405b70c PB |
530 | /* Accept? */ |
531 | if (yystate == yyfinal_) | |
532 | return true; | |
a0d4650a | 533 | |
8405b70c PB |
534 | /* Take a decision. First try without lookahead. */ |
535 | yyn = yypact_[yystate]; | |
536 | if (yyn == yypact_ninf_) | |
537 | { | |
538 | label = YYDEFAULT; | |
11707b2b | 539 | break; |
8405b70c | 540 | } |
a0d4650a | 541 | |
8405b70c PB |
542 | /* Read a lookahead token. */ |
543 | if (yychar == yyempty_) | |
544 | { | |
c4ddc0fb AD |
545 | yycdebug ("Reading a token: "); |
546 | yychar = yylexer.yylex ();] | |
01b477c6 | 547 | b4_locations_if([[ |
c4ddc0fb | 548 | yylloc = new ]b4_location_type[(yylexer.getStartPos (), |
1979121c | 549 | yylexer.getEndPos ());]]) |
01b477c6 | 550 | yylval = yylexer.getLVal ();[ |
8405b70c | 551 | } |
a0d4650a | 552 | |
8405b70c | 553 | /* Convert token to internal form. */ |
1979121c | 554 | if (yychar <= Lexer.EOF) |
8405b70c | 555 | { |
c4ddc0fb AD |
556 | yychar = yytoken = Lexer.EOF; |
557 | yycdebug ("Now at end of input.\n"); | |
8405b70c PB |
558 | } |
559 | else | |
560 | { | |
11707b2b AD |
561 | yytoken = yytranslate_ (yychar); |
562 | yy_symbol_print ("Next token is", yytoken, | |
563 | yylval]b4_locations_if([, yylloc])[); | |
8405b70c | 564 | } |
a0d4650a | 565 | |
8405b70c PB |
566 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
567 | detect an error, take that action. */ | |
568 | yyn += yytoken; | |
569 | if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) | |
570 | label = YYDEFAULT; | |
a0d4650a | 571 | |
8405b70c PB |
572 | /* <= 0 means reduce or error. */ |
573 | else if ((yyn = yytable_[yyn]) <= 0) | |
574 | { | |
11707b2b AD |
575 | if (yyn == 0 || yyn == yytable_ninf_) |
576 | label = YYFAIL; | |
577 | else | |
578 | { | |
579 | yyn = -yyn; | |
580 | label = YYREDUCE; | |
581 | } | |
8405b70c | 582 | } |
a0d4650a | 583 | |
8405b70c PB |
584 | else |
585 | { | |
586 | /* Shift the lookahead token. */ | |
11707b2b AD |
587 | yy_symbol_print ("Shifting", yytoken, |
588 | yylval]b4_locations_if([, yylloc])[); | |
a0d4650a | 589 | |
8405b70c PB |
590 | /* Discard the token being shifted. */ |
591 | yychar = yyempty_; | |
a0d4650a | 592 | |
8405b70c PB |
593 | /* Count tokens shifted since error; after three, turn off error |
594 | status. */ | |
595 | if (yyerrstatus_ > 0) | |
596 | --yyerrstatus_; | |
a0d4650a | 597 | |
8405b70c PB |
598 | yystate = yyn; |
599 | yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); | |
600 | label = YYNEWSTATE; | |
601 | } | |
602 | break; | |
a0d4650a | 603 | |
8405b70c PB |
604 | /*-----------------------------------------------------------. |
605 | | yydefault -- do the default action for the current state. | | |
606 | `-----------------------------------------------------------*/ | |
607 | case YYDEFAULT: | |
608 | yyn = yydefact_[yystate]; | |
609 | if (yyn == 0) | |
610 | label = YYFAIL; | |
611 | else | |
612 | label = YYREDUCE; | |
613 | break; | |
a0d4650a | 614 | |
8405b70c PB |
615 | /*-----------------------------. |
616 | | yyreduce -- Do a reduction. | | |
617 | `-----------------------------*/ | |
618 | case YYREDUCE: | |
619 | yylen = yyr2_[yyn]; | |
620 | label = yyaction (yyn, yystack, yylen); | |
11707b2b | 621 | yystate = yystack.stateAt (0); |
8405b70c | 622 | break; |
a0d4650a | 623 | |
8405b70c PB |
624 | /*------------------------------------. |
625 | | yyerrlab -- here on detecting error | | |
626 | `------------------------------------*/ | |
627 | case YYFAIL: | |
628 | /* If not already recovering from an error, report this error. */ | |
629 | if (yyerrstatus_ == 0) | |
630 | { | |
11707b2b AD |
631 | ++yynerrs_; |
632 | yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken)); | |
8405b70c | 633 | } |
a0d4650a | 634 | |
8405b70c PB |
635 | ]b4_locations_if([yyerrloc = yylloc;])[ |
636 | if (yyerrstatus_ == 3) | |
637 | { | |
1979121c DJ |
638 | /* If just tried and failed to reuse lookahead token after an |
639 | error, discard it. */ | |
a0d4650a | 640 | |
1979121c DJ |
641 | if (yychar <= Lexer.EOF) |
642 | { | |
643 | /* Return failure if at end of input. */ | |
644 | if (yychar == Lexer.EOF) | |
645 | return false; | |
646 | } | |
647 | else | |
11707b2b | 648 | yychar = yyempty_; |
8405b70c | 649 | } |
a0d4650a | 650 | |
8405b70c PB |
651 | /* Else will try to reuse lookahead token after shifting the error |
652 | token. */ | |
653 | label = YYERRLAB1; | |
654 | break; | |
a0d4650a | 655 | |
8405b70c PB |
656 | /*---------------------------------------------------. |
657 | | errorlab -- error raised explicitly by YYERROR. | | |
658 | `---------------------------------------------------*/ | |
659 | case YYERROR: | |
a0d4650a | 660 | |
8405b70c PB |
661 | ]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[ |
662 | /* Do not reclaim the symbols of the rule which action triggered | |
663 | this YYERROR. */ | |
664 | yystack.pop (yylen); | |
665 | yylen = 0; | |
666 | yystate = yystack.stateAt (0); | |
667 | label = YYERRLAB1; | |
668 | break; | |
a0d4650a | 669 | |
8405b70c PB |
670 | /*-------------------------------------------------------------. |
671 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
672 | `-------------------------------------------------------------*/ | |
673 | case YYERRLAB1: | |
11707b2b | 674 | yyerrstatus_ = 3; /* Each real token shifted decrements this. */ |
a0d4650a | 675 | |
8405b70c PB |
676 | for (;;) |
677 | { | |
11707b2b AD |
678 | yyn = yypact_[yystate]; |
679 | if (yyn != yypact_ninf_) | |
680 | { | |
681 | yyn += yyterror_; | |
682 | if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) | |
683 | { | |
684 | yyn = yytable_[yyn]; | |
685 | if (0 < yyn) | |
686 | break; | |
687 | } | |
688 | } | |
689 | ||
690 | /* Pop the current state because it cannot handle the error token. */ | |
691 | if (yystack.height == 1) | |
692 | return false; | |
693 | ||
694 | ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[ | |
695 | yystack.pop (); | |
696 | yystate = yystack.stateAt (0); | |
697 | if (yydebug > 0) | |
698 | yystack.print (yyDebugStream); | |
8405b70c | 699 | } |
a0d4650a | 700 | |
11707b2b AD |
701 | ]b4_locations_if([ |
702 | /* Muck with the stack to setup for yylloc. */ | |
703 | yystack.push (0, null, yylloc); | |
704 | yystack.push (0, null, yyerrloc); | |
8405b70c | 705 | yyloc = yylloc (yystack, 2); |
11707b2b | 706 | yystack.pop (2);])[ |
8405b70c PB |
707 | |
708 | /* Shift the error token. */ | |
709 | yy_symbol_print ("Shifting", yystos_[yyn], | |
11707b2b | 710 | yylval]b4_locations_if([, yyloc])[); |
a0d4650a | 711 | |
8405b70c | 712 | yystate = yyn; |
11707b2b | 713 | yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); |
8405b70c PB |
714 | label = YYNEWSTATE; |
715 | break; | |
a0d4650a | 716 | |
8405b70c PB |
717 | /* Accept. */ |
718 | case YYACCEPT: | |
719 | return true; | |
a0d4650a | 720 | |
8405b70c PB |
721 | /* Abort. */ |
722 | case YYABORT: | |
723 | return false; | |
724 | } | |
725 | } | |
726 | ||
727 | // Generate an error message. | |
728 | private String yysyntax_error (int yystate, int tok) | |
1979121c DJ |
729 | {]b4_error_verbose_if([[ |
730 | if (yyErrorVerbose) | |
8405b70c PB |
731 | { |
732 | int yyn = yypact_[yystate]; | |
733 | if (yypact_ninf_ < yyn && yyn <= yylast_) | |
734 | { | |
11707b2b AD |
735 | StringBuffer res; |
736 | ||
737 | /* Start YYX at -YYN if negative to avoid negative indexes in | |
738 | YYCHECK. */ | |
739 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
740 | ||
741 | /* Stay within bounds of both yycheck and yytname. */ | |
742 | int yychecklim = yylast_ - yyn + 1; | |
743 | int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; | |
744 | int count = 0; | |
745 | for (int x = yyxbegin; x < yyxend; ++x) | |
746 | if (yycheck_[x + yyn] == x && x != yyterror_) | |
747 | ++count; | |
748 | ||
749 | // FIXME: This method of building the message is not compatible | |
750 | // with internationalization. | |
751 | res = new StringBuffer ("syntax error, unexpected "); | |
752 | res.append (yytnamerr_ (yytname_[tok])); | |
753 | if (count < 5) | |
754 | { | |
755 | count = 0; | |
756 | for (int x = yyxbegin; x < yyxend; ++x) | |
757 | if (yycheck_[x + yyn] == x && x != yyterror_) | |
758 | { | |
759 | res.append (count++ == 0 ? ", expecting " : " or "); | |
760 | res.append (yytnamerr_ (yytname_[x])); | |
761 | } | |
762 | } | |
2b008529 | 763 | return res.toString (); |
8405b70c PB |
764 | } |
765 | } | |
1979121c | 766 | ]])[ |
8405b70c PB |
767 | return "syntax error"; |
768 | } | |
769 | ||
8405b70c | 770 | private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; |
8405b70c | 771 | private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; |
8405b70c | 772 | |
2c1bf9bd AD |
773 | ]b4_parser_tables_define[ |
774 | ]b4_integral_parser_table_define([token_number], [b4_toknum], | |
775 | [TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding | |
776 | to YYLEX-NUM.])[ | |
8405b70c PB |
777 | |
778 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. | |
779 | First, the terminals, then, starting at \a yyntokens_, nonterminals. */ | |
2c1bf9bd | 780 | ]b4_typed_parser_table_define([String], [tname], [b4_tname])[ |
8405b70c | 781 | |
2c1bf9bd AD |
782 | ]b4_integral_parser_table_define([rline], [b4_rline], |
783 | [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[ | |
8405b70c PB |
784 | |
785 | // Report on the debug stream that the rule yyrule is going to be reduced. | |
d3b12988 | 786 | private void yy_reduce_print (int yyrule, YYStack yystack) |
8405b70c PB |
787 | { |
788 | if (yydebug == 0) | |
789 | return; | |
790 | ||
791 | int yylno = yyrline_[yyrule]; | |
792 | int yynrhs = yyr2_[yyrule]; | |
793 | /* Print the symbols being reduced, and their result. */ | |
794 | yycdebug ("Reducing stack by rule " + (yyrule - 1) | |
11707b2b | 795 | + " (line " + yylno + "), "); |
8405b70c PB |
796 | |
797 | /* The symbols being reduced. */ | |
798 | for (int yyi = 0; yyi < yynrhs; yyi++) | |
799 | yy_symbol_print (" $" + (yyi + 1) + " =", | |
b4f18401 | 800 | yystos_[yystack.stateAt(yyi + 1 - yynrhs)], |
11707b2b AD |
801 | ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([, |
802 | b4_rhs_location(yynrhs, yyi + 1)])[); | |
8405b70c PB |
803 | } |
804 | ||
805 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ | |
2c1bf9bd | 806 | ]b4_integral_parser_table_define([translate_table], [b4_translate])[ |
8405b70c PB |
807 | |
808 | private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t) | |
809 | { | |
810 | if (t >= 0 && t <= yyuser_token_number_max_) | |
811 | return yytranslate_table_[t]; | |
812 | else | |
813 | return yyundef_token_; | |
814 | } | |
815 | ||
816 | private static final int yylast_ = ]b4_last[; | |
817 | private static final int yynnts_ = ]b4_nterms_number[; | |
818 | private static final int yyempty_ = -2; | |
819 | private static final int yyfinal_ = ]b4_final_state_number[; | |
820 | private static final int yyterror_ = 1; | |
821 | private static final int yyerrcode_ = 256; | |
822 | private static final int yyntokens_ = ]b4_tokens_number[; | |
823 | ||
824 | private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[; | |
825 | private static final int yyundef_token_ = ]b4_undef_token_number[; | |
826 | ||
827 | ]/* User implementation code. */ | |
828 | b4_percent_code_get[]dnl | |
829 | ||
830 | } | |
831 | ||
4524c55b | 832 | b4_epilogue[]dnl |
8405b70c | 833 | m4_divert_pop(0)dnl |