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