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