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