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