1 m4_divert(-1) -*- Autoconf -*-
3 # C M4 Macros for Bison.
4 # Copyright (C) 2002 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 ## ---------------- ##
24 ## ---------------- ##
26 # b4_copyright(TITLE, YEARS)
27 # --------------------------
28 m4_define([b4_copyright],
29 [/* A Bison parser, made from b4_filename, by GNU bison b4_version. */
32 Copyright (C) $2 Free Software Foundation, Inc.
34 This program is free software; you can redistribute it and/or modify
35 it under the terms of the GNU General Public License as published by
36 the Free Software Foundation; either version 2, or (at your option)
39 This program is distributed in the hope that it will be useful,
40 but WITHOUT ANY WARRANTY; without even the implied warranty of
41 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 GNU General Public License for more details.
44 You should have received a copy of the GNU General Public License
45 along with this program; if not, write to the Free Software
46 Foundation, Inc., 59 Temple Place - Suite 330,
47 Boston, MA 02111-1307, USA. */])
52 m4_define([b4_identification],
53 [/* Identify Bison output. */
57 [#]define YYSKELETON_NAME "b4_skeleton"
60 [#]define YYPURE b4_pure
62 /* Using locations. */
63 [#]define YYLSP_NEEDED b4_locations_flag
68 ## ------------------------ ##
69 ## Pure/impure interfaces. ##
70 ## ------------------------ ##
75 m4_define([b4_user_args],
76 [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])])
81 # If defined, b4_parse_param arrives double quoted, but below we prefer
82 # it to be single quoted.
83 m4_define_default([b4_parse_param])
84 m4_define([b4_parse_param],
94 # b4_ints_in(INT1, INT2, LOW, HIGH)
95 # ---------------------------------
96 # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
97 m4_define([b4_ints_in],
98 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
101 # b4_int_type(MIN, MAX)
102 # ---------------------
103 # Return the smallest int type able to handle numbers ranging from
104 # MIN to MAX (included).
105 m4_define([b4_int_type],
106 [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
107 b4_ints_in($@, [-128], [127]), [1], [signed char],
109 b4_ints_in($@, [0], [65535]), [1], [unsigned short],
110 b4_ints_in($@, [-32768], [32767]), [1], [short],
112 m4_eval([0 <= $1]), [1], [unsigned int],
117 # b4_int_type_for(NAME)
118 # ---------------------
119 # Return the smallest int type able to handle numbers ranging from
120 # `NAME_min' to `NAME_max' (included).
121 m4_define([b4_int_type_for],
122 [b4_int_type($1_min, $1_max)])
125 ## ------------------ ##
126 ## Decoding options. ##
127 ## ------------------ ##
130 # b4_location_if(IF-TRUE, IF-FALSE)
131 # ---------------------------------
132 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
133 m4_define([b4_location_if],
134 [m4_if(b4_locations_flag, [1],
139 # b4_pure_if(IF-TRUE, IF-FALSE)
140 # -----------------------------
141 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
142 m4_define([b4_pure_if],
149 ## ------------------------- ##
150 ## Assigning token numbers. ##
151 ## ------------------------- ##
153 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
154 # -----------------------------------------
155 # Output the definition of this token as #define.
156 m4_define([b4_token_define],
161 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
162 # ---------------------------------------
163 # Output the definition of this token as an enum.
164 m4_define([b4_token_enum],
168 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
169 # -------------------------------------------------------
170 # Output the definition of the tokens (if there are) as enums and #define.
171 m4_define([b4_token_defines],
172 [m4_if([$@], [[]], [],
176 /* Put the tokens into the symbol table, so that GDB and other debuggers
179 m4_map_sep([ b4_token_enum], [,
184 m4_map([b4_token_define], [$@])
190 ## --------------------------------------------- ##
191 ## Defining C functions in both K&R and ANSI-C. ##
192 ## --------------------------------------------- ##
195 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
196 # ----------------------------------------------------------
197 # Declare the function NAME.
198 m4_define([b4_c_function_def],
199 [#if defined (__STDC__) || defined (__cplusplus)
200 b4_c_ansi_function_def($@)
203 $1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
204 b4_c_knr_formal_decls(m4_shiftn(2, $@))
209 # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
210 # ---------------------------------------------------------------
211 # Declare the function NAME in ANSI.
212 m4_define([b4_c_ansi_function_def],
214 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
218 # b4_c_ansi_formals([DECL1, NAME1], ...)
219 # --------------------------------------
220 # Output the arguments ANSI-C definition.
221 m4_define([b4_c_ansi_formals],
225 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
227 m4_define([b4_c_ansi_formal],
231 # b4_c_knr_formal_names([DECL1, NAME1], ...)
232 # ------------------------------------------
233 # Output the argument names.
234 m4_define([b4_c_knr_formal_names],
235 [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
237 m4_define([b4_c_knr_formal_name],
241 # b4_c_knr_formal_decls([DECL1, NAME1], ...)
242 # ------------------------------------------
243 # Output the K&R argument declarations.
244 m4_define([b4_c_knr_formal_decls],
245 [m4_map_sep([b4_c_knr_formal_decl],
250 m4_define([b4_c_knr_formal_decl],
255 ## ------------------------------------------------------------ ##
256 ## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
257 ## ------------------------------------------------------------ ##
260 # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
261 # -----------------------------------------------------------
262 # Declare the function NAME.
263 m4_define([b4_c_function_decl],
264 [#if defined (__STDC__) || defined (__cplusplus)
265 b4_c_ansi_function_decl($@)
272 # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
273 # ----------------------------------------------------------------
274 # Declare the function NAME.
275 m4_define([b4_c_ansi_function_decl],
276 [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
282 ## --------------------- ##
283 ## Calling C functions. ##
284 ## --------------------- ##
287 # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
288 # -----------------------------------------------------------
289 # Call the function NAME with arguments NAME1, NAME2 etc.
290 m4_define([b4_c_function_call],
291 [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
295 # b4_c_args([DECL1, NAME1], ...)
296 # ------------------------------
297 # Output the arguments NAME1, NAME2...
298 m4_define([b4_c_args],
299 [m4_map_sep([b4_c_arg], [, ], [$@])])
301 m4_define([b4_c_arg],
310 # b4_syncline(LINE, FILE)
311 # -----------------------
312 m4_define([b4_syncline],
313 [m4_if(b4_synclines_flag, 1,