3 # Java language support for Bison
5 # Copyright (C) 2007 Free Software Foundation, Inc.
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 2 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 m4_define([b4_comment], [/* m4_bpatsubst([$1], [
30 # b4_flag_value(BOOLEAN-FLAG)
31 # ---------------------------
32 m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
35 # b4_public_if(TRUE, FALSE)
36 # -------------------------
37 b4_percent_define_default([[public]], [[false]])
38 m4_define([b4_public_if],
39 [b4_percent_define_flag_if([public], [$1], [$2])])
41 # b4_single_class_if(TRUE, FALSE)
42 # -------------------------------
43 b4_percent_define_default([[single_class]], [[false]])
44 m4_define([b4_single_class_if],
45 [b4_percent_define_flag_if([single_class], [$1], [$2])])
48 # b4_abstract_if(TRUE, FALSE)
49 # ---------------------------
50 m4_define([b4_abstract_if],
51 [b4_pure_if([$2], [b4_single_class_if([$2], [$1])])])
56 m4_define([b4_identification],
57 [/** Always <tt>true</tt>, identifies Bison output. */
58 public static final boolean bison = true;
60 /** Version number for the Bison executable that generated this parser. */
61 public static final String bisonVersion = "b4_version";
63 /** Name of the skeleton that generated this parser. */
64 public static final String bisonSkeleton = b4_skeleton;
72 # b4_int_type(MIN, MAX)
73 # ---------------------
74 # Return the smallest int type able to handle numbers ranging from
75 # MIN to MAX (included).
76 m4_define([b4_int_type],
77 [m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
78 b4_ints_in($@, [-32768], [32767]), [1], [short],
81 # b4_int_type_for(NAME)
82 # ---------------------
83 # Return the smallest int type able to handle numbers ranging from
84 # `NAME_min' to `NAME_max' (included).
85 m4_define([b4_int_type_for],
86 [b4_int_type($1_min, $1_max)])
90 m4_define([b4_null], [null])
93 ## ------------------------- ##
94 ## Assigning token numbers. ##
95 ## ------------------------- ##
97 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
98 # ---------------------------------------
99 # Output the definition of this token as an enum.
100 m4_define([b4_token_enum],
101 [ /** Token number, to be returned by the scanner. */
102 public static final int $1 = $2;
106 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
107 # -----------------------------------------------------
108 # Output the definition of the tokens (if there are) as enums.
109 m4_define([b4_token_enums],
110 [m4_if([$@], [[]], [],
112 m4_map([b4_token_enum], [$@])])
117 # We need to fool Java's stupid unreachable code detection.
118 m4_define([b4_case], [ case $1:
125 ## ---------------- ##
126 ## Default values. ##
127 ## ---------------- ##
129 m4_define([b4_union_name], [b4_percent_define_get([[union_name]])])
130 b4_percent_define_default([[union_name]], [[Object]])])
132 m4_define_default([[b4_prefix]], [[YY]])])
133 b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
134 m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
136 b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
137 m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
139 b4_percent_define_default([[throws]], [b4_lex_throws])])
140 m4_define([b4_throws], [b4_percent_define_get([[throws]])])
142 b4_percent_define_default([[location_type]], [Location])])
143 m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
145 b4_percent_define_default([[position_type]], [Position])])
146 m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
149 ## ----------------- ##
150 ## Semantic Values. ##
151 ## ----------------- ##
154 # b4_lhs_value([TYPE])
155 # --------------------
156 # Expansion of $<TYPE>$.
157 m4_define([b4_lhs_value], [yyval])
160 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
161 # --------------------------------------
162 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
165 # In this simple implementation, %token and %type have class names
166 # between the angle brackets.
167 m4_define([b4_rhs_value],
168 [(m4_ifval([$3], [($3)])[](yystack.valueAt ($1-($2))))])
173 m4_define([b4_lhs_location],
177 # b4_rhs_location(RULE-LENGTH, NUM)
178 # ---------------------------------
179 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
181 m4_define([b4_rhs_location],
182 [yystack.locationAt ($1-($2))])
188 # If defined, b4_lex_param arrives double quoted, but below we prefer
189 # it to be single quoted. Same for b4_parse_param.
191 # TODO: should be in bison.m4
192 m4_define_default([b4_lex_param], [[]]))
193 m4_define([b4_lex_param], b4_lex_param))
194 m4_define([b4_parse_param], b4_parse_param))
197 # -------------------
198 # Extra formal arguments of the constructor.
199 m4_define([b4_lex_param_decl],
200 [m4_ifset([b4_lex_param],
201 [b4_remove_comma([$1],
202 [m4_map([b4_lex_param_decl_1], [b4_lex_param])])],
205 m4_define([b4_lex_param_decl_1], [, $1])
206 m4_define([b4_remove_comma], [m4_ifval([$1], [$1, ], [])m4_cdr([m4_cdr($@)])])
211 # -------------------
212 # Extra initialisations of the constructor.
213 m4_define([b4_lex_param_call],
214 [m4_ifset([b4_lex_param],
215 [b4_remove_comma([$1],
216 [b4_lex_param_calls(b4_lex_param)])],
218 m4_define([b4_lex_param_calls],
219 [m4_map([b4_lex_param_call_1], [$@])])
220 m4_define([b4_lex_param_call_1], [, $2])
224 # b4_parse_param_decl
225 # -------------------
226 # Extra formal arguments of the constructor.
227 m4_define([b4_parse_param_decl],
228 [m4_ifset([b4_parse_param],
229 [b4_remove_comma([$1],
230 [m4_map([b4_parse_param_decl_1],
231 [b4_parse_param])])],
234 m4_define([b4_parse_param_decl_1], [, $1])
238 # b4_parse_param_cons
239 # -------------------
240 # Extra initialisations of the constructor.
241 m4_define([b4_parse_param_cons],
242 [m4_ifset([b4_parse_param],
243 [b4_constructor_calls(b4_parse_param)])])
244 m4_define([b4_constructor_calls],
245 [m4_map([b4_constructor_call], [$@])])
246 m4_define([b4_constructor_call],
250 # b4_parse_param_vars
251 # -------------------
252 # Extra instance variables.
253 m4_define([b4_parse_param_vars],
254 [m4_ifset([b4_parse_param],
256 /* User arguments. */
257 b4_var_decls(b4_parse_param)])])
258 m4_define([b4_var_decls],
259 [m4_map_sep([b4_var_decl], [
261 m4_define([b4_var_decl],
262 [ protected final $1;])
264 # b4_maybe_throws(THROWS)
265 # -----------------------
266 # Expand to either an empty string or "throws THROWS".
267 m4_define([b4_maybe_throws],
268 [m4_ifval([$1], [throws $1])])