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 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 ## ---------------- ##
70 ## ---------------- ##
72 m4_define_default([b4_epilogue], [])
76 ## ------------------------ ##
77 ## Pure/impure interfaces. ##
78 ## ------------------------ ##
83 m4_define([b4_user_args],
84 [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])])
89 # If defined, b4_parse_param arrives double quoted, but below we prefer
90 # it to be single quoted.
91 m4_define_default([b4_parse_param])
92 m4_define([b4_parse_param],
102 # b4_ints_in(INT1, INT2, LOW, HIGH)
103 # ---------------------------------
104 # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
105 m4_define([b4_ints_in],
106 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
109 # b4_int_type(MIN, MAX)
110 # ---------------------
111 # Return the smallest int type able to handle numbers ranging from
112 # MIN to MAX (included).
113 m4_define([b4_int_type],
114 [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
115 b4_ints_in($@, [-128], [127]), [1], [signed char],
117 b4_ints_in($@, [0], [65535]), [1], [unsigned short],
118 b4_ints_in($@, [-32768], [32767]), [1], [short],
120 m4_eval([0 <= $1]), [1], [unsigned int],
125 # b4_int_type_for(NAME)
126 # ---------------------
127 # Return the smallest int type able to handle numbers ranging from
128 # `NAME_min' to `NAME_max' (included).
129 m4_define([b4_int_type_for],
130 [b4_int_type($1_min, $1_max)])
133 ## ------------------ ##
134 ## Decoding options. ##
135 ## ------------------ ##
138 # b4_location_if(IF-TRUE, IF-FALSE)
139 # ---------------------------------
140 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
141 m4_define([b4_location_if],
142 [m4_if(b4_locations_flag, [1],
147 # b4_pure_if(IF-TRUE, IF-FALSE)
148 # -----------------------------
149 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
150 m4_define([b4_pure_if],
157 ## ------------------------- ##
158 ## Assigning token numbers. ##
159 ## ------------------------- ##
161 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
162 # -----------------------------------------
163 # Output the definition of this token as #define.
164 m4_define([b4_token_define],
169 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
170 # ---------------------------------------
171 # Output the definition of this token as an enum.
172 m4_define([b4_token_enum],
176 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
177 # -------------------------------------------------------
178 # Output the definition of the tokens (if there are) as enums and #define.
179 m4_define([b4_token_defines],
180 [m4_if([$@], [[]], [],
184 /* Put the tokens into the symbol table, so that GDB and other debuggers
187 m4_map_sep([ b4_token_enum], [,
192 m4_map([b4_token_define], [$@])
198 ## --------------------------------------------- ##
199 ## Defining C functions in both K&R and ANSI-C. ##
200 ## --------------------------------------------- ##
203 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
204 # ----------------------------------------------------------
205 # Declare the function NAME.
206 m4_define([b4_c_function_def],
207 [#if defined (__STDC__) || defined (__cplusplus)
208 b4_c_ansi_function_def($@)
211 $1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
212 b4_c_knr_formal_decls(m4_shiftn(2, $@))
217 # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
218 # ---------------------------------------------------------------
219 # Declare the function NAME in ANSI.
220 m4_define([b4_c_ansi_function_def],
222 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
226 # b4_c_ansi_formals([DECL1, NAME1], ...)
227 # --------------------------------------
228 # Output the arguments ANSI-C definition.
229 m4_define([b4_c_ansi_formals],
233 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
235 m4_define([b4_c_ansi_formal],
239 # b4_c_knr_formal_names([DECL1, NAME1], ...)
240 # ------------------------------------------
241 # Output the argument names.
242 m4_define([b4_c_knr_formal_names],
243 [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
245 m4_define([b4_c_knr_formal_name],
249 # b4_c_knr_formal_decls([DECL1, NAME1], ...)
250 # ------------------------------------------
251 # Output the K&R argument declarations.
252 m4_define([b4_c_knr_formal_decls],
253 [m4_map_sep([b4_c_knr_formal_decl],
258 m4_define([b4_c_knr_formal_decl],
263 ## ------------------------------------------------------------ ##
264 ## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
265 ## ------------------------------------------------------------ ##
268 # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
269 # -----------------------------------------------------------
270 # Declare the function NAME.
271 m4_define([b4_c_function_decl],
272 [#if defined (__STDC__) || defined (__cplusplus)
273 b4_c_ansi_function_decl($@)
280 # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
281 # ----------------------------------------------------------------
282 # Declare the function NAME.
283 m4_define([b4_c_ansi_function_decl],
284 [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
290 ## --------------------- ##
291 ## Calling C functions. ##
292 ## --------------------- ##
295 # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
296 # -----------------------------------------------------------
297 # Call the function NAME with arguments NAME1, NAME2 etc.
298 m4_define([b4_c_function_call],
299 [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
303 # b4_c_args([DECL1, NAME1], ...)
304 # ------------------------------
305 # Output the arguments NAME1, NAME2...
306 m4_define([b4_c_args],
307 [m4_map_sep([b4_c_arg], [, ], [$@])])
309 m4_define([b4_c_arg],
318 # b4_syncline(LINE, FILE)
319 # -----------------------
320 m4_define([b4_syncline],
321 [m4_if(b4_synclines_flag, 1,
325 # b4_symbol_actions(FILENAME, LINENO,
326 # SYMBOL-TAG, SYMBOL-NUM,
327 # SYMBOL-ACTION, SYMBOL-TYPENAME)
328 # -------------------------------------------------
329 m4_define([b4_symbol_actions],
330 [m4_pushdef([b4_dollar_dollar], [yyvaluep->$6])dnl
331 m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
333 b4_syncline([$2], [$1])
335 b4_syncline([@oline@], [@ofile@])
337 m4_popdef([b4_at_dollar])dnl
338 m4_popdef([b4_dollar_dollar])dnl
342 # b4_yydestruct_generate(FUNCTION-DECLARATOR)
343 # -------------------------------------------
344 # Generate the "yydestruct" function, which declaration is issued using
345 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
346 # or "b4_c_function_def" for K&R.
347 m4_define([b4_yydestruct_generate],
348 [[/*-----------------------------------------------.
349 | Release the memory associated to this symbol. |
350 `-----------------------------------------------*/
354 [[int yytype], [yytype]],
355 [[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([,
356 [[YYLTYPE *yylocationp], [yylocationp]]]))[
358 /* Pacify ``unused variable'' warnings. */
360 ]b4_location_if([ (void) yylocationp;
364 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
372 # b4_yysymprint_generate(FUNCTION-DECLARATOR)
373 # -------------------------------------------
374 # Generate the "yysymprint" function, which declaration is issued using
375 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
376 # or "b4_c_function_def" for K&R.
377 m4_define([b4_yysymprint_generate],
378 [[/*--------------------------------.
379 | Print this symbol on YYOUTPUT. |
380 `--------------------------------*/
384 [[FILE *yyoutput], [yyoutput]],
385 [[int yytype], [yytype]],
386 [[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([,
387 [[YYLTYPE *yylocationp], [yylocationp]]]))
389 /* Pacify ``unused variable'' warnings. */
391 b4_location_if([ (void) yylocationp;
394 if (yytype < YYNTOKENS)
396 YYFPRINTF (yyoutput, "token %s (", yytname[[yytype]]);
398 YYPRINT (yyoutput, yytoknum[[yytype]], *yyvaluep);
402 YYFPRINTF (yyoutput, "nterm %s (", yytname[[yytype]]);
406 m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
410 YYFPRINTF (yyoutput, ")");