]> git.saurik.com Git - bison.git/blame - data/java.m4
* NEWS (2.3a+): Mention yesterday's state-removal change.
[bison.git] / data / java.m4
CommitLineData
8405b70c
PB
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# ----------------
25m4_define([b4_comment], [/* m4_bpatsubst([$1], [
26], [
27 ]) */])
28
29
30# b4_flag_value(BOOLEAN-FLAG)
31# ---------------------------
32m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
33
34
35# b4_public_if(TRUE, FALSE)
36# -------------------------
c1d19e10 37b4_percent_define_default([[public]], [[false]])
8405b70c
PB
38m4_define([b4_public_if],
39[b4_percent_define_flag_if([public], [$1], [$2])])
40
8405b70c
PB
41
42# b4_abstract_if(TRUE, FALSE)
43# ---------------------------
01b477c6 44b4_percent_define_default([[abstract]], [[false]])
8405b70c 45m4_define([b4_abstract_if],
01b477c6
PB
46[b4_percent_define_flag_if([abstract], [$1], [$2])])
47
48
49# b4_lexer_if(TRUE, FALSE)
50# ------------------------
51m4_define([b4_lexer_if],
52[b4_percent_code_ifdef([[lexer]], [$1], [$2])])
8405b70c
PB
53
54
55# b4_identification
56# -----------------
57m4_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).
77m4_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).
86m4_define([b4_int_type_for],
87[b4_int_type($1_min, $1_max)])
88
89# b4_null
90# -------
91m4_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.
101m4_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.
110m4_define([b4_token_enums],
111[m4_if([$@], [[]], [],
112[/* Tokens. */
113m4_map([b4_token_enum], [$@])])
114])
115
116# b4-case(ID, CODE)
117# -----------------
118# We need to fool Java's stupid unreachable code detection.
119m4_define([b4_case], [ case $1:
120 if (yyn == $1)
121 $2;
122 break;
123 ])
124
125
126## ---------------- ##
127## Default values. ##
128## ---------------- ##
129
01b477c6
PB
130m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
131b4_percent_define_default([[stype]], [[Object]])])
8405b70c
PB
132
133m4_define_default([[b4_prefix]], [[YY]])])
134b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
135m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
136
137b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
138m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
139
140b4_percent_define_default([[throws]], [b4_lex_throws])])
141m4_define([b4_throws], [b4_percent_define_get([[throws]])])
142
143b4_percent_define_default([[location_type]], [Location])])
144m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
145
146b4_percent_define_default([[position_type]], [Position])])
147m4_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>$.
158m4_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.
168m4_define([b4_rhs_value],
01b477c6 169[(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
8405b70c
PB
170
171# b4_lhs_location()
172# -----------------
173# Expansion of @$.
174m4_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.
182m4_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
193m4_define_default([b4_lex_param], [[]]))
194m4_define([b4_lex_param], b4_lex_param))
195m4_define([b4_parse_param], b4_parse_param))
196
197# b4_lex_param_decl
198# -------------------
199# Extra formal arguments of the constructor.
200m4_define([b4_lex_param_decl],
201[m4_ifset([b4_lex_param],
202 [b4_remove_comma([$1],
01b477c6 203 b4_param_decls(b4_lex_param))],
8405b70c
PB
204 [$1])])
205
01b477c6
PB
206m4_define([b4_param_decls],
207 [m4_map([b4_param_decl], [$@])])
208m4_define([b4_param_decl], [, $1])
8405b70c 209
01b477c6 210m4_define([b4_remove_comma], [m4_ifval($1, [$1, ], [])m4_shiftn(2, $@)])
8405b70c
PB
211
212
213
214# b4_parse_param_decl
215# -------------------
216# Extra formal arguments of the constructor.
217m4_define([b4_parse_param_decl],
218[m4_ifset([b4_parse_param],
219 [b4_remove_comma([$1],
01b477c6 220 b4_param_decls(b4_parse_param))],
8405b70c
PB
221 [$1])])
222
01b477c6
PB
223
224
225# b4_lex_param_call
226# -------------------
227# Delegating the lexer parameters to the lexer constructor.
228m4_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])])
233m4_define([b4_param_calls],
234 [m4_map([b4_param_call], [$@])])
235m4_define([b4_param_call], [, $2])
8405b70c
PB
236
237
238
239# b4_parse_param_cons
240# -------------------
241# Extra initialisations of the constructor.
242m4_define([b4_parse_param_cons],
243 [m4_ifset([b4_parse_param],
244 [b4_constructor_calls(b4_parse_param)])])
01b477c6 245
8405b70c
PB
246m4_define([b4_constructor_calls],
247 [m4_map([b4_constructor_call], [$@])])
248m4_define([b4_constructor_call],
249 [this.$2 = $2;
250 ])
251
01b477c6
PB
252
253
8405b70c
PB
254# b4_parse_param_vars
255# -------------------
256# Extra instance variables.
257m4_define([b4_parse_param_vars],
258 [m4_ifset([b4_parse_param],
259 [
260 /* User arguments. */
261b4_var_decls(b4_parse_param)])])
01b477c6 262
8405b70c
PB
263m4_define([b4_var_decls],
264 [m4_map_sep([b4_var_decl], [
265], [$@])])
266m4_define([b4_var_decl],
267 [ protected final $1;])
268
01b477c6
PB
269
270
8405b70c
PB
271# b4_maybe_throws(THROWS)
272# -----------------------
273# Expand to either an empty string or "throws THROWS".
274m4_define([b4_maybe_throws],
01b477c6 275 [m4_ifval($1, [throws $1])])