]> git.saurik.com Git - bison.git/blob - data/java.m4
38820f0d20fb36eca4ed25fd6499406f0d0f652e
[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 # 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])])
46
47
48 # b4_abstract_if(TRUE, FALSE)
49 # ---------------------------
50 m4_define([b4_abstract_if],
51 [b4_pure_if([$2], [b4_single_class_if([$2], [$1])])])
52
53
54 # b4_identification
55 # -----------------
56 m4_define([b4_identification],
57 [/** Always <tt>true</tt>, identifies Bison output. */
58 public static final boolean bison = true;
59
60 /** Version number for the Bison executable that generated this parser. */
61 public static final String bisonVersion = "b4_version";
62
63 /** Name of the skeleton that generated this parser. */
64 public static final String bisonSkeleton = b4_skeleton;
65 ])
66
67
68 ## ------------ ##
69 ## Data types. ##
70 ## ------------ ##
71
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],
79 [int])])
80
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)])
87
88 # b4_null
89 # -------
90 m4_define([b4_null], [null])
91
92
93 ## ------------------------- ##
94 ## Assigning token numbers. ##
95 ## ------------------------- ##
96
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;
103 ])
104
105
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([$@], [[]], [],
111 [/* Tokens. */
112 m4_map([b4_token_enum], [$@])])
113 ])
114
115 # b4-case(ID, CODE)
116 # -----------------
117 # We need to fool Java's stupid unreachable code detection.
118 m4_define([b4_case], [ case $1:
119 if (yyn == $1)
120 $2;
121 break;
122 ])
123
124
125 ## ---------------- ##
126 ## Default values. ##
127 ## ---------------- ##
128
129 m4_define([b4_union_name], [b4_percent_define_get([[union_name]])])
130 b4_percent_define_default([[union_name]], [[Object]])])
131
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]])])
135
136 b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
137 m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
138
139 b4_percent_define_default([[throws]], [b4_lex_throws])])
140 m4_define([b4_throws], [b4_percent_define_get([[throws]])])
141
142 b4_percent_define_default([[location_type]], [Location])])
143 m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
144
145 b4_percent_define_default([[position_type]], [Position])])
146 m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
147
148
149 ## ----------------- ##
150 ## Semantic Values. ##
151 ## ----------------- ##
152
153
154 # b4_lhs_value([TYPE])
155 # --------------------
156 # Expansion of $<TYPE>$.
157 m4_define([b4_lhs_value], [yyval])
158
159
160 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
161 # --------------------------------------
162 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
163 # symbols on RHS.
164 #
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))))])
169
170 # b4_lhs_location()
171 # -----------------
172 # Expansion of @$.
173 m4_define([b4_lhs_location],
174 [(yyloc)])
175
176
177 # b4_rhs_location(RULE-LENGTH, NUM)
178 # ---------------------------------
179 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
180 # on RHS.
181 m4_define([b4_rhs_location],
182 [yystack.locationAt ($1-($2))])
183
184
185 # b4_lex_param
186 # b4_parse_param
187 # --------------
188 # If defined, b4_lex_param arrives double quoted, but below we prefer
189 # it to be single quoted. Same for b4_parse_param.
190
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))
195
196 # b4_lex_param_decl
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])])],
203 [$1])])
204
205 m4_define([b4_lex_param_decl_1], [, $1])
206 m4_define([b4_remove_comma], [m4_ifval([$1], [$1, ], [])m4_cdr([m4_cdr($@)])])
207
208
209
210 # b4_lex_param_call
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)])],
217 [$1])])
218 m4_define([b4_lex_param_calls],
219 [m4_map([b4_lex_param_call_1], [$@])])
220 m4_define([b4_lex_param_call_1], [, $2])
221
222
223
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])])],
232 [$1])])
233
234 m4_define([b4_parse_param_decl_1], [, $1])
235
236
237
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],
247 [this.$2 = $2;
248 ])
249
250 # b4_parse_param_vars
251 # -------------------
252 # Extra instance variables.
253 m4_define([b4_parse_param_vars],
254 [m4_ifset([b4_parse_param],
255 [
256 /* User arguments. */
257 b4_var_decls(b4_parse_param)])])
258 m4_define([b4_var_decls],
259 [m4_map_sep([b4_var_decl], [
260 ], [$@])])
261 m4_define([b4_var_decl],
262 [ protected final $1;])
263
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])])