]> git.saurik.com Git - bison.git/blob - data/java.m4
Don't depend on C99 features.
[bison.git] / data / java.m4
1 -*- Autoconf -*-
2
3 # Java language support for Bison
4
5 # Copyright (C) 2007 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 2 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, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301 USA
21
22
23 # b4_comment(TEXT)
24 # ----------------
25 m4_define([b4_comment], [/* m4_bpatsubst([$1], [
26 ], [
27 ]) */])
28
29
30 # b4_flag_value(BOOLEAN-FLAG)
31 # ---------------------------
32 m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
33
34
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])])
40
41
42 # b4_abstract_if(TRUE, FALSE)
43 # ---------------------------
44 b4_percent_define_default([[abstract]], [[false]])
45 m4_define([b4_abstract_if],
46 [b4_percent_define_flag_if([abstract], [$1], [$2])])
47
48
49 # b4_lexer_if(TRUE, FALSE)
50 # ------------------------
51 m4_define([b4_lexer_if],
52 [b4_percent_code_ifdef([[lexer]], [$1], [$2])])
53
54
55 # b4_identification
56 # -----------------
57 m4_define([b4_identification],
58 [/** Always <tt>true</tt>, identifies Bison output. */
59 public static final boolean bison = true;
60
61 /** Version number for the Bison executable that generated this parser. */
62 public static final String bisonVersion = "b4_version";
63
64 /** Name of the skeleton that generated this parser. */
65 public static final String bisonSkeleton = b4_skeleton;
66 ])
67
68
69 ## ------------ ##
70 ## Data types. ##
71 ## ------------ ##
72
73 # b4_int_type(MIN, MAX)
74 # ---------------------
75 # Return the smallest int type able to handle numbers ranging from
76 # MIN to MAX (included).
77 m4_define([b4_int_type],
78 [m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
79 b4_ints_in($@, [-32768], [32767]), [1], [short],
80 [int])])
81
82 # b4_int_type_for(NAME)
83 # ---------------------
84 # Return the smallest int type able to handle numbers ranging from
85 # `NAME_min' to `NAME_max' (included).
86 m4_define([b4_int_type_for],
87 [b4_int_type($1_min, $1_max)])
88
89 # b4_null
90 # -------
91 m4_define([b4_null], [null])
92
93
94 ## ------------------------- ##
95 ## Assigning token numbers. ##
96 ## ------------------------- ##
97
98 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
99 # ---------------------------------------
100 # Output the definition of this token as an enum.
101 m4_define([b4_token_enum],
102 [ /** Token number, to be returned by the scanner. */
103 public static final int $1 = $2;
104 ])
105
106
107 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
108 # -----------------------------------------------------
109 # Output the definition of the tokens (if there are) as enums.
110 m4_define([b4_token_enums],
111 [m4_if([$@], [[]], [],
112 [/* Tokens. */
113 m4_map([b4_token_enum], [$@])])
114 ])
115
116 # b4-case(ID, CODE)
117 # -----------------
118 # We need to fool Java's stupid unreachable code detection.
119 m4_define([b4_case], [ case $1:
120 if (yyn == $1)
121 $2;
122 break;
123 ])
124
125
126 ## ---------------- ##
127 ## Default values. ##
128 ## ---------------- ##
129
130 m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
131 b4_percent_define_default([[stype]], [[Object]])])
132
133 m4_define_default([[b4_prefix]], [[YY]])])
134 b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
135 m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
136
137 b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
138 m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
139
140 b4_percent_define_default([[throws]], [b4_lex_throws])])
141 m4_define([b4_throws], [b4_percent_define_get([[throws]])])
142
143 b4_percent_define_default([[location_type]], [Location])])
144 m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
145
146 b4_percent_define_default([[position_type]], [Position])])
147 m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
148
149
150 ## ----------------- ##
151 ## Semantic Values. ##
152 ## ----------------- ##
153
154
155 # b4_lhs_value([TYPE])
156 # --------------------
157 # Expansion of $<TYPE>$.
158 m4_define([b4_lhs_value], [yyval])
159
160
161 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
162 # --------------------------------------
163 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
164 # symbols on RHS.
165 #
166 # In this simple implementation, %token and %type have class names
167 # between the angle brackets.
168 m4_define([b4_rhs_value],
169 [(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
170
171 # b4_lhs_location()
172 # -----------------
173 # Expansion of @$.
174 m4_define([b4_lhs_location],
175 [(yyloc)])
176
177
178 # b4_rhs_location(RULE-LENGTH, NUM)
179 # ---------------------------------
180 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
181 # on RHS.
182 m4_define([b4_rhs_location],
183 [yystack.locationAt ($1-($2))])
184
185
186 # b4_lex_param
187 # b4_parse_param
188 # --------------
189 # If defined, b4_lex_param arrives double quoted, but below we prefer
190 # it to be single quoted. Same for b4_parse_param.
191
192 # TODO: should be in bison.m4
193 m4_define_default([b4_lex_param], [[]]))
194 m4_define([b4_lex_param], b4_lex_param))
195 m4_define([b4_parse_param], b4_parse_param))
196
197 # b4_lex_param_decl
198 # -------------------
199 # Extra formal arguments of the constructor.
200 m4_define([b4_lex_param_decl],
201 [m4_ifset([b4_lex_param],
202 [b4_remove_comma([$1],
203 b4_param_decls(b4_lex_param))],
204 [$1])])
205
206 m4_define([b4_param_decls],
207 [m4_map([b4_param_decl], [$@])])
208 m4_define([b4_param_decl], [, $1])
209
210 m4_define([b4_remove_comma], [m4_ifval($1, [$1, ], [])m4_shiftn(2, $@)])
211
212
213
214 # b4_parse_param_decl
215 # -------------------
216 # Extra formal arguments of the constructor.
217 m4_define([b4_parse_param_decl],
218 [m4_ifset([b4_parse_param],
219 [b4_remove_comma([$1],
220 b4_param_decls(b4_parse_param))],
221 [$1])])
222
223
224
225 # b4_lex_param_call
226 # -------------------
227 # Delegating the lexer parameters to the lexer constructor.
228 m4_define([b4_lex_param_call],
229 [m4_ifset([b4_lex_param],
230 [b4_remove_comma([$1],
231 b4_param_calls(b4_lex_param))],
232 [$1])])
233 m4_define([b4_param_calls],
234 [m4_map([b4_param_call], [$@])])
235 m4_define([b4_param_call], [, $2])
236
237
238
239 # b4_parse_param_cons
240 # -------------------
241 # Extra initialisations of the constructor.
242 m4_define([b4_parse_param_cons],
243 [m4_ifset([b4_parse_param],
244 [b4_constructor_calls(b4_parse_param)])])
245
246 m4_define([b4_constructor_calls],
247 [m4_map([b4_constructor_call], [$@])])
248 m4_define([b4_constructor_call],
249 [this.$2 = $2;
250 ])
251
252
253
254 # b4_parse_param_vars
255 # -------------------
256 # Extra instance variables.
257 m4_define([b4_parse_param_vars],
258 [m4_ifset([b4_parse_param],
259 [
260 /* User arguments. */
261 b4_var_decls(b4_parse_param)])])
262
263 m4_define([b4_var_decls],
264 [m4_map_sep([b4_var_decl], [
265 ], [$@])])
266 m4_define([b4_var_decl],
267 [ protected final $1;])
268
269
270
271 # b4_maybe_throws(THROWS)
272 # -----------------------
273 # Expand to either an empty string or "throws THROWS".
274 m4_define([b4_maybe_throws],
275 [m4_ifval($1, [throws $1])])