[270] | 1 | -*- Autoconf -*-
|
---|
| 2 |
|
---|
| 3 | # Java language support for Bison
|
---|
| 4 |
|
---|
| 5 | # Copyright (C) 2007, 2008 Free Software Foundation, Inc.
|
---|
| 6 |
|
---|
| 7 | # This program is free software: you can redistribute it and/or modify
|
---|
| 8 | # it under the terms of the GNU General Public License as published by
|
---|
| 9 | # the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | # (at your option) any later version.
|
---|
| 11 | #
|
---|
| 12 | # This program is distributed in the hope that it will be useful,
|
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | # GNU General Public License for more details.
|
---|
| 16 | #
|
---|
| 17 | # You should have received a copy of the GNU General Public License
|
---|
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | # b4_comment(TEXT)
|
---|
| 22 | # ----------------
|
---|
| 23 | m4_define([b4_comment], [/* m4_bpatsubst([$1], [
|
---|
| 24 | ], [
|
---|
| 25 | ]) */])
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | # b4_list2(LIST1, LIST2)
|
---|
| 29 | # --------------------------
|
---|
| 30 | # Join two lists with a comma if necessary.
|
---|
| 31 | m4_define([b4_list2],
|
---|
| 32 | [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | # b4_percent_define_get3(DEF, PRE, POST, NOT)
|
---|
| 36 | # -------------------------------------------
|
---|
| 37 | # Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
|
---|
| 38 | # otherwise NOT.
|
---|
| 39 | m4_define([b4_percent_define_get3],
|
---|
| 40 | [m4_ifval(m4_quote(b4_percent_define_get([$1])),
|
---|
| 41 | [$2[]b4_percent_define_get([$1])[]$3], [$4])])
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | # b4_flag_value(BOOLEAN-FLAG)
|
---|
| 46 | # ---------------------------
|
---|
| 47 | m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | # b4_public_if(TRUE, FALSE)
|
---|
| 51 | # -------------------------
|
---|
| 52 | b4_percent_define_default([[public]], [[false]])
|
---|
| 53 | m4_define([b4_public_if],
|
---|
| 54 | [b4_percent_define_flag_if([public], [$1], [$2])])
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | # b4_abstract_if(TRUE, FALSE)
|
---|
| 58 | # ---------------------------
|
---|
| 59 | b4_percent_define_default([[abstract]], [[false]])
|
---|
| 60 | m4_define([b4_abstract_if],
|
---|
| 61 | [b4_percent_define_flag_if([abstract], [$1], [$2])])
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | # b4_final_if(TRUE, FALSE)
|
---|
| 65 | # ---------------------------
|
---|
| 66 | b4_percent_define_default([[final]], [[false]])
|
---|
| 67 | m4_define([b4_final_if],
|
---|
| 68 | [b4_percent_define_flag_if([final], [$1], [$2])])
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | # b4_strictfp_if(TRUE, FALSE)
|
---|
| 72 | # ---------------------------
|
---|
| 73 | b4_percent_define_default([[strictfp]], [[false]])
|
---|
| 74 | m4_define([b4_strictfp_if],
|
---|
| 75 | [b4_percent_define_flag_if([strictfp], [$1], [$2])])
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | # b4_lexer_if(TRUE, FALSE)
|
---|
| 79 | # ------------------------
|
---|
| 80 | m4_define([b4_lexer_if],
|
---|
| 81 | [b4_percent_code_ifdef([[lexer]], [$1], [$2])])
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | # b4_identification
|
---|
| 85 | # -----------------
|
---|
| 86 | m4_define([b4_identification],
|
---|
| 87 | [ /** Version number for the Bison executable that generated this parser. */
|
---|
| 88 | public static final String bisonVersion = "b4_version";
|
---|
| 89 |
|
---|
| 90 | /** Name of the skeleton that generated this parser. */
|
---|
| 91 | public static final String bisonSkeleton = b4_skeleton;
|
---|
| 92 | ])
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | ## ------------ ##
|
---|
| 96 | ## Data types. ##
|
---|
| 97 | ## ------------ ##
|
---|
| 98 |
|
---|
| 99 | # b4_int_type(MIN, MAX)
|
---|
| 100 | # ---------------------
|
---|
| 101 | # Return the smallest int type able to handle numbers ranging from
|
---|
| 102 | # MIN to MAX (included).
|
---|
| 103 | m4_define([b4_int_type],
|
---|
| 104 | [m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
|
---|
| 105 | b4_ints_in($@, [-32768], [32767]), [1], [short],
|
---|
| 106 | [int])])
|
---|
| 107 |
|
---|
| 108 | # b4_int_type_for(NAME)
|
---|
| 109 | # ---------------------
|
---|
| 110 | # Return the smallest int type able to handle numbers ranging from
|
---|
| 111 | # `NAME_min' to `NAME_max' (included).
|
---|
| 112 | m4_define([b4_int_type_for],
|
---|
| 113 | [b4_int_type($1_min, $1_max)])
|
---|
| 114 |
|
---|
| 115 | # b4_null
|
---|
| 116 | # -------
|
---|
| 117 | m4_define([b4_null], [null])
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | ## ------------------------- ##
|
---|
| 121 | ## Assigning token numbers. ##
|
---|
| 122 | ## ------------------------- ##
|
---|
| 123 |
|
---|
| 124 | # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
|
---|
| 125 | # ---------------------------------------
|
---|
| 126 | # Output the definition of this token as an enum.
|
---|
| 127 | m4_define([b4_token_enum],
|
---|
| 128 | [ /** Token number, to be returned by the scanner. */
|
---|
| 129 | public static final int $1 = $2;
|
---|
| 130 | ])
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
|
---|
| 134 | # -----------------------------------------------------
|
---|
| 135 | # Output the definition of the tokens (if there are) as enums.
|
---|
| 136 | m4_define([b4_token_enums],
|
---|
| 137 | [m4_if([$#$1], [1], [],
|
---|
| 138 | [/* Tokens. */
|
---|
| 139 | m4_map([b4_token_enum], [$@])])
|
---|
| 140 | ])
|
---|
| 141 |
|
---|
| 142 | # b4-case(ID, CODE)
|
---|
| 143 | # -----------------
|
---|
| 144 | # We need to fool Java's stupid unreachable code detection.
|
---|
| 145 | m4_define([b4_case], [ case $1:
|
---|
| 146 | if (yyn == $1)
|
---|
| 147 | $2;
|
---|
| 148 | break;
|
---|
| 149 | ])
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | ## ---------------- ##
|
---|
| 153 | ## Default values. ##
|
---|
| 154 | ## ---------------- ##
|
---|
| 155 |
|
---|
| 156 | m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
|
---|
| 157 | b4_percent_define_default([[stype]], [[Object]])])
|
---|
| 158 |
|
---|
| 159 | # %name-prefix
|
---|
| 160 | m4_define_default([b4_prefix], [[YY]])
|
---|
| 161 |
|
---|
| 162 | b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
|
---|
| 163 | m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
|
---|
| 164 |
|
---|
| 165 | b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
|
---|
| 166 | m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
|
---|
| 167 |
|
---|
| 168 | b4_percent_define_default([[throws]], [])])
|
---|
| 169 | m4_define([b4_throws], [b4_percent_define_get([[throws]])])
|
---|
| 170 |
|
---|
| 171 | b4_percent_define_default([[location_type]], [Location])])
|
---|
| 172 | m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
|
---|
| 173 |
|
---|
| 174 | b4_percent_define_default([[position_type]], [Position])])
|
---|
| 175 | m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | ## ----------------- ##
|
---|
| 179 | ## Semantic Values. ##
|
---|
| 180 | ## ----------------- ##
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | # b4_lhs_value([TYPE])
|
---|
| 184 | # --------------------
|
---|
| 185 | # Expansion of $<TYPE>$.
|
---|
| 186 | m4_define([b4_lhs_value], [yyval])
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
|
---|
| 190 | # --------------------------------------
|
---|
| 191 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
|
---|
| 192 | # symbols on RHS.
|
---|
| 193 | #
|
---|
| 194 | # In this simple implementation, %token and %type have class names
|
---|
| 195 | # between the angle brackets.
|
---|
| 196 | m4_define([b4_rhs_value],
|
---|
| 197 | [(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
|
---|
| 198 |
|
---|
| 199 | # b4_lhs_location()
|
---|
| 200 | # -----------------
|
---|
| 201 | # Expansion of @$.
|
---|
| 202 | m4_define([b4_lhs_location],
|
---|
| 203 | [(yyloc)])
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | # b4_rhs_location(RULE-LENGTH, NUM)
|
---|
| 207 | # ---------------------------------
|
---|
| 208 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
|
---|
| 209 | # on RHS.
|
---|
| 210 | m4_define([b4_rhs_location],
|
---|
| 211 | [yystack.locationAt ($1-($2))])
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 | # b4_lex_param
|
---|
| 215 | # b4_parse_param
|
---|
| 216 | # --------------
|
---|
| 217 | # If defined, b4_lex_param arrives double quoted, but below we prefer
|
---|
| 218 | # it to be single quoted. Same for b4_parse_param.
|
---|
| 219 |
|
---|
| 220 | # TODO: should be in bison.m4
|
---|
| 221 | m4_define_default([b4_lex_param], [[]]))
|
---|
| 222 | m4_define([b4_lex_param], b4_lex_param))
|
---|
| 223 | m4_define([b4_parse_param], b4_parse_param))
|
---|
| 224 |
|
---|
| 225 | # b4_lex_param_decl
|
---|
| 226 | # -------------------
|
---|
| 227 | # Extra formal arguments of the constructor.
|
---|
| 228 | m4_define([b4_lex_param_decl],
|
---|
| 229 | [m4_ifset([b4_lex_param],
|
---|
| 230 | [b4_remove_comma([$1],
|
---|
| 231 | b4_param_decls(b4_lex_param))],
|
---|
| 232 | [$1])])
|
---|
| 233 |
|
---|
| 234 | m4_define([b4_param_decls],
|
---|
| 235 | [m4_map([b4_param_decl], [$@])])
|
---|
| 236 | m4_define([b4_param_decl], [, $1])
|
---|
| 237 |
|
---|
| 238 | m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | # b4_parse_param_decl
|
---|
| 243 | # -------------------
|
---|
| 244 | # Extra formal arguments of the constructor.
|
---|
| 245 | m4_define([b4_parse_param_decl],
|
---|
| 246 | [m4_ifset([b4_parse_param],
|
---|
| 247 | [b4_remove_comma([$1],
|
---|
| 248 | b4_param_decls(b4_parse_param))],
|
---|
| 249 | [$1])])
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 | # b4_lex_param_call
|
---|
| 254 | # -------------------
|
---|
| 255 | # Delegating the lexer parameters to the lexer constructor.
|
---|
| 256 | m4_define([b4_lex_param_call],
|
---|
| 257 | [m4_ifset([b4_lex_param],
|
---|
| 258 | [b4_remove_comma([$1],
|
---|
| 259 | b4_param_calls(b4_lex_param))],
|
---|
| 260 | [$1])])
|
---|
| 261 | m4_define([b4_param_calls],
|
---|
| 262 | [m4_map([b4_param_call], [$@])])
|
---|
| 263 | m4_define([b4_param_call], [, $2])
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | # b4_parse_param_cons
|
---|
| 268 | # -------------------
|
---|
| 269 | # Extra initialisations of the constructor.
|
---|
| 270 | m4_define([b4_parse_param_cons],
|
---|
| 271 | [m4_ifset([b4_parse_param],
|
---|
| 272 | [b4_constructor_calls(b4_parse_param)])])
|
---|
| 273 |
|
---|
| 274 | m4_define([b4_constructor_calls],
|
---|
| 275 | [m4_map([b4_constructor_call], [$@])])
|
---|
| 276 | m4_define([b4_constructor_call],
|
---|
| 277 | [this.$2 = $2;
|
---|
| 278 | ])
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | # b4_parse_param_vars
|
---|
| 283 | # -------------------
|
---|
| 284 | # Extra instance variables.
|
---|
| 285 | m4_define([b4_parse_param_vars],
|
---|
| 286 | [m4_ifset([b4_parse_param],
|
---|
| 287 | [
|
---|
| 288 | /* User arguments. */
|
---|
| 289 | b4_var_decls(b4_parse_param)])])
|
---|
| 290 |
|
---|
| 291 | m4_define([b4_var_decls],
|
---|
| 292 | [m4_map_sep([b4_var_decl], [
|
---|
| 293 | ], [$@])])
|
---|
| 294 | m4_define([b4_var_decl],
|
---|
| 295 | [ protected final $1;])
|
---|
| 296 |
|
---|
| 297 |
|
---|
| 298 |
|
---|
| 299 | # b4_maybe_throws(THROWS)
|
---|
| 300 | # -----------------------
|
---|
| 301 | # Expand to either an empty string or "throws THROWS".
|
---|
| 302 | m4_define([b4_maybe_throws],
|
---|
| 303 | [m4_ifval($1, [throws $1])])
|
---|