* data/yacc.c (yyparse): Correct the comment when locations aren't used.
[bison.git] / data / java.m4
blob3f259fd5d7759523a1b25bbef755cd28318d0d29
1                                                             -*- Autoconf -*-
3 # Java language support for Bison
5 # Copyright (C) 2007 Free Software Foundation, Inc.
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 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 # b4_comment(TEXT)
22 # ----------------
23 m4_define([b4_comment], [/* m4_bpatsubst([$1], [
24 ], [
25    ])  */])
28 # b4_flag_value(BOOLEAN-FLAG)
29 # ---------------------------
30 m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
33 # b4_public_if(TRUE, FALSE)
34 # -------------------------
35 b4_percent_define_default([[public]], [[false]])
36 m4_define([b4_public_if],
37 [b4_percent_define_flag_if([public], [$1], [$2])])
40 # b4_abstract_if(TRUE, FALSE)
41 # ---------------------------
42 b4_percent_define_default([[abstract]], [[false]])
43 m4_define([b4_abstract_if],
44 [b4_percent_define_flag_if([abstract], [$1], [$2])])
47 # b4_lexer_if(TRUE, FALSE)
48 # ------------------------
49 m4_define([b4_lexer_if],
50 [b4_percent_code_ifdef([[lexer]], [$1], [$2])])
53 # b4_identification
54 # -----------------
55 m4_define([b4_identification],
56 [/** Always <tt>true</tt>, identifies Bison output.  */
57   public static final boolean bison = true;
59   /** Version number for the Bison executable that generated this parser.  */
60   public static final String bisonVersion = "b4_version";
62   /** Name of the skeleton that generated this parser.  */
63   public static final String bisonSkeleton = b4_skeleton;
67 ## ------------ ##
68 ## Data types.  ##
69 ## ------------ ##
71 # b4_int_type(MIN, MAX)
72 # ---------------------
73 # Return the smallest int type able to handle numbers ranging from
74 # MIN to MAX (included).
75 m4_define([b4_int_type],
76 [m4_if(b4_ints_in($@,   [-128],   [127]), [1], [byte],
77        b4_ints_in($@, [-32768], [32767]), [1], [short],
78                                                [int])])
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).
84 m4_define([b4_int_type_for],
85 [b4_int_type($1_min, $1_max)])
87 # b4_null
88 # -------
89 m4_define([b4_null], [null])
92 ## ------------------------- ##
93 ## Assigning token numbers.  ##
94 ## ------------------------- ##
96 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
97 # ---------------------------------------
98 # Output the definition of this token as an enum.
99 m4_define([b4_token_enum],
100 [  /** Token number, to be returned by the scanner.  */
101   public static final int $1 = $2;
105 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
106 # -----------------------------------------------------
107 # Output the definition of the tokens (if there are) as enums.
108 m4_define([b4_token_enums],
109 [m4_if([$@], [[]], [],
110 [/* Tokens.  */
111 m4_map([b4_token_enum], [$@])])
114 # b4-case(ID, CODE)
115 # -----------------
116 # We need to fool Java's stupid unreachable code detection.
117 m4_define([b4_case], [  case $1:
118   if (yyn == $1)
119     $2;
120   break;
121     ])
124 ## ---------------- ##
125 ## Default values.  ##
126 ## ---------------- ##
128 m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
129 b4_percent_define_default([[stype]], [[Object]])])
131 m4_define_default([[b4_prefix]], [[YY]])])
132 b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
133 m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
135 b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
136 m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
138 b4_percent_define_default([[throws]], [b4_lex_throws])])
139 m4_define([b4_throws], [b4_percent_define_get([[throws]])])
141 b4_percent_define_default([[location_type]], [Location])])
142 m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
144 b4_percent_define_default([[position_type]], [Position])])
145 m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
148 ## ----------------- ##
149 ## Semantic Values.  ##
150 ## ----------------- ##
153 # b4_lhs_value([TYPE])
154 # --------------------
155 # Expansion of $<TYPE>$.
156 m4_define([b4_lhs_value], [yyval])
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.
164 # In this simple implementation, %token and %type have class names
165 # between the angle brackets.
166 m4_define([b4_rhs_value],
167 [(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
169 # b4_lhs_location()
170 # -----------------
171 # Expansion of @$.
172 m4_define([b4_lhs_location],
173 [(yyloc)])
176 # b4_rhs_location(RULE-LENGTH, NUM)
177 # ---------------------------------
178 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
179 # on RHS.
180 m4_define([b4_rhs_location],
181 [yystack.locationAt ($1-($2))])
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.
190 # TODO: should be in bison.m4
191 m4_define_default([b4_lex_param], [[]]))
192 m4_define([b4_lex_param], b4_lex_param))
193 m4_define([b4_parse_param], b4_parse_param))
195 # b4_lex_param_decl
196 # -------------------
197 # Extra formal arguments of the constructor.
198 m4_define([b4_lex_param_decl],
199 [m4_ifset([b4_lex_param],
200           [b4_remove_comma([$1],
201                            b4_param_decls(b4_lex_param))],
202           [$1])])
204 m4_define([b4_param_decls],
205           [m4_map([b4_param_decl], [$@])])
206 m4_define([b4_param_decl], [, $1])
208 m4_define([b4_remove_comma], [m4_ifval($1, [$1, ], [])m4_shiftn(2, $@)])
212 # b4_parse_param_decl
213 # -------------------
214 # Extra formal arguments of the constructor.
215 m4_define([b4_parse_param_decl],
216 [m4_ifset([b4_parse_param],
217           [b4_remove_comma([$1],
218                            b4_param_decls(b4_parse_param))],
219           [$1])])
223 # b4_lex_param_call
224 # -------------------
225 # Delegating the lexer parameters to the lexer constructor.
226 m4_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])])
231 m4_define([b4_param_calls],
232           [m4_map([b4_param_call], [$@])])
233 m4_define([b4_param_call], [, $2])
237 # b4_parse_param_cons
238 # -------------------
239 # Extra initialisations of the constructor.
240 m4_define([b4_parse_param_cons],
241           [m4_ifset([b4_parse_param],
242                     [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           ])
252 # b4_parse_param_vars
253 # -------------------
254 # Extra instance variables.
255 m4_define([b4_parse_param_vars],
256           [m4_ifset([b4_parse_param],
257                     [
258     /* User arguments.  */
259 b4_var_decls(b4_parse_param)])])
261 m4_define([b4_var_decls],
262           [m4_map_sep([b4_var_decl], [
263 ], [$@])])
264 m4_define([b4_var_decl],
265           [    protected final $1;])
269 # b4_maybe_throws(THROWS)
270 # -----------------------
271 # Expand to either an empty string or "throws THROWS".
272 m4_define([b4_maybe_throws],
273           [m4_ifval($1, [throws $1])])