1*cda5da8dSAndroid Build Coastguard Worker # Java skeleton for Bison -*- java -*- 2*cda5da8dSAndroid Build Coastguard Worker 3*cda5da8dSAndroid Build Coastguard Worker # Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc. 4*cda5da8dSAndroid Build Coastguard Worker 5*cda5da8dSAndroid Build Coastguard Worker # This program is free software: you can redistribute it and/or modify 6*cda5da8dSAndroid Build Coastguard Worker # it under the terms of the GNU General Public License as published by 7*cda5da8dSAndroid Build Coastguard Worker # the Free Software Foundation, either version 3 of the License, or 8*cda5da8dSAndroid Build Coastguard Worker # (at your option) any later version. 9*cda5da8dSAndroid Build Coastguard Worker # 10*cda5da8dSAndroid Build Coastguard Worker # This program is distributed in the hope that it will be useful, 11*cda5da8dSAndroid Build Coastguard Worker # but WITHOUT ANY WARRANTY; without even the implied warranty of 12*cda5da8dSAndroid Build Coastguard Worker # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*cda5da8dSAndroid Build Coastguard Worker # GNU General Public License for more details. 14*cda5da8dSAndroid Build Coastguard Worker # 15*cda5da8dSAndroid Build Coastguard Worker # You should have received a copy of the GNU General Public License 16*cda5da8dSAndroid Build Coastguard Worker # along with this program. If not, see <https://www.gnu.org/licenses/>. 17*cda5da8dSAndroid Build Coastguard Worker 18*cda5da8dSAndroid Build Coastguard Worker m4_include(b4_skeletonsdir/[java.m4]) 19*cda5da8dSAndroid Build Coastguard Worker 20*cda5da8dSAndroid Build Coastguard Worker b4_header_if([b4_complain([%header/%defines does not make sense in Java])]) 21*cda5da8dSAndroid Build Coastguard Worker 22*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_symbol_no_destructor_assert], 23*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_if([$1], [has_destructor], 24*cda5da8dSAndroid Build Coastguard Worker [b4_complain_at(m4_unquote(b4_symbol([$1], [destructor_loc])), 25*cda5da8dSAndroid Build Coastguard Worker [%destructor does not make sense in Java])])]) 26*cda5da8dSAndroid Build Coastguard Worker b4_symbol_foreach([b4_symbol_no_destructor_assert]) 27*cda5da8dSAndroid Build Coastguard Worker 28*cda5da8dSAndroid Build Coastguard Worker ## --------------- ## 29*cda5da8dSAndroid Build Coastguard Worker ## api.push-pull. ## 30*cda5da8dSAndroid Build Coastguard Worker ## --------------- ## 31*cda5da8dSAndroid Build Coastguard Worker 32*cda5da8dSAndroid Build Coastguard Worker b4_percent_define_default([[api.push-pull]], [[pull]]) 33*cda5da8dSAndroid Build Coastguard Worker b4_percent_define_check_values([[[[api.push-pull]], 34*cda5da8dSAndroid Build Coastguard Worker [[pull]], [[push]], [[both]]]]) 35*cda5da8dSAndroid Build Coastguard Worker 36*cda5da8dSAndroid Build Coastguard Worker # Define m4 conditional macros that encode the value 37*cda5da8dSAndroid Build Coastguard Worker # of the api.push-pull flag. 38*cda5da8dSAndroid Build Coastguard Worker b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) 39*cda5da8dSAndroid Build Coastguard Worker b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) 40*cda5da8dSAndroid Build Coastguard Worker m4_case(b4_percent_define_get([[api.push-pull]]), 41*cda5da8dSAndroid Build Coastguard Worker [pull], [m4_define([b4_push_flag], [[0]])], 42*cda5da8dSAndroid Build Coastguard Worker [push], [m4_define([b4_pull_flag], [[0]])]) 43*cda5da8dSAndroid Build Coastguard Worker 44*cda5da8dSAndroid Build Coastguard Worker # Define a macro to be true when api.push-pull has the value "both". 45*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])]) 46*cda5da8dSAndroid Build Coastguard Worker 47*cda5da8dSAndroid Build Coastguard Worker # Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing 48*cda5da8dSAndroid Build Coastguard Worker # tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the 49*cda5da8dSAndroid Build Coastguard Worker # behavior of Bison at all when push parsing is already requested. 50*cda5da8dSAndroid Build Coastguard Worker b4_define_flag_if([use_push_for_pull]) 51*cda5da8dSAndroid Build Coastguard Worker b4_use_push_for_pull_if([ 52*cda5da8dSAndroid Build Coastguard Worker b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], 53*cda5da8dSAndroid Build Coastguard Worker [m4_define([b4_push_flag], [[1]])])]) 54*cda5da8dSAndroid Build Coastguard Worker 55*cda5da8dSAndroid Build Coastguard Worker # Define a macro to encapsulate the parse state variables. This 56*cda5da8dSAndroid Build Coastguard Worker # allows them to be defined either in parse() when doing pull parsing, 57*cda5da8dSAndroid Build Coastguard Worker # or as class instance variable when doing push parsing. 58*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_define_state], 59*cda5da8dSAndroid Build Coastguard Worker [[ 60*cda5da8dSAndroid Build Coastguard Worker /* Lookahead token kind. */ 61*cda5da8dSAndroid Build Coastguard Worker int yychar = YYEMPTY_; 62*cda5da8dSAndroid Build Coastguard Worker /* Lookahead symbol kind. */ 63*cda5da8dSAndroid Build Coastguard Worker SymbolKind yytoken = null; 64*cda5da8dSAndroid Build Coastguard Worker 65*cda5da8dSAndroid Build Coastguard Worker /* State. */ 66*cda5da8dSAndroid Build Coastguard Worker int yyn = 0; 67*cda5da8dSAndroid Build Coastguard Worker int yylen = 0; 68*cda5da8dSAndroid Build Coastguard Worker int yystate = 0; 69*cda5da8dSAndroid Build Coastguard Worker YYStack yystack = new YYStack (); 70*cda5da8dSAndroid Build Coastguard Worker int label = YYNEWSTATE; 71*cda5da8dSAndroid Build Coastguard Worker 72*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 73*cda5da8dSAndroid Build Coastguard Worker /* The location where the error started. */ 74*cda5da8dSAndroid Build Coastguard Worker ]b4_location_type[ yyerrloc = null; 75*cda5da8dSAndroid Build Coastguard Worker 76*cda5da8dSAndroid Build Coastguard Worker /* Location. */ 77*cda5da8dSAndroid Build Coastguard Worker ]b4_location_type[ yylloc = new ]b4_location_type[ (null, null);]])[ 78*cda5da8dSAndroid Build Coastguard Worker 79*cda5da8dSAndroid Build Coastguard Worker /* Semantic value of the lookahead. */ 80*cda5da8dSAndroid Build Coastguard Worker ]b4_yystype[ yylval = null; 81*cda5da8dSAndroid Build Coastguard Worker ]]) 82*cda5da8dSAndroid Build Coastguard Worker 83*cda5da8dSAndroid Build Coastguard Worker # parse.lac 84*cda5da8dSAndroid Build Coastguard Worker b4_percent_define_default([[parse.lac]], [[none]]) 85*cda5da8dSAndroid Build Coastguard Worker b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) 86*cda5da8dSAndroid Build Coastguard Worker b4_define_flag_if([lac]) 87*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_lac_flag], 88*cda5da8dSAndroid Build Coastguard Worker [m4_if(b4_percent_define_get([[parse.lac]]), 89*cda5da8dSAndroid Build Coastguard Worker [none], [[0]], [[1]])]) 90*cda5da8dSAndroid Build Coastguard Worker 91*cda5da8dSAndroid Build Coastguard Worker 92*cda5da8dSAndroid Build Coastguard Worker ## ------------- ## 93*cda5da8dSAndroid Build Coastguard Worker ## Parser File. ## 94*cda5da8dSAndroid Build Coastguard Worker ## ------------- ## 95*cda5da8dSAndroid Build Coastguard Worker 96*cda5da8dSAndroid Build Coastguard Worker b4_output_begin([b4_parser_file_name])[ 97*cda5da8dSAndroid Build Coastguard Worker ]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], 98*cda5da8dSAndroid Build Coastguard Worker [2007-2015, 2018-2021])[ 99*cda5da8dSAndroid Build Coastguard Worker ]b4_disclaimer[ 100*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_define_ifdef([api.package], [package b4_percent_define_get([api.package]);[ 101*cda5da8dSAndroid Build Coastguard Worker ]])[ 102*cda5da8dSAndroid Build Coastguard Worker ]b4_user_pre_prologue[ 103*cda5da8dSAndroid Build Coastguard Worker ]b4_user_post_prologue[ 104*cda5da8dSAndroid Build Coastguard Worker import java.text.MessageFormat; 105*cda5da8dSAndroid Build Coastguard Worker import java.util.ArrayList; 106*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[imports]])[ 107*cda5da8dSAndroid Build Coastguard Worker /** 108*cda5da8dSAndroid Build Coastguard Worker * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>. 109*cda5da8dSAndroid Build Coastguard Worker * 110*cda5da8dSAndroid Build Coastguard Worker * @@author LALR (1) parser skeleton written by Paolo Bonzini. 111*cda5da8dSAndroid Build Coastguard Worker */ 112*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class_declaration[ 113*cda5da8dSAndroid Build Coastguard Worker { 114*cda5da8dSAndroid Build Coastguard Worker ]b4_identification[ 115*cda5da8dSAndroid Build Coastguard Worker ][ 116*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch( 117*cda5da8dSAndroid Build Coastguard Worker [detailed\|verbose], [[ 118*cda5da8dSAndroid Build Coastguard Worker /** 119*cda5da8dSAndroid Build Coastguard Worker * True if verbose error messages are enabled. 120*cda5da8dSAndroid Build Coastguard Worker */ 121*cda5da8dSAndroid Build Coastguard Worker private boolean yyErrorVerbose = true; 122*cda5da8dSAndroid Build Coastguard Worker 123*cda5da8dSAndroid Build Coastguard Worker /** 124*cda5da8dSAndroid Build Coastguard Worker * Whether verbose error messages are enabled. 125*cda5da8dSAndroid Build Coastguard Worker */ 126*cda5da8dSAndroid Build Coastguard Worker public final boolean getErrorVerbose() { return yyErrorVerbose; } 127*cda5da8dSAndroid Build Coastguard Worker 128*cda5da8dSAndroid Build Coastguard Worker /** 129*cda5da8dSAndroid Build Coastguard Worker * Set the verbosity of error messages. 130*cda5da8dSAndroid Build Coastguard Worker * @@param verbose True to request verbose error messages. 131*cda5da8dSAndroid Build Coastguard Worker */ 132*cda5da8dSAndroid Build Coastguard Worker public final void setErrorVerbose(boolean verbose) 133*cda5da8dSAndroid Build Coastguard Worker { yyErrorVerbose = verbose; } 134*cda5da8dSAndroid Build Coastguard Worker ]])[ 135*cda5da8dSAndroid Build Coastguard Worker 136*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 137*cda5da8dSAndroid Build Coastguard Worker /** 138*cda5da8dSAndroid Build Coastguard Worker * A class defining a pair of positions. Positions, defined by the 139*cda5da8dSAndroid Build Coastguard Worker * <code>]b4_position_type[</code> class, denote a point in the input. 140*cda5da8dSAndroid Build Coastguard Worker * Locations represent a part of the input through the beginning 141*cda5da8dSAndroid Build Coastguard Worker * and ending positions. 142*cda5da8dSAndroid Build Coastguard Worker */ 143*cda5da8dSAndroid Build Coastguard Worker public static class ]b4_location_type[ { 144*cda5da8dSAndroid Build Coastguard Worker /** 145*cda5da8dSAndroid Build Coastguard Worker * The first, inclusive, position in the range. 146*cda5da8dSAndroid Build Coastguard Worker */ 147*cda5da8dSAndroid Build Coastguard Worker public ]b4_position_type[ begin; 148*cda5da8dSAndroid Build Coastguard Worker 149*cda5da8dSAndroid Build Coastguard Worker /** 150*cda5da8dSAndroid Build Coastguard Worker * The first position beyond the range. 151*cda5da8dSAndroid Build Coastguard Worker */ 152*cda5da8dSAndroid Build Coastguard Worker public ]b4_position_type[ end; 153*cda5da8dSAndroid Build Coastguard Worker 154*cda5da8dSAndroid Build Coastguard Worker /** 155*cda5da8dSAndroid Build Coastguard Worker * Create a <code>]b4_location_type[</code> denoting an empty range located at 156*cda5da8dSAndroid Build Coastguard Worker * a given point. 157*cda5da8dSAndroid Build Coastguard Worker * @@param loc The position at which the range is anchored. 158*cda5da8dSAndroid Build Coastguard Worker */ 159*cda5da8dSAndroid Build Coastguard Worker public ]b4_location_type[ (]b4_position_type[ loc) { 160*cda5da8dSAndroid Build Coastguard Worker this.begin = this.end = loc; 161*cda5da8dSAndroid Build Coastguard Worker } 162*cda5da8dSAndroid Build Coastguard Worker 163*cda5da8dSAndroid Build Coastguard Worker /** 164*cda5da8dSAndroid Build Coastguard Worker * Create a <code>]b4_location_type[</code> from the endpoints of the range. 165*cda5da8dSAndroid Build Coastguard Worker * @@param begin The first position included in the range. 166*cda5da8dSAndroid Build Coastguard Worker * @@param end The first position beyond the range. 167*cda5da8dSAndroid Build Coastguard Worker */ 168*cda5da8dSAndroid Build Coastguard Worker public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) { 169*cda5da8dSAndroid Build Coastguard Worker this.begin = begin; 170*cda5da8dSAndroid Build Coastguard Worker this.end = end; 171*cda5da8dSAndroid Build Coastguard Worker } 172*cda5da8dSAndroid Build Coastguard Worker 173*cda5da8dSAndroid Build Coastguard Worker /** 174*cda5da8dSAndroid Build Coastguard Worker * Print a representation of the location. For this to be correct, 175*cda5da8dSAndroid Build Coastguard Worker * <code>]b4_position_type[</code> should override the <code>equals</code> 176*cda5da8dSAndroid Build Coastguard Worker * method. 177*cda5da8dSAndroid Build Coastguard Worker */ 178*cda5da8dSAndroid Build Coastguard Worker public String toString() { 179*cda5da8dSAndroid Build Coastguard Worker if (begin.equals (end)) 180*cda5da8dSAndroid Build Coastguard Worker return begin.toString(); 181*cda5da8dSAndroid Build Coastguard Worker else 182*cda5da8dSAndroid Build Coastguard Worker return begin.toString() + "-" + end.toString(); 183*cda5da8dSAndroid Build Coastguard Worker } 184*cda5da8dSAndroid Build Coastguard Worker } 185*cda5da8dSAndroid Build Coastguard Worker 186*cda5da8dSAndroid Build Coastguard Worker private ]b4_location_type[ yylloc(YYStack rhs, int n) 187*cda5da8dSAndroid Build Coastguard Worker { 188*cda5da8dSAndroid Build Coastguard Worker if (0 < n) 189*cda5da8dSAndroid Build Coastguard Worker return new ]b4_location_type[(rhs.locationAt(n-1).begin, rhs.locationAt(0).end); 190*cda5da8dSAndroid Build Coastguard Worker else 191*cda5da8dSAndroid Build Coastguard Worker return new ]b4_location_type[(rhs.locationAt(0).end); 192*cda5da8dSAndroid Build Coastguard Worker }]])[ 193*cda5da8dSAndroid Build Coastguard Worker 194*cda5da8dSAndroid Build Coastguard Worker ]b4_declare_symbol_enum[ 195*cda5da8dSAndroid Build Coastguard Worker 196*cda5da8dSAndroid Build Coastguard Worker /** 197*cda5da8dSAndroid Build Coastguard Worker * Communication interface between the scanner and the Bison-generated 198*cda5da8dSAndroid Build Coastguard Worker * parser <tt>]b4_parser_class[</tt>. 199*cda5da8dSAndroid Build Coastguard Worker */ 200*cda5da8dSAndroid Build Coastguard Worker public interface Lexer { 201*cda5da8dSAndroid Build Coastguard Worker ]b4_token_enums[ 202*cda5da8dSAndroid Build Coastguard Worker /** Deprecated, use ]b4_symbol(eof, id)[ instead. */ 203*cda5da8dSAndroid Build Coastguard Worker public static final int EOF = ]b4_symbol(eof, id)[; 204*cda5da8dSAndroid Build Coastguard Worker ]b4_pull_if([b4_locations_if([[ 205*cda5da8dSAndroid Build Coastguard Worker /** 206*cda5da8dSAndroid Build Coastguard Worker * Method to retrieve the beginning position of the last scanned token. 207*cda5da8dSAndroid Build Coastguard Worker * @@return the position at which the last scanned token starts. 208*cda5da8dSAndroid Build Coastguard Worker */ 209*cda5da8dSAndroid Build Coastguard Worker ]b4_position_type[ getStartPos(); 210*cda5da8dSAndroid Build Coastguard Worker 211*cda5da8dSAndroid Build Coastguard Worker /** 212*cda5da8dSAndroid Build Coastguard Worker * Method to retrieve the ending position of the last scanned token. 213*cda5da8dSAndroid Build Coastguard Worker * @@return the first position beyond the last scanned token. 214*cda5da8dSAndroid Build Coastguard Worker */ 215*cda5da8dSAndroid Build Coastguard Worker ]b4_position_type[ getEndPos();]])[ 216*cda5da8dSAndroid Build Coastguard Worker 217*cda5da8dSAndroid Build Coastguard Worker /** 218*cda5da8dSAndroid Build Coastguard Worker * Method to retrieve the semantic value of the last scanned token. 219*cda5da8dSAndroid Build Coastguard Worker * @@return the semantic value of the last scanned token. 220*cda5da8dSAndroid Build Coastguard Worker */ 221*cda5da8dSAndroid Build Coastguard Worker ]b4_yystype[ getLVal(); 222*cda5da8dSAndroid Build Coastguard Worker 223*cda5da8dSAndroid Build Coastguard Worker /** 224*cda5da8dSAndroid Build Coastguard Worker * Entry point for the scanner. Returns the token identifier corresponding 225*cda5da8dSAndroid Build Coastguard Worker * to the next token and prepares to return the semantic value 226*cda5da8dSAndroid Build Coastguard Worker * ]b4_locations_if([and beginning/ending positions ])[of the token. 227*cda5da8dSAndroid Build Coastguard Worker * @@return the token identifier corresponding to the next token. 228*cda5da8dSAndroid Build Coastguard Worker */ 229*cda5da8dSAndroid Build Coastguard Worker int yylex()]b4_maybe_throws([b4_lex_throws])[; 230*cda5da8dSAndroid Build Coastguard Worker ]])[ 231*cda5da8dSAndroid Build Coastguard Worker /** 232*cda5da8dSAndroid Build Coastguard Worker * Emit an error]b4_locations_if([ referring to the given location])[in a user-defined way. 233*cda5da8dSAndroid Build Coastguard Worker * 234*cda5da8dSAndroid Build Coastguard Worker *]b4_locations_if([[ @@param loc The location of the element to which the 235*cda5da8dSAndroid Build Coastguard Worker * error message is related.]])[ 236*cda5da8dSAndroid Build Coastguard Worker * @@param msg The string for the error message. 237*cda5da8dSAndroid Build Coastguard Worker */ 238*cda5da8dSAndroid Build Coastguard Worker void yyerror(]b4_locations_if([b4_location_type[ loc, ]])[String msg); 239*cda5da8dSAndroid Build Coastguard Worker 240*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch( 241*cda5da8dSAndroid Build Coastguard Worker [custom], [[ 242*cda5da8dSAndroid Build Coastguard Worker /** 243*cda5da8dSAndroid Build Coastguard Worker * Build and emit a "syntax error" message in a user-defined way. 244*cda5da8dSAndroid Build Coastguard Worker * 245*cda5da8dSAndroid Build Coastguard Worker * @@param ctx The context of the error. 246*cda5da8dSAndroid Build Coastguard Worker */ 247*cda5da8dSAndroid Build Coastguard Worker void reportSyntaxError(Context ctx); 248*cda5da8dSAndroid Build Coastguard Worker ]])[ 249*cda5da8dSAndroid Build Coastguard Worker } 250*cda5da8dSAndroid Build Coastguard Worker 251*cda5da8dSAndroid Build Coastguard Worker ]b4_lexer_if([[ 252*cda5da8dSAndroid Build Coastguard Worker private class YYLexer implements Lexer { 253*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[lexer]])[ 254*cda5da8dSAndroid Build Coastguard Worker } 255*cda5da8dSAndroid Build Coastguard Worker 256*cda5da8dSAndroid Build Coastguard Worker ]])[ 257*cda5da8dSAndroid Build Coastguard Worker /** 258*cda5da8dSAndroid Build Coastguard Worker * The object doing lexical analysis for us. 259*cda5da8dSAndroid Build Coastguard Worker */ 260*cda5da8dSAndroid Build Coastguard Worker private Lexer yylexer; 261*cda5da8dSAndroid Build Coastguard Worker 262*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_vars[ 263*cda5da8dSAndroid Build Coastguard Worker 264*cda5da8dSAndroid Build Coastguard Worker ]b4_lexer_if([[ 265*cda5da8dSAndroid Build Coastguard Worker /** 266*cda5da8dSAndroid Build Coastguard Worker * Instantiates the Bison-generated parser. 267*cda5da8dSAndroid Build Coastguard Worker */ 268*cda5da8dSAndroid Build Coastguard Worker public ]b4_parser_class[(]b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[ 269*cda5da8dSAndroid Build Coastguard Worker { 270*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[init]])[]b4_lac_if([[ 271*cda5da8dSAndroid Build Coastguard Worker this.yylacStack = new ArrayList<Integer>(); 272*cda5da8dSAndroid Build Coastguard Worker this.yylacEstablished = false;]])[ 273*cda5da8dSAndroid Build Coastguard Worker this.yylexer = new YYLexer(]b4_lex_param_call[); 274*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_cons[ 275*cda5da8dSAndroid Build Coastguard Worker } 276*cda5da8dSAndroid Build Coastguard Worker ]])[ 277*cda5da8dSAndroid Build Coastguard Worker 278*cda5da8dSAndroid Build Coastguard Worker /** 279*cda5da8dSAndroid Build Coastguard Worker * Instantiates the Bison-generated parser. 280*cda5da8dSAndroid Build Coastguard Worker * @@param yylexer The scanner that will supply tokens to the parser. 281*cda5da8dSAndroid Build Coastguard Worker */ 282*cda5da8dSAndroid Build Coastguard Worker ]b4_lexer_if([[protected]], [[public]]) b4_parser_class[(]b4_parse_param_decl([[Lexer yylexer]])[)]b4_maybe_throws([b4_init_throws])[ 283*cda5da8dSAndroid Build Coastguard Worker { 284*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[init]])[]b4_lac_if([[ 285*cda5da8dSAndroid Build Coastguard Worker this.yylacStack = new ArrayList<Integer>(); 286*cda5da8dSAndroid Build Coastguard Worker this.yylacEstablished = false;]])[ 287*cda5da8dSAndroid Build Coastguard Worker this.yylexer = yylexer; 288*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_cons[ 289*cda5da8dSAndroid Build Coastguard Worker } 290*cda5da8dSAndroid Build Coastguard Worker 291*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_trace_if([[ 292*cda5da8dSAndroid Build Coastguard Worker private java.io.PrintStream yyDebugStream = System.err; 293*cda5da8dSAndroid Build Coastguard Worker 294*cda5da8dSAndroid Build Coastguard Worker /** 295*cda5da8dSAndroid Build Coastguard Worker * The <tt>PrintStream</tt> on which the debugging output is printed. 296*cda5da8dSAndroid Build Coastguard Worker */ 297*cda5da8dSAndroid Build Coastguard Worker public final java.io.PrintStream getDebugStream() { return yyDebugStream; } 298*cda5da8dSAndroid Build Coastguard Worker 299*cda5da8dSAndroid Build Coastguard Worker /** 300*cda5da8dSAndroid Build Coastguard Worker * Set the <tt>PrintStream</tt> on which the debug output is printed. 301*cda5da8dSAndroid Build Coastguard Worker * @@param s The stream that is used for debugging output. 302*cda5da8dSAndroid Build Coastguard Worker */ 303*cda5da8dSAndroid Build Coastguard Worker public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; } 304*cda5da8dSAndroid Build Coastguard Worker 305*cda5da8dSAndroid Build Coastguard Worker private int yydebug = 0; 306*cda5da8dSAndroid Build Coastguard Worker 307*cda5da8dSAndroid Build Coastguard Worker /** 308*cda5da8dSAndroid Build Coastguard Worker * Answer the verbosity of the debugging output; 0 means that all kinds of 309*cda5da8dSAndroid Build Coastguard Worker * output from the parser are suppressed. 310*cda5da8dSAndroid Build Coastguard Worker */ 311*cda5da8dSAndroid Build Coastguard Worker public final int getDebugLevel() { return yydebug; } 312*cda5da8dSAndroid Build Coastguard Worker 313*cda5da8dSAndroid Build Coastguard Worker /** 314*cda5da8dSAndroid Build Coastguard Worker * Set the verbosity of the debugging output; 0 means that all kinds of 315*cda5da8dSAndroid Build Coastguard Worker * output from the parser are suppressed. 316*cda5da8dSAndroid Build Coastguard Worker * @@param level The verbosity level for debugging output. 317*cda5da8dSAndroid Build Coastguard Worker */ 318*cda5da8dSAndroid Build Coastguard Worker public final void setDebugLevel(int level) { yydebug = level; } 319*cda5da8dSAndroid Build Coastguard Worker ]])[ 320*cda5da8dSAndroid Build Coastguard Worker 321*cda5da8dSAndroid Build Coastguard Worker private int yynerrs = 0; 322*cda5da8dSAndroid Build Coastguard Worker 323*cda5da8dSAndroid Build Coastguard Worker /** 324*cda5da8dSAndroid Build Coastguard Worker * The number of syntax errors so far. 325*cda5da8dSAndroid Build Coastguard Worker */ 326*cda5da8dSAndroid Build Coastguard Worker public final int getNumberOfErrors() { return yynerrs; } 327*cda5da8dSAndroid Build Coastguard Worker 328*cda5da8dSAndroid Build Coastguard Worker /** 329*cda5da8dSAndroid Build Coastguard Worker * Print an error message via the lexer. 330*cda5da8dSAndroid Build Coastguard Worker *]b4_locations_if([[ Use a <code>null</code> location.]])[ 331*cda5da8dSAndroid Build Coastguard Worker * @@param msg The error message. 332*cda5da8dSAndroid Build Coastguard Worker */ 333*cda5da8dSAndroid Build Coastguard Worker public final void yyerror(String msg) { 334*cda5da8dSAndroid Build Coastguard Worker yylexer.yyerror(]b4_locations_if([[(]b4_location_type[)null, ]])[msg); 335*cda5da8dSAndroid Build Coastguard Worker } 336*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 337*cda5da8dSAndroid Build Coastguard Worker /** 338*cda5da8dSAndroid Build Coastguard Worker * Print an error message via the lexer. 339*cda5da8dSAndroid Build Coastguard Worker * @@param loc The location associated with the message. 340*cda5da8dSAndroid Build Coastguard Worker * @@param msg The error message. 341*cda5da8dSAndroid Build Coastguard Worker */ 342*cda5da8dSAndroid Build Coastguard Worker public final void yyerror(]b4_location_type[ loc, String msg) { 343*cda5da8dSAndroid Build Coastguard Worker yylexer.yyerror(loc, msg); 344*cda5da8dSAndroid Build Coastguard Worker } 345*cda5da8dSAndroid Build Coastguard Worker 346*cda5da8dSAndroid Build Coastguard Worker /** 347*cda5da8dSAndroid Build Coastguard Worker * Print an error message via the lexer. 348*cda5da8dSAndroid Build Coastguard Worker * @@param pos The position associated with the message. 349*cda5da8dSAndroid Build Coastguard Worker * @@param msg The error message. 350*cda5da8dSAndroid Build Coastguard Worker */ 351*cda5da8dSAndroid Build Coastguard Worker public final void yyerror(]b4_position_type[ pos, String msg) { 352*cda5da8dSAndroid Build Coastguard Worker yylexer.yyerror(new ]b4_location_type[ (pos), msg); 353*cda5da8dSAndroid Build Coastguard Worker }]])[ 354*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_trace_if([[ 355*cda5da8dSAndroid Build Coastguard Worker protected final void yycdebugNnl(String s) { 356*cda5da8dSAndroid Build Coastguard Worker if (0 < yydebug) 357*cda5da8dSAndroid Build Coastguard Worker yyDebugStream.print(s); 358*cda5da8dSAndroid Build Coastguard Worker } 359*cda5da8dSAndroid Build Coastguard Worker 360*cda5da8dSAndroid Build Coastguard Worker protected final void yycdebug(String s) { 361*cda5da8dSAndroid Build Coastguard Worker if (0 < yydebug) 362*cda5da8dSAndroid Build Coastguard Worker yyDebugStream.println(s); 363*cda5da8dSAndroid Build Coastguard Worker }]])[ 364*cda5da8dSAndroid Build Coastguard Worker 365*cda5da8dSAndroid Build Coastguard Worker private final class YYStack { 366*cda5da8dSAndroid Build Coastguard Worker private int[] stateStack = new int[16];]b4_locations_if([[ 367*cda5da8dSAndroid Build Coastguard Worker private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[ 368*cda5da8dSAndroid Build Coastguard Worker private ]b4_yystype[[] valueStack = new ]b4_yystype[[16]; 369*cda5da8dSAndroid Build Coastguard Worker 370*cda5da8dSAndroid Build Coastguard Worker public int size = 16; 371*cda5da8dSAndroid Build Coastguard Worker public int height = -1; 372*cda5da8dSAndroid Build Coastguard Worker 373*cda5da8dSAndroid Build Coastguard Worker public final void push(int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) { 374*cda5da8dSAndroid Build Coastguard Worker height++; 375*cda5da8dSAndroid Build Coastguard Worker if (size == height) { 376*cda5da8dSAndroid Build Coastguard Worker int[] newStateStack = new int[size * 2]; 377*cda5da8dSAndroid Build Coastguard Worker System.arraycopy(stateStack, 0, newStateStack, 0, height); 378*cda5da8dSAndroid Build Coastguard Worker stateStack = newStateStack;]b4_locations_if([[ 379*cda5da8dSAndroid Build Coastguard Worker ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2]; 380*cda5da8dSAndroid Build Coastguard Worker System.arraycopy(locStack, 0, newLocStack, 0, height); 381*cda5da8dSAndroid Build Coastguard Worker locStack = newLocStack;]]) 382*cda5da8dSAndroid Build Coastguard Worker 383*cda5da8dSAndroid Build Coastguard Worker b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2]; 384*cda5da8dSAndroid Build Coastguard Worker System.arraycopy(valueStack, 0, newValueStack, 0, height); 385*cda5da8dSAndroid Build Coastguard Worker valueStack = newValueStack; 386*cda5da8dSAndroid Build Coastguard Worker 387*cda5da8dSAndroid Build Coastguard Worker size *= 2; 388*cda5da8dSAndroid Build Coastguard Worker } 389*cda5da8dSAndroid Build Coastguard Worker 390*cda5da8dSAndroid Build Coastguard Worker stateStack[height] = state;]b4_locations_if([[ 391*cda5da8dSAndroid Build Coastguard Worker locStack[height] = loc;]])[ 392*cda5da8dSAndroid Build Coastguard Worker valueStack[height] = value; 393*cda5da8dSAndroid Build Coastguard Worker } 394*cda5da8dSAndroid Build Coastguard Worker 395*cda5da8dSAndroid Build Coastguard Worker public final void pop() { 396*cda5da8dSAndroid Build Coastguard Worker pop(1); 397*cda5da8dSAndroid Build Coastguard Worker } 398*cda5da8dSAndroid Build Coastguard Worker 399*cda5da8dSAndroid Build Coastguard Worker public final void pop(int num) { 400*cda5da8dSAndroid Build Coastguard Worker // Avoid memory leaks... garbage collection is a white lie! 401*cda5da8dSAndroid Build Coastguard Worker if (0 < num) { 402*cda5da8dSAndroid Build Coastguard Worker java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);]b4_locations_if([[ 403*cda5da8dSAndroid Build Coastguard Worker java.util.Arrays.fill(locStack, height - num + 1, height + 1, null);]])[ 404*cda5da8dSAndroid Build Coastguard Worker } 405*cda5da8dSAndroid Build Coastguard Worker height -= num; 406*cda5da8dSAndroid Build Coastguard Worker } 407*cda5da8dSAndroid Build Coastguard Worker 408*cda5da8dSAndroid Build Coastguard Worker public final int stateAt(int i) { 409*cda5da8dSAndroid Build Coastguard Worker return stateStack[height - i]; 410*cda5da8dSAndroid Build Coastguard Worker } 411*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 412*cda5da8dSAndroid Build Coastguard Worker 413*cda5da8dSAndroid Build Coastguard Worker public final ]b4_location_type[ locationAt(int i) { 414*cda5da8dSAndroid Build Coastguard Worker return locStack[height - i]; 415*cda5da8dSAndroid Build Coastguard Worker } 416*cda5da8dSAndroid Build Coastguard Worker ]])[ 417*cda5da8dSAndroid Build Coastguard Worker public final ]b4_yystype[ valueAt(int i) { 418*cda5da8dSAndroid Build Coastguard Worker return valueStack[height - i]; 419*cda5da8dSAndroid Build Coastguard Worker } 420*cda5da8dSAndroid Build Coastguard Worker 421*cda5da8dSAndroid Build Coastguard Worker // Print the state stack on the debug stream. 422*cda5da8dSAndroid Build Coastguard Worker public void print(java.io.PrintStream out) { 423*cda5da8dSAndroid Build Coastguard Worker out.print ("Stack now"); 424*cda5da8dSAndroid Build Coastguard Worker 425*cda5da8dSAndroid Build Coastguard Worker for (int i = 0; i <= height; i++) { 426*cda5da8dSAndroid Build Coastguard Worker out.print(' '); 427*cda5da8dSAndroid Build Coastguard Worker out.print(stateStack[i]); 428*cda5da8dSAndroid Build Coastguard Worker } 429*cda5da8dSAndroid Build Coastguard Worker out.println(); 430*cda5da8dSAndroid Build Coastguard Worker } 431*cda5da8dSAndroid Build Coastguard Worker } 432*cda5da8dSAndroid Build Coastguard Worker 433*cda5da8dSAndroid Build Coastguard Worker /** 434*cda5da8dSAndroid Build Coastguard Worker * Returned by a Bison action in order to stop the parsing process and 435*cda5da8dSAndroid Build Coastguard Worker * return success (<tt>true</tt>). 436*cda5da8dSAndroid Build Coastguard Worker */ 437*cda5da8dSAndroid Build Coastguard Worker public static final int YYACCEPT = 0; 438*cda5da8dSAndroid Build Coastguard Worker 439*cda5da8dSAndroid Build Coastguard Worker /** 440*cda5da8dSAndroid Build Coastguard Worker * Returned by a Bison action in order to stop the parsing process and 441*cda5da8dSAndroid Build Coastguard Worker * return failure (<tt>false</tt>). 442*cda5da8dSAndroid Build Coastguard Worker */ 443*cda5da8dSAndroid Build Coastguard Worker public static final int YYABORT = 1; 444*cda5da8dSAndroid Build Coastguard Worker 445*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([ 446*cda5da8dSAndroid Build Coastguard Worker /** 447*cda5da8dSAndroid Build Coastguard Worker * Returned by a Bison action in order to request a new token. 448*cda5da8dSAndroid Build Coastguard Worker */ 449*cda5da8dSAndroid Build Coastguard Worker public static final int YYPUSH_MORE = 4;])[ 450*cda5da8dSAndroid Build Coastguard Worker 451*cda5da8dSAndroid Build Coastguard Worker /** 452*cda5da8dSAndroid Build Coastguard Worker * Returned by a Bison action in order to start error recovery without 453*cda5da8dSAndroid Build Coastguard Worker * printing an error message. 454*cda5da8dSAndroid Build Coastguard Worker */ 455*cda5da8dSAndroid Build Coastguard Worker public static final int YYERROR = 2; 456*cda5da8dSAndroid Build Coastguard Worker 457*cda5da8dSAndroid Build Coastguard Worker /** 458*cda5da8dSAndroid Build Coastguard Worker * Internal return codes that are not supported for user semantic 459*cda5da8dSAndroid Build Coastguard Worker * actions. 460*cda5da8dSAndroid Build Coastguard Worker */ 461*cda5da8dSAndroid Build Coastguard Worker private static final int YYERRLAB = 3; 462*cda5da8dSAndroid Build Coastguard Worker private static final int YYNEWSTATE = 4; 463*cda5da8dSAndroid Build Coastguard Worker private static final int YYDEFAULT = 5; 464*cda5da8dSAndroid Build Coastguard Worker private static final int YYREDUCE = 6; 465*cda5da8dSAndroid Build Coastguard Worker private static final int YYERRLAB1 = 7; 466*cda5da8dSAndroid Build Coastguard Worker private static final int YYRETURN = 8; 467*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([[ private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[ 468*cda5da8dSAndroid Build Coastguard Worker 469*cda5da8dSAndroid Build Coastguard Worker private int yyerrstatus_ = 0; 470*cda5da8dSAndroid Build Coastguard Worker 471*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([b4_define_state])[ 472*cda5da8dSAndroid Build Coastguard Worker /** 473*cda5da8dSAndroid Build Coastguard Worker * Whether error recovery is being done. In this state, the parser 474*cda5da8dSAndroid Build Coastguard Worker * reads token until it reaches a known state, and then restarts normal 475*cda5da8dSAndroid Build Coastguard Worker * operation. 476*cda5da8dSAndroid Build Coastguard Worker */ 477*cda5da8dSAndroid Build Coastguard Worker public final boolean recovering () 478*cda5da8dSAndroid Build Coastguard Worker { 479*cda5da8dSAndroid Build Coastguard Worker return yyerrstatus_ == 0; 480*cda5da8dSAndroid Build Coastguard Worker } 481*cda5da8dSAndroid Build Coastguard Worker 482*cda5da8dSAndroid Build Coastguard Worker /** Compute post-reduction state. 483*cda5da8dSAndroid Build Coastguard Worker * @@param yystate the current state 484*cda5da8dSAndroid Build Coastguard Worker * @@param yysym the nonterminal to push on the stack 485*cda5da8dSAndroid Build Coastguard Worker */ 486*cda5da8dSAndroid Build Coastguard Worker private int yyLRGotoState(int yystate, int yysym) { 487*cda5da8dSAndroid Build Coastguard Worker int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate; 488*cda5da8dSAndroid Build Coastguard Worker if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate) 489*cda5da8dSAndroid Build Coastguard Worker return yytable_[yyr]; 490*cda5da8dSAndroid Build Coastguard Worker else 491*cda5da8dSAndroid Build Coastguard Worker return yydefgoto_[yysym - YYNTOKENS_]; 492*cda5da8dSAndroid Build Coastguard Worker } 493*cda5da8dSAndroid Build Coastguard Worker 494*cda5da8dSAndroid Build Coastguard Worker private int yyaction(int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[ 495*cda5da8dSAndroid Build Coastguard Worker { 496*cda5da8dSAndroid Build Coastguard Worker /* If YYLEN is nonzero, implement the default value of the action: 497*cda5da8dSAndroid Build Coastguard Worker '$$ = $1'. Otherwise, use the top of the stack. 498*cda5da8dSAndroid Build Coastguard Worker 499*cda5da8dSAndroid Build Coastguard Worker Otherwise, the following line sets YYVAL to garbage. 500*cda5da8dSAndroid Build Coastguard Worker This behavior is undocumented and Bison 501*cda5da8dSAndroid Build Coastguard Worker users should not rely upon it. */ 502*cda5da8dSAndroid Build Coastguard Worker ]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt(yylen - 1) : yystack.valueAt(0);]b4_locations_if([[ 503*cda5da8dSAndroid Build Coastguard Worker ]b4_location_type[ yyloc = yylloc(yystack, yylen);]])[]b4_parse_trace_if([[ 504*cda5da8dSAndroid Build Coastguard Worker 505*cda5da8dSAndroid Build Coastguard Worker yyReducePrint(yyn, yystack);]])[ 506*cda5da8dSAndroid Build Coastguard Worker 507*cda5da8dSAndroid Build Coastguard Worker switch (yyn) 508*cda5da8dSAndroid Build Coastguard Worker { 509*cda5da8dSAndroid Build Coastguard Worker ]b4_user_actions[ 510*cda5da8dSAndroid Build Coastguard Worker default: break; 511*cda5da8dSAndroid Build Coastguard Worker }]b4_parse_trace_if([[ 512*cda5da8dSAndroid Build Coastguard Worker 513*cda5da8dSAndroid Build Coastguard Worker yySymbolPrint("-> $$ =", SymbolKind.get(yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[ 514*cda5da8dSAndroid Build Coastguard Worker 515*cda5da8dSAndroid Build Coastguard Worker yystack.pop(yylen); 516*cda5da8dSAndroid Build Coastguard Worker yylen = 0; 517*cda5da8dSAndroid Build Coastguard Worker /* Shift the result of the reduction. */ 518*cda5da8dSAndroid Build Coastguard Worker int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]); 519*cda5da8dSAndroid Build Coastguard Worker yystack.push(yystate, yyval]b4_locations_if([, yyloc])[); 520*cda5da8dSAndroid Build Coastguard Worker return YYNEWSTATE; 521*cda5da8dSAndroid Build Coastguard Worker } 522*cda5da8dSAndroid Build Coastguard Worker 523*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_trace_if([[ 524*cda5da8dSAndroid Build Coastguard Worker /*--------------------------------. 525*cda5da8dSAndroid Build Coastguard Worker | Print this symbol on YYOUTPUT. | 526*cda5da8dSAndroid Build Coastguard Worker `--------------------------------*/ 527*cda5da8dSAndroid Build Coastguard Worker 528*cda5da8dSAndroid Build Coastguard Worker private void yySymbolPrint(String s, SymbolKind yykind, 529*cda5da8dSAndroid Build Coastguard Worker ]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[) { 530*cda5da8dSAndroid Build Coastguard Worker if (0 < yydebug) { 531*cda5da8dSAndroid Build Coastguard Worker yycdebug(s 532*cda5da8dSAndroid Build Coastguard Worker + (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ") 533*cda5da8dSAndroid Build Coastguard Worker + yykind.getName() + " ("]b4_locations_if([ 534*cda5da8dSAndroid Build Coastguard Worker + yylocation + ": "])[ 535*cda5da8dSAndroid Build Coastguard Worker + (yyvalue == null ? "(null)" : yyvalue.toString()) + ")"); 536*cda5da8dSAndroid Build Coastguard Worker } 537*cda5da8dSAndroid Build Coastguard Worker }]])[ 538*cda5da8dSAndroid Build Coastguard Worker 539*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([],[[ 540*cda5da8dSAndroid Build Coastguard Worker /** 541*cda5da8dSAndroid Build Coastguard Worker * Parse input from the scanner that was specified at object construction 542*cda5da8dSAndroid Build Coastguard Worker * time. Return whether the end of the input was reached successfully. 543*cda5da8dSAndroid Build Coastguard Worker * 544*cda5da8dSAndroid Build Coastguard Worker * @@return <tt>true</tt> if the parsing succeeds. Note that this does not 545*cda5da8dSAndroid Build Coastguard Worker * imply that there were no syntax errors. 546*cda5da8dSAndroid Build Coastguard Worker */ 547*cda5da8dSAndroid Build Coastguard Worker public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[ 548*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([ 549*cda5da8dSAndroid Build Coastguard Worker /** 550*cda5da8dSAndroid Build Coastguard Worker * Push Parse input from external lexer 551*cda5da8dSAndroid Build Coastguard Worker * 552*cda5da8dSAndroid Build Coastguard Worker * @@param yylextoken current token 553*cda5da8dSAndroid Build Coastguard Worker * @@param yylexval current lval]b4_locations_if([[ 554*cda5da8dSAndroid Build Coastguard Worker * @@param yylexloc current position]])[ 555*cda5da8dSAndroid Build Coastguard Worker * 556*cda5da8dSAndroid Build Coastguard Worker * @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt> 557*cda5da8dSAndroid Build Coastguard Worker */ 558*cda5da8dSAndroid Build Coastguard Worker public int push_parse(int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[ 559*cda5da8dSAndroid Build Coastguard Worker {]b4_locations_if([[ 560*cda5da8dSAndroid Build Coastguard Worker /* @@$. */ 561*cda5da8dSAndroid Build Coastguard Worker ]b4_location_type[ yyloc;]])[ 562*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([],[[ 563*cda5da8dSAndroid Build Coastguard Worker ]b4_define_state[ 564*cda5da8dSAndroid Build Coastguard Worker ]b4_lac_if([[ 565*cda5da8dSAndroid Build Coastguard Worker // Discard the LAC context in case there still is one left from a 566*cda5da8dSAndroid Build Coastguard Worker // previous invocation. 567*cda5da8dSAndroid Build Coastguard Worker yylacDiscard("init");]])[ 568*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_trace_if([[ 569*cda5da8dSAndroid Build Coastguard Worker yycdebug ("Starting parse");]])[ 570*cda5da8dSAndroid Build Coastguard Worker yyerrstatus_ = 0; 571*cda5da8dSAndroid Build Coastguard Worker yynerrs = 0; 572*cda5da8dSAndroid Build Coastguard Worker 573*cda5da8dSAndroid Build Coastguard Worker /* Initialize the stack. */ 574*cda5da8dSAndroid Build Coastguard Worker yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); 575*cda5da8dSAndroid Build Coastguard Worker ]m4_ifdef([b4_initial_action], [ 576*cda5da8dSAndroid Build Coastguard Worker b4_dollar_pushdef([yylval], [], [], [yylloc])dnl 577*cda5da8dSAndroid Build Coastguard Worker b4_user_initial_action 578*cda5da8dSAndroid Build Coastguard Worker b4_dollar_popdef[]dnl 579*cda5da8dSAndroid Build Coastguard Worker ])[ 580*cda5da8dSAndroid Build Coastguard Worker ]])[ 581*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([[ 582*cda5da8dSAndroid Build Coastguard Worker if (!this.push_parse_initialized) 583*cda5da8dSAndroid Build Coastguard Worker { 584*cda5da8dSAndroid Build Coastguard Worker push_parse_initialize (); 585*cda5da8dSAndroid Build Coastguard Worker ]m4_ifdef([b4_initial_action], [ 586*cda5da8dSAndroid Build Coastguard Worker b4_dollar_pushdef([yylval], [], [], [yylloc])dnl 587*cda5da8dSAndroid Build Coastguard Worker b4_user_initial_action 588*cda5da8dSAndroid Build Coastguard Worker b4_dollar_popdef[]dnl 589*cda5da8dSAndroid Build Coastguard Worker ])[]b4_parse_trace_if([[ 590*cda5da8dSAndroid Build Coastguard Worker yycdebug ("Starting parse");]])[ 591*cda5da8dSAndroid Build Coastguard Worker yyerrstatus_ = 0; 592*cda5da8dSAndroid Build Coastguard Worker } else 593*cda5da8dSAndroid Build Coastguard Worker label = YYGETTOKEN; 594*cda5da8dSAndroid Build Coastguard Worker 595*cda5da8dSAndroid Build Coastguard Worker boolean push_token_consumed = true; 596*cda5da8dSAndroid Build Coastguard Worker ]])[ 597*cda5da8dSAndroid Build Coastguard Worker for (;;) 598*cda5da8dSAndroid Build Coastguard Worker switch (label) 599*cda5da8dSAndroid Build Coastguard Worker { 600*cda5da8dSAndroid Build Coastguard Worker /* New state. Unlike in the C/C++ skeletons, the state is already 601*cda5da8dSAndroid Build Coastguard Worker pushed when we come here. */ 602*cda5da8dSAndroid Build Coastguard Worker case YYNEWSTATE:]b4_parse_trace_if([[ 603*cda5da8dSAndroid Build Coastguard Worker yycdebug ("Entering state " + yystate); 604*cda5da8dSAndroid Build Coastguard Worker if (0 < yydebug) 605*cda5da8dSAndroid Build Coastguard Worker yystack.print (yyDebugStream);]])[ 606*cda5da8dSAndroid Build Coastguard Worker 607*cda5da8dSAndroid Build Coastguard Worker /* Accept? */ 608*cda5da8dSAndroid Build Coastguard Worker if (yystate == YYFINAL_) 609*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([{label = YYACCEPT; break;}], 610*cda5da8dSAndroid Build Coastguard Worker [return true;])[ 611*cda5da8dSAndroid Build Coastguard Worker 612*cda5da8dSAndroid Build Coastguard Worker /* Take a decision. First try without lookahead. */ 613*cda5da8dSAndroid Build Coastguard Worker yyn = yypact_[yystate]; 614*cda5da8dSAndroid Build Coastguard Worker if (yyPactValueIsDefault (yyn)) 615*cda5da8dSAndroid Build Coastguard Worker { 616*cda5da8dSAndroid Build Coastguard Worker label = YYDEFAULT; 617*cda5da8dSAndroid Build Coastguard Worker break; 618*cda5da8dSAndroid Build Coastguard Worker } 619*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([ /* Fall Through */ 620*cda5da8dSAndroid Build Coastguard Worker 621*cda5da8dSAndroid Build Coastguard Worker case YYGETTOKEN:])[ 622*cda5da8dSAndroid Build Coastguard Worker /* Read a lookahead token. */ 623*cda5da8dSAndroid Build Coastguard Worker if (yychar == YYEMPTY_) 624*cda5da8dSAndroid Build Coastguard Worker { 625*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([[ 626*cda5da8dSAndroid Build Coastguard Worker if (!push_token_consumed) 627*cda5da8dSAndroid Build Coastguard Worker return YYPUSH_MORE;]b4_parse_trace_if([[ 628*cda5da8dSAndroid Build Coastguard Worker yycdebug ("Reading a token");]])[ 629*cda5da8dSAndroid Build Coastguard Worker yychar = yylextoken; 630*cda5da8dSAndroid Build Coastguard Worker yylval = yylexval;]b4_locations_if([ 631*cda5da8dSAndroid Build Coastguard Worker yylloc = yylexloc;])[ 632*cda5da8dSAndroid Build Coastguard Worker push_token_consumed = false;]], [b4_parse_trace_if([[ 633*cda5da8dSAndroid Build Coastguard Worker yycdebug ("Reading a token");]])[ 634*cda5da8dSAndroid Build Coastguard Worker yychar = yylexer.yylex (); 635*cda5da8dSAndroid Build Coastguard Worker yylval = yylexer.getLVal();]b4_locations_if([[ 636*cda5da8dSAndroid Build Coastguard Worker yylloc = new ]b4_location_type[(yylexer.getStartPos(), 637*cda5da8dSAndroid Build Coastguard Worker yylexer.getEndPos());]])[ 638*cda5da8dSAndroid Build Coastguard Worker ]])[ 639*cda5da8dSAndroid Build Coastguard Worker } 640*cda5da8dSAndroid Build Coastguard Worker 641*cda5da8dSAndroid Build Coastguard Worker /* Convert token to internal form. */ 642*cda5da8dSAndroid Build Coastguard Worker yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[ 643*cda5da8dSAndroid Build Coastguard Worker yySymbolPrint("Next token is", yytoken, 644*cda5da8dSAndroid Build Coastguard Worker yylval]b4_locations_if([, yylloc])[);]])[ 645*cda5da8dSAndroid Build Coastguard Worker 646*cda5da8dSAndroid Build Coastguard Worker if (yytoken == ]b4_symbol(error, kind)[) 647*cda5da8dSAndroid Build Coastguard Worker { 648*cda5da8dSAndroid Build Coastguard Worker // The scanner already issued an error message, process directly 649*cda5da8dSAndroid Build Coastguard Worker // to error recovery. But do not keep the error token as 650*cda5da8dSAndroid Build Coastguard Worker // lookahead, it is too special and may lead us to an endless 651*cda5da8dSAndroid Build Coastguard Worker // loop in error recovery. */ 652*cda5da8dSAndroid Build Coastguard Worker yychar = Lexer.]b4_symbol(undef, id)[; 653*cda5da8dSAndroid Build Coastguard Worker yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[ 654*cda5da8dSAndroid Build Coastguard Worker yyerrloc = yylloc;]])[ 655*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB1; 656*cda5da8dSAndroid Build Coastguard Worker } 657*cda5da8dSAndroid Build Coastguard Worker else 658*cda5da8dSAndroid Build Coastguard Worker { 659*cda5da8dSAndroid Build Coastguard Worker /* If the proper action on seeing token YYTOKEN is to reduce or to 660*cda5da8dSAndroid Build Coastguard Worker detect an error, take that action. */ 661*cda5da8dSAndroid Build Coastguard Worker yyn += yytoken.getCode(); 662*cda5da8dSAndroid Build Coastguard Worker if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) {]b4_lac_if([[ 663*cda5da8dSAndroid Build Coastguard Worker if (!yylacEstablish(yystack, yytoken)) { 664*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB; 665*cda5da8dSAndroid Build Coastguard Worker } else]])[ 666*cda5da8dSAndroid Build Coastguard Worker label = YYDEFAULT; 667*cda5da8dSAndroid Build Coastguard Worker } 668*cda5da8dSAndroid Build Coastguard Worker 669*cda5da8dSAndroid Build Coastguard Worker /* <= 0 means reduce or error. */ 670*cda5da8dSAndroid Build Coastguard Worker else if ((yyn = yytable_[yyn]) <= 0) 671*cda5da8dSAndroid Build Coastguard Worker { 672*cda5da8dSAndroid Build Coastguard Worker if (yyTableValueIsError(yyn)) { 673*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB; 674*cda5da8dSAndroid Build Coastguard Worker }]b4_lac_if([[ else if (!yylacEstablish(yystack, yytoken)) { 675*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB; 676*cda5da8dSAndroid Build Coastguard Worker }]])[ else { 677*cda5da8dSAndroid Build Coastguard Worker yyn = -yyn; 678*cda5da8dSAndroid Build Coastguard Worker label = YYREDUCE; 679*cda5da8dSAndroid Build Coastguard Worker } 680*cda5da8dSAndroid Build Coastguard Worker } 681*cda5da8dSAndroid Build Coastguard Worker 682*cda5da8dSAndroid Build Coastguard Worker else 683*cda5da8dSAndroid Build Coastguard Worker { 684*cda5da8dSAndroid Build Coastguard Worker /* Shift the lookahead token. */]b4_parse_trace_if([[ 685*cda5da8dSAndroid Build Coastguard Worker yySymbolPrint("Shifting", yytoken, 686*cda5da8dSAndroid Build Coastguard Worker yylval]b4_locations_if([, yylloc])[); 687*cda5da8dSAndroid Build Coastguard Worker ]])[ 688*cda5da8dSAndroid Build Coastguard Worker /* Discard the token being shifted. */ 689*cda5da8dSAndroid Build Coastguard Worker yychar = YYEMPTY_; 690*cda5da8dSAndroid Build Coastguard Worker 691*cda5da8dSAndroid Build Coastguard Worker /* Count tokens shifted since error; after three, turn off error 692*cda5da8dSAndroid Build Coastguard Worker status. */ 693*cda5da8dSAndroid Build Coastguard Worker if (yyerrstatus_ > 0) 694*cda5da8dSAndroid Build Coastguard Worker --yyerrstatus_; 695*cda5da8dSAndroid Build Coastguard Worker 696*cda5da8dSAndroid Build Coastguard Worker yystate = yyn; 697*cda5da8dSAndroid Build Coastguard Worker yystack.push(yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[ 698*cda5da8dSAndroid Build Coastguard Worker yylacDiscard("shift");]])[ 699*cda5da8dSAndroid Build Coastguard Worker label = YYNEWSTATE; 700*cda5da8dSAndroid Build Coastguard Worker } 701*cda5da8dSAndroid Build Coastguard Worker } 702*cda5da8dSAndroid Build Coastguard Worker break; 703*cda5da8dSAndroid Build Coastguard Worker 704*cda5da8dSAndroid Build Coastguard Worker /*-----------------------------------------------------------. 705*cda5da8dSAndroid Build Coastguard Worker | yydefault -- do the default action for the current state. | 706*cda5da8dSAndroid Build Coastguard Worker `-----------------------------------------------------------*/ 707*cda5da8dSAndroid Build Coastguard Worker case YYDEFAULT: 708*cda5da8dSAndroid Build Coastguard Worker yyn = yydefact_[yystate]; 709*cda5da8dSAndroid Build Coastguard Worker if (yyn == 0) 710*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB; 711*cda5da8dSAndroid Build Coastguard Worker else 712*cda5da8dSAndroid Build Coastguard Worker label = YYREDUCE; 713*cda5da8dSAndroid Build Coastguard Worker break; 714*cda5da8dSAndroid Build Coastguard Worker 715*cda5da8dSAndroid Build Coastguard Worker /*-----------------------------. 716*cda5da8dSAndroid Build Coastguard Worker | yyreduce -- Do a reduction. | 717*cda5da8dSAndroid Build Coastguard Worker `-----------------------------*/ 718*cda5da8dSAndroid Build Coastguard Worker case YYREDUCE: 719*cda5da8dSAndroid Build Coastguard Worker yylen = yyr2_[yyn]; 720*cda5da8dSAndroid Build Coastguard Worker label = yyaction(yyn, yystack, yylen); 721*cda5da8dSAndroid Build Coastguard Worker yystate = yystack.stateAt(0); 722*cda5da8dSAndroid Build Coastguard Worker break; 723*cda5da8dSAndroid Build Coastguard Worker 724*cda5da8dSAndroid Build Coastguard Worker /*------------------------------------. 725*cda5da8dSAndroid Build Coastguard Worker | yyerrlab -- here on detecting error | 726*cda5da8dSAndroid Build Coastguard Worker `------------------------------------*/ 727*cda5da8dSAndroid Build Coastguard Worker case YYERRLAB: 728*cda5da8dSAndroid Build Coastguard Worker /* If not already recovering from an error, report this error. */ 729*cda5da8dSAndroid Build Coastguard Worker if (yyerrstatus_ == 0) 730*cda5da8dSAndroid Build Coastguard Worker { 731*cda5da8dSAndroid Build Coastguard Worker ++yynerrs; 732*cda5da8dSAndroid Build Coastguard Worker if (yychar == YYEMPTY_) 733*cda5da8dSAndroid Build Coastguard Worker yytoken = null; 734*cda5da8dSAndroid Build Coastguard Worker yyreportSyntaxError(new Context(this, yystack, yytoken]b4_locations_if([[, yylloc]])[)); 735*cda5da8dSAndroid Build Coastguard Worker } 736*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 737*cda5da8dSAndroid Build Coastguard Worker yyerrloc = yylloc;]])[ 738*cda5da8dSAndroid Build Coastguard Worker if (yyerrstatus_ == 3) 739*cda5da8dSAndroid Build Coastguard Worker { 740*cda5da8dSAndroid Build Coastguard Worker /* If just tried and failed to reuse lookahead token after an 741*cda5da8dSAndroid Build Coastguard Worker error, discard it. */ 742*cda5da8dSAndroid Build Coastguard Worker 743*cda5da8dSAndroid Build Coastguard Worker if (yychar <= Lexer.]b4_symbol(eof, id)[) 744*cda5da8dSAndroid Build Coastguard Worker { 745*cda5da8dSAndroid Build Coastguard Worker /* Return failure if at end of input. */ 746*cda5da8dSAndroid Build Coastguard Worker if (yychar == Lexer.]b4_symbol(eof, id)[) 747*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([{label = YYABORT; break;}], [return false;])[ 748*cda5da8dSAndroid Build Coastguard Worker } 749*cda5da8dSAndroid Build Coastguard Worker else 750*cda5da8dSAndroid Build Coastguard Worker yychar = YYEMPTY_; 751*cda5da8dSAndroid Build Coastguard Worker } 752*cda5da8dSAndroid Build Coastguard Worker 753*cda5da8dSAndroid Build Coastguard Worker /* Else will try to reuse lookahead token after shifting the error 754*cda5da8dSAndroid Build Coastguard Worker token. */ 755*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB1; 756*cda5da8dSAndroid Build Coastguard Worker break; 757*cda5da8dSAndroid Build Coastguard Worker 758*cda5da8dSAndroid Build Coastguard Worker /*-------------------------------------------------. 759*cda5da8dSAndroid Build Coastguard Worker | errorlab -- error raised explicitly by YYERROR. | 760*cda5da8dSAndroid Build Coastguard Worker `-------------------------------------------------*/ 761*cda5da8dSAndroid Build Coastguard Worker case YYERROR:]b4_locations_if([[ 762*cda5da8dSAndroid Build Coastguard Worker yyerrloc = yystack.locationAt (yylen - 1);]])[ 763*cda5da8dSAndroid Build Coastguard Worker /* Do not reclaim the symbols of the rule which action triggered 764*cda5da8dSAndroid Build Coastguard Worker this YYERROR. */ 765*cda5da8dSAndroid Build Coastguard Worker yystack.pop (yylen); 766*cda5da8dSAndroid Build Coastguard Worker yylen = 0; 767*cda5da8dSAndroid Build Coastguard Worker yystate = yystack.stateAt(0); 768*cda5da8dSAndroid Build Coastguard Worker label = YYERRLAB1; 769*cda5da8dSAndroid Build Coastguard Worker break; 770*cda5da8dSAndroid Build Coastguard Worker 771*cda5da8dSAndroid Build Coastguard Worker /*-------------------------------------------------------------. 772*cda5da8dSAndroid Build Coastguard Worker | yyerrlab1 -- common code for both syntax error and YYERROR. | 773*cda5da8dSAndroid Build Coastguard Worker `-------------------------------------------------------------*/ 774*cda5da8dSAndroid Build Coastguard Worker case YYERRLAB1: 775*cda5da8dSAndroid Build Coastguard Worker yyerrstatus_ = 3; /* Each real token shifted decrements this. */ 776*cda5da8dSAndroid Build Coastguard Worker 777*cda5da8dSAndroid Build Coastguard Worker // Pop stack until we find a state that shifts the error token. 778*cda5da8dSAndroid Build Coastguard Worker for (;;) 779*cda5da8dSAndroid Build Coastguard Worker { 780*cda5da8dSAndroid Build Coastguard Worker yyn = yypact_[yystate]; 781*cda5da8dSAndroid Build Coastguard Worker if (!yyPactValueIsDefault (yyn)) 782*cda5da8dSAndroid Build Coastguard Worker { 783*cda5da8dSAndroid Build Coastguard Worker yyn += ]b4_symbol(error, kind)[.getCode(); 784*cda5da8dSAndroid Build Coastguard Worker if (0 <= yyn && yyn <= YYLAST_ 785*cda5da8dSAndroid Build Coastguard Worker && yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode()) 786*cda5da8dSAndroid Build Coastguard Worker { 787*cda5da8dSAndroid Build Coastguard Worker yyn = yytable_[yyn]; 788*cda5da8dSAndroid Build Coastguard Worker if (0 < yyn) 789*cda5da8dSAndroid Build Coastguard Worker break; 790*cda5da8dSAndroid Build Coastguard Worker } 791*cda5da8dSAndroid Build Coastguard Worker } 792*cda5da8dSAndroid Build Coastguard Worker 793*cda5da8dSAndroid Build Coastguard Worker /* Pop the current state because it cannot handle the 794*cda5da8dSAndroid Build Coastguard Worker * error token. */ 795*cda5da8dSAndroid Build Coastguard Worker if (yystack.height == 0) 796*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([{label = YYABORT; break;}],[return false;])[ 797*cda5da8dSAndroid Build Coastguard Worker 798*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 799*cda5da8dSAndroid Build Coastguard Worker yyerrloc = yystack.locationAt (0);]])[ 800*cda5da8dSAndroid Build Coastguard Worker yystack.pop (); 801*cda5da8dSAndroid Build Coastguard Worker yystate = yystack.stateAt(0);]b4_parse_trace_if([[ 802*cda5da8dSAndroid Build Coastguard Worker if (0 < yydebug) 803*cda5da8dSAndroid Build Coastguard Worker yystack.print (yyDebugStream);]])[ 804*cda5da8dSAndroid Build Coastguard Worker } 805*cda5da8dSAndroid Build Coastguard Worker 806*cda5da8dSAndroid Build Coastguard Worker if (label == YYABORT) 807*cda5da8dSAndroid Build Coastguard Worker /* Leave the switch. */ 808*cda5da8dSAndroid Build Coastguard Worker break; 809*cda5da8dSAndroid Build Coastguard Worker 810*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 811*cda5da8dSAndroid Build Coastguard Worker /* Muck with the stack to setup for yylloc. */ 812*cda5da8dSAndroid Build Coastguard Worker yystack.push (0, null, yylloc); 813*cda5da8dSAndroid Build Coastguard Worker yystack.push (0, null, yyerrloc); 814*cda5da8dSAndroid Build Coastguard Worker yyloc = yylloc (yystack, 2); 815*cda5da8dSAndroid Build Coastguard Worker yystack.pop (2);]])[ 816*cda5da8dSAndroid Build Coastguard Worker 817*cda5da8dSAndroid Build Coastguard Worker /* Shift the error token. */]b4_lac_if([[ 818*cda5da8dSAndroid Build Coastguard Worker yylacDiscard("error recovery");]])[]b4_parse_trace_if([[ 819*cda5da8dSAndroid Build Coastguard Worker yySymbolPrint("Shifting", SymbolKind.get(yystos_[yyn]), 820*cda5da8dSAndroid Build Coastguard Worker yylval]b4_locations_if([, yyloc])[);]])[ 821*cda5da8dSAndroid Build Coastguard Worker 822*cda5da8dSAndroid Build Coastguard Worker yystate = yyn; 823*cda5da8dSAndroid Build Coastguard Worker yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); 824*cda5da8dSAndroid Build Coastguard Worker label = YYNEWSTATE; 825*cda5da8dSAndroid Build Coastguard Worker break; 826*cda5da8dSAndroid Build Coastguard Worker 827*cda5da8dSAndroid Build Coastguard Worker /* Accept. */ 828*cda5da8dSAndroid Build Coastguard Worker case YYACCEPT: 829*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([this.push_parse_initialized = false; return YYACCEPT;], 830*cda5da8dSAndroid Build Coastguard Worker [return true;])[ 831*cda5da8dSAndroid Build Coastguard Worker 832*cda5da8dSAndroid Build Coastguard Worker /* Abort. */ 833*cda5da8dSAndroid Build Coastguard Worker case YYABORT: 834*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([this.push_parse_initialized = false; return YYABORT;], 835*cda5da8dSAndroid Build Coastguard Worker [return false;])[ 836*cda5da8dSAndroid Build Coastguard Worker } 837*cda5da8dSAndroid Build Coastguard Worker } 838*cda5da8dSAndroid Build Coastguard Worker ]b4_push_if([[ 839*cda5da8dSAndroid Build Coastguard Worker boolean push_parse_initialized = false; 840*cda5da8dSAndroid Build Coastguard Worker 841*cda5da8dSAndroid Build Coastguard Worker /** 842*cda5da8dSAndroid Build Coastguard Worker * (Re-)Initialize the state of the push parser. 843*cda5da8dSAndroid Build Coastguard Worker */ 844*cda5da8dSAndroid Build Coastguard Worker public void push_parse_initialize () 845*cda5da8dSAndroid Build Coastguard Worker { 846*cda5da8dSAndroid Build Coastguard Worker /* Lookahead and lookahead in internal form. */ 847*cda5da8dSAndroid Build Coastguard Worker this.yychar = YYEMPTY_; 848*cda5da8dSAndroid Build Coastguard Worker this.yytoken = null; 849*cda5da8dSAndroid Build Coastguard Worker 850*cda5da8dSAndroid Build Coastguard Worker /* State. */ 851*cda5da8dSAndroid Build Coastguard Worker this.yyn = 0; 852*cda5da8dSAndroid Build Coastguard Worker this.yylen = 0; 853*cda5da8dSAndroid Build Coastguard Worker this.yystate = 0; 854*cda5da8dSAndroid Build Coastguard Worker this.yystack = new YYStack();]b4_lac_if([[ 855*cda5da8dSAndroid Build Coastguard Worker this.yylacStack = new ArrayList<Integer>(); 856*cda5da8dSAndroid Build Coastguard Worker this.yylacEstablished = false;]])[ 857*cda5da8dSAndroid Build Coastguard Worker this.label = YYNEWSTATE; 858*cda5da8dSAndroid Build Coastguard Worker 859*cda5da8dSAndroid Build Coastguard Worker /* Error handling. */ 860*cda5da8dSAndroid Build Coastguard Worker this.yynerrs = 0;]b4_locations_if([[ 861*cda5da8dSAndroid Build Coastguard Worker /* The location where the error started. */ 862*cda5da8dSAndroid Build Coastguard Worker this.yyerrloc = null; 863*cda5da8dSAndroid Build Coastguard Worker this.yylloc = new ]b4_location_type[ (null, null);]])[ 864*cda5da8dSAndroid Build Coastguard Worker 865*cda5da8dSAndroid Build Coastguard Worker /* Semantic value of the lookahead. */ 866*cda5da8dSAndroid Build Coastguard Worker this.yylval = null; 867*cda5da8dSAndroid Build Coastguard Worker 868*cda5da8dSAndroid Build Coastguard Worker yystack.push (this.yystate, this.yylval]b4_locations_if([, this.yylloc])[); 869*cda5da8dSAndroid Build Coastguard Worker 870*cda5da8dSAndroid Build Coastguard Worker this.push_parse_initialized = true; 871*cda5da8dSAndroid Build Coastguard Worker 872*cda5da8dSAndroid Build Coastguard Worker } 873*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 874*cda5da8dSAndroid Build Coastguard Worker /** 875*cda5da8dSAndroid Build Coastguard Worker * Push parse given input from an external lexer. 876*cda5da8dSAndroid Build Coastguard Worker * 877*cda5da8dSAndroid Build Coastguard Worker * @@param yylextoken current token 878*cda5da8dSAndroid Build Coastguard Worker * @@param yylexval current lval 879*cda5da8dSAndroid Build Coastguard Worker * @@param yyylexpos current position 880*cda5da8dSAndroid Build Coastguard Worker * 881*cda5da8dSAndroid Build Coastguard Worker * @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt> 882*cda5da8dSAndroid Build Coastguard Worker */ 883*cda5da8dSAndroid Build Coastguard Worker public int push_parse(int yylextoken, ]b4_yystype[ yylexval, ]b4_position_type[ yylexpos)]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ { 884*cda5da8dSAndroid Build Coastguard Worker return push_parse(yylextoken, yylexval, new ]b4_location_type[(yylexpos)); 885*cda5da8dSAndroid Build Coastguard Worker } 886*cda5da8dSAndroid Build Coastguard Worker ]])])[ 887*cda5da8dSAndroid Build Coastguard Worker 888*cda5da8dSAndroid Build Coastguard Worker ]b4_both_if([[ 889*cda5da8dSAndroid Build Coastguard Worker /** 890*cda5da8dSAndroid Build Coastguard Worker * Parse input from the scanner that was specified at object construction 891*cda5da8dSAndroid Build Coastguard Worker * time. Return whether the end of the input was reached successfully. 892*cda5da8dSAndroid Build Coastguard Worker * This version of parse() is defined only when api.push-push=both. 893*cda5da8dSAndroid Build Coastguard Worker * 894*cda5da8dSAndroid Build Coastguard Worker * @@return <tt>true</tt> if the parsing succeeds. Note that this does not 895*cda5da8dSAndroid Build Coastguard Worker * imply that there were no syntax errors. 896*cda5da8dSAndroid Build Coastguard Worker */ 897*cda5da8dSAndroid Build Coastguard Worker public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ { 898*cda5da8dSAndroid Build Coastguard Worker if (yylexer == null) 899*cda5da8dSAndroid Build Coastguard Worker throw new NullPointerException("Null Lexer"); 900*cda5da8dSAndroid Build Coastguard Worker int status; 901*cda5da8dSAndroid Build Coastguard Worker do { 902*cda5da8dSAndroid Build Coastguard Worker int token = yylexer.yylex(); 903*cda5da8dSAndroid Build Coastguard Worker ]b4_yystype[ lval = yylexer.getLVal();]b4_locations_if([[ 904*cda5da8dSAndroid Build Coastguard Worker ]b4_location_type[ yyloc = new ]b4_location_type[(yylexer.getStartPos(), yylexer.getEndPos()); 905*cda5da8dSAndroid Build Coastguard Worker status = push_parse(token, lval, yyloc);]], [[ 906*cda5da8dSAndroid Build Coastguard Worker status = push_parse(token, lval);]])[ 907*cda5da8dSAndroid Build Coastguard Worker } while (status == YYPUSH_MORE); 908*cda5da8dSAndroid Build Coastguard Worker return status == YYACCEPT; 909*cda5da8dSAndroid Build Coastguard Worker } 910*cda5da8dSAndroid Build Coastguard Worker ]])[ 911*cda5da8dSAndroid Build Coastguard Worker 912*cda5da8dSAndroid Build Coastguard Worker /** 913*cda5da8dSAndroid Build Coastguard Worker * Information needed to get the list of expected tokens and to forge 914*cda5da8dSAndroid Build Coastguard Worker * a syntax error diagnostic. 915*cda5da8dSAndroid Build Coastguard Worker */ 916*cda5da8dSAndroid Build Coastguard Worker public static final class Context { 917*cda5da8dSAndroid Build Coastguard Worker Context(]b4_parser_class[ parser, YYStack stack, SymbolKind token]b4_locations_if([[, ]b4_location_type[ loc]])[) { 918*cda5da8dSAndroid Build Coastguard Worker yyparser = parser; 919*cda5da8dSAndroid Build Coastguard Worker yystack = stack; 920*cda5da8dSAndroid Build Coastguard Worker yytoken = token;]b4_locations_if([[ 921*cda5da8dSAndroid Build Coastguard Worker yylocation = loc;]])[ 922*cda5da8dSAndroid Build Coastguard Worker } 923*cda5da8dSAndroid Build Coastguard Worker 924*cda5da8dSAndroid Build Coastguard Worker private ]b4_parser_class[ yyparser; 925*cda5da8dSAndroid Build Coastguard Worker private YYStack yystack; 926*cda5da8dSAndroid Build Coastguard Worker 927*cda5da8dSAndroid Build Coastguard Worker 928*cda5da8dSAndroid Build Coastguard Worker /** 929*cda5da8dSAndroid Build Coastguard Worker * The symbol kind of the lookahead token. 930*cda5da8dSAndroid Build Coastguard Worker */ 931*cda5da8dSAndroid Build Coastguard Worker public final SymbolKind getToken() { 932*cda5da8dSAndroid Build Coastguard Worker return yytoken; 933*cda5da8dSAndroid Build Coastguard Worker } 934*cda5da8dSAndroid Build Coastguard Worker 935*cda5da8dSAndroid Build Coastguard Worker private SymbolKind yytoken;]b4_locations_if([[ 936*cda5da8dSAndroid Build Coastguard Worker 937*cda5da8dSAndroid Build Coastguard Worker /** 938*cda5da8dSAndroid Build Coastguard Worker * The location of the lookahead. 939*cda5da8dSAndroid Build Coastguard Worker */ 940*cda5da8dSAndroid Build Coastguard Worker public final ]b4_location_type[ getLocation() { 941*cda5da8dSAndroid Build Coastguard Worker return yylocation; 942*cda5da8dSAndroid Build Coastguard Worker } 943*cda5da8dSAndroid Build Coastguard Worker 944*cda5da8dSAndroid Build Coastguard Worker private ]b4_location_type[ yylocation;]])[ 945*cda5da8dSAndroid Build Coastguard Worker static final int NTOKENS = ]b4_parser_class[.YYNTOKENS_; 946*cda5da8dSAndroid Build Coastguard Worker 947*cda5da8dSAndroid Build Coastguard Worker /** 948*cda5da8dSAndroid Build Coastguard Worker * Put in YYARG at most YYARGN of the expected tokens given the 949*cda5da8dSAndroid Build Coastguard Worker * current YYCTX, and return the number of tokens stored in YYARG. If 950*cda5da8dSAndroid Build Coastguard Worker * YYARG is null, return the number of expected tokens (guaranteed to 951*cda5da8dSAndroid Build Coastguard Worker * be less than YYNTOKENS). 952*cda5da8dSAndroid Build Coastguard Worker */ 953*cda5da8dSAndroid Build Coastguard Worker int getExpectedTokens(SymbolKind yyarg[], int yyargn) { 954*cda5da8dSAndroid Build Coastguard Worker return getExpectedTokens (yyarg, 0, yyargn); 955*cda5da8dSAndroid Build Coastguard Worker } 956*cda5da8dSAndroid Build Coastguard Worker 957*cda5da8dSAndroid Build Coastguard Worker int getExpectedTokens(SymbolKind yyarg[], int yyoffset, int yyargn) { 958*cda5da8dSAndroid Build Coastguard Worker int yycount = yyoffset;]b4_lac_if([b4_parse_trace_if([[ 959*cda5da8dSAndroid Build Coastguard Worker // Execute LAC once. We don't care if it is successful, we 960*cda5da8dSAndroid Build Coastguard Worker // only do it for the sake of debugging output. 961*cda5da8dSAndroid Build Coastguard Worker if (!yyparser.yylacEstablished) 962*cda5da8dSAndroid Build Coastguard Worker yyparser.yylacCheck(yystack, yytoken); 963*cda5da8dSAndroid Build Coastguard Worker ]])[ 964*cda5da8dSAndroid Build Coastguard Worker for (int yyx = 0; yyx < YYNTOKENS_; ++yyx) 965*cda5da8dSAndroid Build Coastguard Worker { 966*cda5da8dSAndroid Build Coastguard Worker SymbolKind yysym = SymbolKind.get(yyx); 967*cda5da8dSAndroid Build Coastguard Worker if (yysym != ]b4_symbol(error, kind)[ 968*cda5da8dSAndroid Build Coastguard Worker && yysym != ]b4_symbol(undef, kind)[ 969*cda5da8dSAndroid Build Coastguard Worker && yyparser.yylacCheck(yystack, yysym)) 970*cda5da8dSAndroid Build Coastguard Worker { 971*cda5da8dSAndroid Build Coastguard Worker if (yyarg == null) 972*cda5da8dSAndroid Build Coastguard Worker yycount += 1; 973*cda5da8dSAndroid Build Coastguard Worker else if (yycount == yyargn) 974*cda5da8dSAndroid Build Coastguard Worker return 0; 975*cda5da8dSAndroid Build Coastguard Worker else 976*cda5da8dSAndroid Build Coastguard Worker yyarg[yycount++] = yysym; 977*cda5da8dSAndroid Build Coastguard Worker } 978*cda5da8dSAndroid Build Coastguard Worker }]], [[ 979*cda5da8dSAndroid Build Coastguard Worker int yyn = yypact_[this.yystack.stateAt(0)]; 980*cda5da8dSAndroid Build Coastguard Worker if (!yyPactValueIsDefault(yyn)) 981*cda5da8dSAndroid Build Coastguard Worker { 982*cda5da8dSAndroid Build Coastguard Worker /* Start YYX at -YYN if negative to avoid negative 983*cda5da8dSAndroid Build Coastguard Worker indexes in YYCHECK. In other words, skip the first 984*cda5da8dSAndroid Build Coastguard Worker -YYN actions for this state because they are default 985*cda5da8dSAndroid Build Coastguard Worker actions. */ 986*cda5da8dSAndroid Build Coastguard Worker int yyxbegin = yyn < 0 ? -yyn : 0; 987*cda5da8dSAndroid Build Coastguard Worker /* Stay within bounds of both yycheck and yytname. */ 988*cda5da8dSAndroid Build Coastguard Worker int yychecklim = YYLAST_ - yyn + 1; 989*cda5da8dSAndroid Build Coastguard Worker int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS; 990*cda5da8dSAndroid Build Coastguard Worker for (int yyx = yyxbegin; yyx < yyxend; ++yyx) 991*cda5da8dSAndroid Build Coastguard Worker if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[.getCode() 992*cda5da8dSAndroid Build Coastguard Worker && !yyTableValueIsError(yytable_[yyx + yyn])) 993*cda5da8dSAndroid Build Coastguard Worker { 994*cda5da8dSAndroid Build Coastguard Worker if (yyarg == null) 995*cda5da8dSAndroid Build Coastguard Worker yycount += 1; 996*cda5da8dSAndroid Build Coastguard Worker else if (yycount == yyargn) 997*cda5da8dSAndroid Build Coastguard Worker return 0; // FIXME: this is incorrect. 998*cda5da8dSAndroid Build Coastguard Worker else 999*cda5da8dSAndroid Build Coastguard Worker yyarg[yycount++] = SymbolKind.get(yyx); 1000*cda5da8dSAndroid Build Coastguard Worker } 1001*cda5da8dSAndroid Build Coastguard Worker }]])[ 1002*cda5da8dSAndroid Build Coastguard Worker if (yyarg != null && yycount == yyoffset && yyoffset < yyargn) 1003*cda5da8dSAndroid Build Coastguard Worker yyarg[yycount] = null; 1004*cda5da8dSAndroid Build Coastguard Worker return yycount - yyoffset; 1005*cda5da8dSAndroid Build Coastguard Worker } 1006*cda5da8dSAndroid Build Coastguard Worker } 1007*cda5da8dSAndroid Build Coastguard Worker 1008*cda5da8dSAndroid Build Coastguard Worker ]b4_lac_if([[ 1009*cda5da8dSAndroid Build Coastguard Worker /** Check the lookahead yytoken. 1010*cda5da8dSAndroid Build Coastguard Worker * \returns true iff the token will be eventually shifted. 1011*cda5da8dSAndroid Build Coastguard Worker */ 1012*cda5da8dSAndroid Build Coastguard Worker boolean yylacCheck(YYStack yystack, SymbolKind yytoken) 1013*cda5da8dSAndroid Build Coastguard Worker { 1014*cda5da8dSAndroid Build Coastguard Worker // Logically, the yylacStack's lifetime is confined to this function. 1015*cda5da8dSAndroid Build Coastguard Worker // Clear it, to get rid of potential left-overs from previous call. 1016*cda5da8dSAndroid Build Coastguard Worker yylacStack.clear(); 1017*cda5da8dSAndroid Build Coastguard Worker // Reduce until we encounter a shift and thereby accept the token. 1018*cda5da8dSAndroid Build Coastguard Worker yycdebugNnl("LAC: checking lookahead " + yytoken.getName() + ":"); 1019*cda5da8dSAndroid Build Coastguard Worker int lacTop = 0; 1020*cda5da8dSAndroid Build Coastguard Worker while (true) 1021*cda5da8dSAndroid Build Coastguard Worker { 1022*cda5da8dSAndroid Build Coastguard Worker int topState = (yylacStack.isEmpty() 1023*cda5da8dSAndroid Build Coastguard Worker ? yystack.stateAt(lacTop) 1024*cda5da8dSAndroid Build Coastguard Worker : yylacStack.get(yylacStack.size() - 1)); 1025*cda5da8dSAndroid Build Coastguard Worker int yyrule = yypact_[topState]; 1026*cda5da8dSAndroid Build Coastguard Worker if (yyPactValueIsDefault(yyrule) 1027*cda5da8dSAndroid Build Coastguard Worker || (yyrule += yytoken.getCode()) < 0 || YYLAST_ < yyrule 1028*cda5da8dSAndroid Build Coastguard Worker || yycheck_[yyrule] != yytoken.getCode()) 1029*cda5da8dSAndroid Build Coastguard Worker { 1030*cda5da8dSAndroid Build Coastguard Worker // Use the default action. 1031*cda5da8dSAndroid Build Coastguard Worker yyrule = yydefact_[+topState]; 1032*cda5da8dSAndroid Build Coastguard Worker if (yyrule == 0) { 1033*cda5da8dSAndroid Build Coastguard Worker yycdebug(" Err"); 1034*cda5da8dSAndroid Build Coastguard Worker return false; 1035*cda5da8dSAndroid Build Coastguard Worker } 1036*cda5da8dSAndroid Build Coastguard Worker } 1037*cda5da8dSAndroid Build Coastguard Worker else 1038*cda5da8dSAndroid Build Coastguard Worker { 1039*cda5da8dSAndroid Build Coastguard Worker // Use the action from yytable. 1040*cda5da8dSAndroid Build Coastguard Worker yyrule = yytable_[yyrule]; 1041*cda5da8dSAndroid Build Coastguard Worker if (yyTableValueIsError(yyrule)) { 1042*cda5da8dSAndroid Build Coastguard Worker yycdebug(" Err"); 1043*cda5da8dSAndroid Build Coastguard Worker return false; 1044*cda5da8dSAndroid Build Coastguard Worker } 1045*cda5da8dSAndroid Build Coastguard Worker if (0 < yyrule) { 1046*cda5da8dSAndroid Build Coastguard Worker yycdebug(" S" + yyrule); 1047*cda5da8dSAndroid Build Coastguard Worker return true; 1048*cda5da8dSAndroid Build Coastguard Worker } 1049*cda5da8dSAndroid Build Coastguard Worker yyrule = -yyrule; 1050*cda5da8dSAndroid Build Coastguard Worker } 1051*cda5da8dSAndroid Build Coastguard Worker // By now we know we have to simulate a reduce. 1052*cda5da8dSAndroid Build Coastguard Worker yycdebugNnl(" R" + (yyrule - 1)); 1053*cda5da8dSAndroid Build Coastguard Worker // Pop the corresponding number of values from the stack. 1054*cda5da8dSAndroid Build Coastguard Worker { 1055*cda5da8dSAndroid Build Coastguard Worker int yylen = yyr2_[yyrule]; 1056*cda5da8dSAndroid Build Coastguard Worker // First pop from the LAC stack as many tokens as possible. 1057*cda5da8dSAndroid Build Coastguard Worker int lacSize = yylacStack.size(); 1058*cda5da8dSAndroid Build Coastguard Worker if (yylen < lacSize) { 1059*cda5da8dSAndroid Build Coastguard Worker // yylacStack.setSize(lacSize - yylen); 1060*cda5da8dSAndroid Build Coastguard Worker for (/* Nothing */; 0 < yylen; yylen -= 1) { 1061*cda5da8dSAndroid Build Coastguard Worker yylacStack.remove(yylacStack.size() - 1); 1062*cda5da8dSAndroid Build Coastguard Worker } 1063*cda5da8dSAndroid Build Coastguard Worker yylen = 0; 1064*cda5da8dSAndroid Build Coastguard Worker } else if (lacSize != 0) { 1065*cda5da8dSAndroid Build Coastguard Worker yylacStack.clear(); 1066*cda5da8dSAndroid Build Coastguard Worker yylen -= lacSize; 1067*cda5da8dSAndroid Build Coastguard Worker } 1068*cda5da8dSAndroid Build Coastguard Worker // Only afterwards look at the main stack. 1069*cda5da8dSAndroid Build Coastguard Worker // We simulate popping elements by incrementing lacTop. 1070*cda5da8dSAndroid Build Coastguard Worker lacTop += yylen; 1071*cda5da8dSAndroid Build Coastguard Worker } 1072*cda5da8dSAndroid Build Coastguard Worker // Keep topState in sync with the updated stack. 1073*cda5da8dSAndroid Build Coastguard Worker topState = (yylacStack.isEmpty() 1074*cda5da8dSAndroid Build Coastguard Worker ? yystack.stateAt(lacTop) 1075*cda5da8dSAndroid Build Coastguard Worker : yylacStack.get(yylacStack.size() - 1)); 1076*cda5da8dSAndroid Build Coastguard Worker // Push the resulting state of the reduction. 1077*cda5da8dSAndroid Build Coastguard Worker int state = yyLRGotoState(topState, yyr1_[yyrule]); 1078*cda5da8dSAndroid Build Coastguard Worker yycdebugNnl(" G" + state); 1079*cda5da8dSAndroid Build Coastguard Worker yylacStack.add(state); 1080*cda5da8dSAndroid Build Coastguard Worker } 1081*cda5da8dSAndroid Build Coastguard Worker } 1082*cda5da8dSAndroid Build Coastguard Worker 1083*cda5da8dSAndroid Build Coastguard Worker /** Establish the initial context if no initial context currently exists. 1084*cda5da8dSAndroid Build Coastguard Worker * \returns true iff the token will be eventually shifted. 1085*cda5da8dSAndroid Build Coastguard Worker */ 1086*cda5da8dSAndroid Build Coastguard Worker boolean yylacEstablish(YYStack yystack, SymbolKind yytoken) { 1087*cda5da8dSAndroid Build Coastguard Worker /* Establish the initial context for the current lookahead if no initial 1088*cda5da8dSAndroid Build Coastguard Worker context is currently established. 1089*cda5da8dSAndroid Build Coastguard Worker 1090*cda5da8dSAndroid Build Coastguard Worker We define a context as a snapshot of the parser stacks. We define 1091*cda5da8dSAndroid Build Coastguard Worker the initial context for a lookahead as the context in which the 1092*cda5da8dSAndroid Build Coastguard Worker parser initially examines that lookahead in order to select a 1093*cda5da8dSAndroid Build Coastguard Worker syntactic action. Thus, if the lookahead eventually proves 1094*cda5da8dSAndroid Build Coastguard Worker syntactically unacceptable (possibly in a later context reached via a 1095*cda5da8dSAndroid Build Coastguard Worker series of reductions), the initial context can be used to determine 1096*cda5da8dSAndroid Build Coastguard Worker the exact set of tokens that would be syntactically acceptable in the 1097*cda5da8dSAndroid Build Coastguard Worker lookahead's place. Moreover, it is the context after which any 1098*cda5da8dSAndroid Build Coastguard Worker further semantic actions would be erroneous because they would be 1099*cda5da8dSAndroid Build Coastguard Worker determined by a syntactically unacceptable token. 1100*cda5da8dSAndroid Build Coastguard Worker 1101*cda5da8dSAndroid Build Coastguard Worker yylacEstablish should be invoked when a reduction is about to be 1102*cda5da8dSAndroid Build Coastguard Worker performed in an inconsistent state (which, for the purposes of LAC, 1103*cda5da8dSAndroid Build Coastguard Worker includes consistent states that don't know they're consistent because 1104*cda5da8dSAndroid Build Coastguard Worker their default reductions have been disabled). 1105*cda5da8dSAndroid Build Coastguard Worker 1106*cda5da8dSAndroid Build Coastguard Worker For parse.lac=full, the implementation of yylacEstablish is as 1107*cda5da8dSAndroid Build Coastguard Worker follows. If no initial context is currently established for the 1108*cda5da8dSAndroid Build Coastguard Worker current lookahead, then check if that lookahead can eventually be 1109*cda5da8dSAndroid Build Coastguard Worker shifted if syntactic actions continue from the current context. */ 1110*cda5da8dSAndroid Build Coastguard Worker if (yylacEstablished) { 1111*cda5da8dSAndroid Build Coastguard Worker return true; 1112*cda5da8dSAndroid Build Coastguard Worker } else { 1113*cda5da8dSAndroid Build Coastguard Worker yycdebug("LAC: initial context established for " + yytoken.getName()); 1114*cda5da8dSAndroid Build Coastguard Worker yylacEstablished = true; 1115*cda5da8dSAndroid Build Coastguard Worker return yylacCheck(yystack, yytoken); 1116*cda5da8dSAndroid Build Coastguard Worker } 1117*cda5da8dSAndroid Build Coastguard Worker } 1118*cda5da8dSAndroid Build Coastguard Worker 1119*cda5da8dSAndroid Build Coastguard Worker /** Discard any previous initial lookahead context because of event. 1120*cda5da8dSAndroid Build Coastguard Worker * \param event the event which caused the lookahead to be discarded. 1121*cda5da8dSAndroid Build Coastguard Worker * Only used for debbuging output. */ 1122*cda5da8dSAndroid Build Coastguard Worker void yylacDiscard(String event) { 1123*cda5da8dSAndroid Build Coastguard Worker /* Discard any previous initial lookahead context because of Event, 1124*cda5da8dSAndroid Build Coastguard Worker which may be a lookahead change or an invalidation of the currently 1125*cda5da8dSAndroid Build Coastguard Worker established initial context for the current lookahead. 1126*cda5da8dSAndroid Build Coastguard Worker 1127*cda5da8dSAndroid Build Coastguard Worker The most common example of a lookahead change is a shift. An example 1128*cda5da8dSAndroid Build Coastguard Worker of both cases is syntax error recovery. That is, a syntax error 1129*cda5da8dSAndroid Build Coastguard Worker occurs when the lookahead is syntactically erroneous for the 1130*cda5da8dSAndroid Build Coastguard Worker currently established initial context, so error recovery manipulates 1131*cda5da8dSAndroid Build Coastguard Worker the parser stacks to try to find a new initial context in which the 1132*cda5da8dSAndroid Build Coastguard Worker current lookahead is syntactically acceptable. If it fails to find 1133*cda5da8dSAndroid Build Coastguard Worker such a context, it discards the lookahead. */ 1134*cda5da8dSAndroid Build Coastguard Worker if (yylacEstablished) { 1135*cda5da8dSAndroid Build Coastguard Worker yycdebug("LAC: initial context discarded due to " + event); 1136*cda5da8dSAndroid Build Coastguard Worker yylacEstablished = false; 1137*cda5da8dSAndroid Build Coastguard Worker } 1138*cda5da8dSAndroid Build Coastguard Worker } 1139*cda5da8dSAndroid Build Coastguard Worker 1140*cda5da8dSAndroid Build Coastguard Worker /** The stack for LAC. 1141*cda5da8dSAndroid Build Coastguard Worker * Logically, the yylacStack's lifetime is confined to the function 1142*cda5da8dSAndroid Build Coastguard Worker * yylacCheck. We just store it as a member of this class to hold 1143*cda5da8dSAndroid Build Coastguard Worker * on to the memory and to avoid frequent reallocations. 1144*cda5da8dSAndroid Build Coastguard Worker */ 1145*cda5da8dSAndroid Build Coastguard Worker ArrayList<Integer> yylacStack; 1146*cda5da8dSAndroid Build Coastguard Worker /** Whether an initial LAC context was established. */ 1147*cda5da8dSAndroid Build Coastguard Worker boolean yylacEstablished; 1148*cda5da8dSAndroid Build Coastguard Worker ]])[ 1149*cda5da8dSAndroid Build Coastguard Worker 1150*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch( 1151*cda5da8dSAndroid Build Coastguard Worker [detailed\|verbose], [[ 1152*cda5da8dSAndroid Build Coastguard Worker private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) { 1153*cda5da8dSAndroid Build Coastguard Worker /* There are many possibilities here to consider: 1154*cda5da8dSAndroid Build Coastguard Worker - If this state is a consistent state with a default action, 1155*cda5da8dSAndroid Build Coastguard Worker then the only way this function was invoked is if the 1156*cda5da8dSAndroid Build Coastguard Worker default action is an error action. In that case, don't 1157*cda5da8dSAndroid Build Coastguard Worker check for expected tokens because there are none. 1158*cda5da8dSAndroid Build Coastguard Worker - The only way there can be no lookahead present (in tok) is 1159*cda5da8dSAndroid Build Coastguard Worker if this state is a consistent state with a default action. 1160*cda5da8dSAndroid Build Coastguard Worker Thus, detecting the absence of a lookahead is sufficient to 1161*cda5da8dSAndroid Build Coastguard Worker determine that there is no unexpected or expected token to 1162*cda5da8dSAndroid Build Coastguard Worker report. In that case, just report a simple "syntax error". 1163*cda5da8dSAndroid Build Coastguard Worker - Don't assume there isn't a lookahead just because this 1164*cda5da8dSAndroid Build Coastguard Worker state is a consistent state with a default action. There 1165*cda5da8dSAndroid Build Coastguard Worker might have been a previous inconsistent state, consistent 1166*cda5da8dSAndroid Build Coastguard Worker state with a non-default action, or user semantic action 1167*cda5da8dSAndroid Build Coastguard Worker that manipulated yychar. (However, yychar is currently out 1168*cda5da8dSAndroid Build Coastguard Worker of scope during semantic actions.) 1169*cda5da8dSAndroid Build Coastguard Worker - Of course, the expected token list depends on states to 1170*cda5da8dSAndroid Build Coastguard Worker have correct lookahead information, and it depends on the 1171*cda5da8dSAndroid Build Coastguard Worker parser not to perform extra reductions after fetching a 1172*cda5da8dSAndroid Build Coastguard Worker lookahead from the scanner and before detecting a syntax 1173*cda5da8dSAndroid Build Coastguard Worker error. Thus, state merging (from LALR or IELR) and default 1174*cda5da8dSAndroid Build Coastguard Worker reductions corrupt the expected token list. However, the 1175*cda5da8dSAndroid Build Coastguard Worker list is correct for canonical LR with one exception: it 1176*cda5da8dSAndroid Build Coastguard Worker will still contain any token that will not be accepted due 1177*cda5da8dSAndroid Build Coastguard Worker to an error action in a later state. 1178*cda5da8dSAndroid Build Coastguard Worker */ 1179*cda5da8dSAndroid Build Coastguard Worker int yycount = 0; 1180*cda5da8dSAndroid Build Coastguard Worker if (yyctx.getToken() != null) 1181*cda5da8dSAndroid Build Coastguard Worker { 1182*cda5da8dSAndroid Build Coastguard Worker if (yyarg != null) 1183*cda5da8dSAndroid Build Coastguard Worker yyarg[yycount] = yyctx.getToken(); 1184*cda5da8dSAndroid Build Coastguard Worker yycount += 1; 1185*cda5da8dSAndroid Build Coastguard Worker yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn); 1186*cda5da8dSAndroid Build Coastguard Worker } 1187*cda5da8dSAndroid Build Coastguard Worker return yycount; 1188*cda5da8dSAndroid Build Coastguard Worker } 1189*cda5da8dSAndroid Build Coastguard Worker ]])[ 1190*cda5da8dSAndroid Build Coastguard Worker 1191*cda5da8dSAndroid Build Coastguard Worker /** 1192*cda5da8dSAndroid Build Coastguard Worker * Build and emit a "syntax error" message in a user-defined way. 1193*cda5da8dSAndroid Build Coastguard Worker * 1194*cda5da8dSAndroid Build Coastguard Worker * @@param ctx The context of the error. 1195*cda5da8dSAndroid Build Coastguard Worker */ 1196*cda5da8dSAndroid Build Coastguard Worker private void yyreportSyntaxError(Context yyctx) {]b4_parse_error_bmatch( 1197*cda5da8dSAndroid Build Coastguard Worker [custom], [[ 1198*cda5da8dSAndroid Build Coastguard Worker yylexer.reportSyntaxError(yyctx);]], 1199*cda5da8dSAndroid Build Coastguard Worker [detailed\|verbose], [[ 1200*cda5da8dSAndroid Build Coastguard Worker if (yyErrorVerbose) { 1201*cda5da8dSAndroid Build Coastguard Worker final int argmax = 5; 1202*cda5da8dSAndroid Build Coastguard Worker SymbolKind[] yyarg = new SymbolKind[argmax]; 1203*cda5da8dSAndroid Build Coastguard Worker int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax); 1204*cda5da8dSAndroid Build Coastguard Worker String[] yystr = new String[yycount]; 1205*cda5da8dSAndroid Build Coastguard Worker for (int yyi = 0; yyi < yycount; ++yyi) { 1206*cda5da8dSAndroid Build Coastguard Worker yystr[yyi] = yyarg[yyi].getName(); 1207*cda5da8dSAndroid Build Coastguard Worker } 1208*cda5da8dSAndroid Build Coastguard Worker String yyformat; 1209*cda5da8dSAndroid Build Coastguard Worker switch (yycount) { 1210*cda5da8dSAndroid Build Coastguard Worker default: 1211*cda5da8dSAndroid Build Coastguard Worker case 0: yyformat = ]b4_trans(["syntax error"])[; break; 1212*cda5da8dSAndroid Build Coastguard Worker case 1: yyformat = ]b4_trans(["syntax error, unexpected {0}"])[; break; 1213*cda5da8dSAndroid Build Coastguard Worker case 2: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1}"])[; break; 1214*cda5da8dSAndroid Build Coastguard Worker case 3: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2}"])[; break; 1215*cda5da8dSAndroid Build Coastguard Worker case 4: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3}"])[; break; 1216*cda5da8dSAndroid Build Coastguard Worker case 5: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"])[; break; 1217*cda5da8dSAndroid Build Coastguard Worker } 1218*cda5da8dSAndroid Build Coastguard Worker yyerror(]b4_locations_if([[yyctx.yylocation, ]])[new MessageFormat(yyformat).format(yystr)); 1219*cda5da8dSAndroid Build Coastguard Worker } else { 1220*cda5da8dSAndroid Build Coastguard Worker yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[); 1221*cda5da8dSAndroid Build Coastguard Worker }]], 1222*cda5da8dSAndroid Build Coastguard Worker [simple], [[ 1223*cda5da8dSAndroid Build Coastguard Worker yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[);]])[ 1224*cda5da8dSAndroid Build Coastguard Worker } 1225*cda5da8dSAndroid Build Coastguard Worker 1226*cda5da8dSAndroid Build Coastguard Worker /** 1227*cda5da8dSAndroid Build Coastguard Worker * Whether the given <code>yypact_</code> value indicates a defaulted state. 1228*cda5da8dSAndroid Build Coastguard Worker * @@param yyvalue the value to check 1229*cda5da8dSAndroid Build Coastguard Worker */ 1230*cda5da8dSAndroid Build Coastguard Worker private static boolean yyPactValueIsDefault(int yyvalue) { 1231*cda5da8dSAndroid Build Coastguard Worker return yyvalue == yypact_ninf_; 1232*cda5da8dSAndroid Build Coastguard Worker } 1233*cda5da8dSAndroid Build Coastguard Worker 1234*cda5da8dSAndroid Build Coastguard Worker /** 1235*cda5da8dSAndroid Build Coastguard Worker * Whether the given <code>yytable_</code> 1236*cda5da8dSAndroid Build Coastguard Worker * value indicates a syntax error. 1237*cda5da8dSAndroid Build Coastguard Worker * @@param yyvalue the value to check 1238*cda5da8dSAndroid Build Coastguard Worker */ 1239*cda5da8dSAndroid Build Coastguard Worker private static boolean yyTableValueIsError(int yyvalue) { 1240*cda5da8dSAndroid Build Coastguard Worker return yyvalue == yytable_ninf_; 1241*cda5da8dSAndroid Build Coastguard Worker } 1242*cda5da8dSAndroid Build Coastguard Worker 1243*cda5da8dSAndroid Build Coastguard Worker private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; 1244*cda5da8dSAndroid Build Coastguard Worker private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; 1245*cda5da8dSAndroid Build Coastguard Worker 1246*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_tables_define[ 1247*cda5da8dSAndroid Build Coastguard Worker 1248*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_trace_if([[ 1249*cda5da8dSAndroid Build Coastguard Worker ]b4_integral_parser_table_define([rline], [b4_rline], 1250*cda5da8dSAndroid Build Coastguard Worker [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ 1251*cda5da8dSAndroid Build Coastguard Worker 1252*cda5da8dSAndroid Build Coastguard Worker 1253*cda5da8dSAndroid Build Coastguard Worker // Report on the debug stream that the rule yyrule is going to be reduced. 1254*cda5da8dSAndroid Build Coastguard Worker private void yyReducePrint (int yyrule, YYStack yystack) 1255*cda5da8dSAndroid Build Coastguard Worker { 1256*cda5da8dSAndroid Build Coastguard Worker if (yydebug == 0) 1257*cda5da8dSAndroid Build Coastguard Worker return; 1258*cda5da8dSAndroid Build Coastguard Worker 1259*cda5da8dSAndroid Build Coastguard Worker int yylno = yyrline_[yyrule]; 1260*cda5da8dSAndroid Build Coastguard Worker int yynrhs = yyr2_[yyrule]; 1261*cda5da8dSAndroid Build Coastguard Worker /* Print the symbols being reduced, and their result. */ 1262*cda5da8dSAndroid Build Coastguard Worker yycdebug ("Reducing stack by rule " + (yyrule - 1) 1263*cda5da8dSAndroid Build Coastguard Worker + " (line " + yylno + "):"); 1264*cda5da8dSAndroid Build Coastguard Worker 1265*cda5da8dSAndroid Build Coastguard Worker /* The symbols being reduced. */ 1266*cda5da8dSAndroid Build Coastguard Worker for (int yyi = 0; yyi < yynrhs; yyi++) 1267*cda5da8dSAndroid Build Coastguard Worker yySymbolPrint(" $" + (yyi + 1) + " =", 1268*cda5da8dSAndroid Build Coastguard Worker SymbolKind.get(yystos_[yystack.stateAt(yynrhs - (yyi + 1))]), 1269*cda5da8dSAndroid Build Coastguard Worker ]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([, 1270*cda5da8dSAndroid Build Coastguard Worker b4_rhs_location(yynrhs, yyi + 1)])[); 1271*cda5da8dSAndroid Build Coastguard Worker }]])[ 1272*cda5da8dSAndroid Build Coastguard Worker 1273*cda5da8dSAndroid Build Coastguard Worker /* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 1274*cda5da8dSAndroid Build Coastguard Worker as returned by yylex, with out-of-bounds checking. */ 1275*cda5da8dSAndroid Build Coastguard Worker private static final SymbolKind yytranslate_(int t) 1276*cda5da8dSAndroid Build Coastguard Worker ]b4_api_token_raw_if(dnl 1277*cda5da8dSAndroid Build Coastguard Worker [[ { 1278*cda5da8dSAndroid Build Coastguard Worker return SymbolKind.get(t); 1279*cda5da8dSAndroid Build Coastguard Worker } 1280*cda5da8dSAndroid Build Coastguard Worker ]], 1281*cda5da8dSAndroid Build Coastguard Worker [[ { 1282*cda5da8dSAndroid Build Coastguard Worker // Last valid token kind. 1283*cda5da8dSAndroid Build Coastguard Worker int code_max = ]b4_code_max[; 1284*cda5da8dSAndroid Build Coastguard Worker if (t <= 0) 1285*cda5da8dSAndroid Build Coastguard Worker return ]b4_symbol(eof, kind)[; 1286*cda5da8dSAndroid Build Coastguard Worker else if (t <= code_max) 1287*cda5da8dSAndroid Build Coastguard Worker return SymbolKind.get(yytranslate_table_[t]); 1288*cda5da8dSAndroid Build Coastguard Worker else 1289*cda5da8dSAndroid Build Coastguard Worker return ]b4_symbol(undef, kind)[; 1290*cda5da8dSAndroid Build Coastguard Worker } 1291*cda5da8dSAndroid Build Coastguard Worker ]b4_integral_parser_table_define([translate_table], [b4_translate])[ 1292*cda5da8dSAndroid Build Coastguard Worker ]])[ 1293*cda5da8dSAndroid Build Coastguard Worker 1294*cda5da8dSAndroid Build Coastguard Worker private static final int YYLAST_ = ]b4_last[; 1295*cda5da8dSAndroid Build Coastguard Worker private static final int YYEMPTY_ = -2; 1296*cda5da8dSAndroid Build Coastguard Worker private static final int YYFINAL_ = ]b4_final_state_number[; 1297*cda5da8dSAndroid Build Coastguard Worker private static final int YYNTOKENS_ = ]b4_tokens_number[; 1298*cda5da8dSAndroid Build Coastguard Worker 1299*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get[ 1300*cda5da8dSAndroid Build Coastguard Worker } 1301*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[epilogue]])[]dnl 1302*cda5da8dSAndroid Build Coastguard Worker b4_epilogue[]dnl 1303*cda5da8dSAndroid Build Coastguard Worker b4_output_end 1304