1 m4_divert(-1) -*- Autoconf -*-
3 # C M4 Macros for Bison.
4 # Copyright (C) 2002, 2004, 2005 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., 51 Franklin Street, Fifth Floor, 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., 51 Franklin Street, Fifth Floor,
47 Boston, MA 02110-1301, USA. */])
52 m4_define([b4_identification],
53 [/* Identify Bison output. */
57 [#]define YYBISON_VERSION "b4_version"
60 [#]define YYSKELETON_NAME b4_skeleton
63 [#]define YYPURE b4_pure
65 /* Using locations. */
66 [#]define YYLSP_NEEDED b4_locations_flag
71 ## ---------------- ##
73 ## ---------------- ##
75 m4_define_default([b4_epilogue], [])
79 ## ------------------------ ##
80 ## Pure/impure interfaces. ##
81 ## ------------------------ ##
86 m4_define([b4_user_args],
87 [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])])
92 # If defined, b4_parse_param arrives double quoted, but below we prefer
93 # it to be single quoted.
94 m4_define_default([b4_parse_param])
95 m4_define([b4_parse_param],
104 # b4_ints_in(INT1, INT2, LOW, HIGH)
105 # ---------------------------------
106 # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
107 m4_define([b4_ints_in],
108 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
111 # b4_int_type(MIN, MAX)
112 # ---------------------
113 # Return the smallest int type able to handle numbers ranging from
114 # MIN to MAX (included).
115 m4_define([b4_int_type],
116 [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
117 b4_ints_in($@, [-128], [127]), [1], [signed char],
119 b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
120 b4_ints_in($@, [-32768], [32767]), [1], [short int],
122 m4_eval([0 <= $1]), [1], [unsigned int],
127 # b4_int_type_for(NAME)
128 # ---------------------
129 # Return the smallest int type able to handle numbers ranging from
130 # `NAME_min' to `NAME_max' (included).
131 m4_define([b4_int_type_for],
132 [b4_int_type($1_min, $1_max)])
135 ## ------------------ ##
136 ## Decoding options. ##
137 ## ------------------ ##
140 # b4_error_verbose_if(IF-TRUE, IF-FALSE)
141 # --------------------------------------
142 # Expand IF-TRUE, if errors are verbose, IF-FALSE otherwise.
143 m4_define([b4_error_verbose_if],
144 [m4_if(b4_error_verbose, [1],
149 # b4_location_if(IF-TRUE, IF-FALSE)
150 # ---------------------------------
151 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
152 m4_define([b4_location_if],
153 [m4_if(b4_locations_flag, [1],
158 # b4_pure_if(IF-TRUE, IF-FALSE)
159 # -----------------------------
160 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
161 m4_define([b4_pure_if],
168 ## ------------------------- ##
169 ## Assigning token numbers. ##
170 ## ------------------------- ##
172 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
173 # -----------------------------------------
174 # Output the definition of this token as #define.
175 m4_define([b4_token_define],
180 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
181 # -------------------------------------------------------
182 # Output the definition of the tokens (if there are) as #defines.
183 m4_define([b4_token_defines],
184 [m4_if([$@], [[]], [],
186 m4_map([b4_token_define], [$@])])
190 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
191 # ---------------------------------------
192 # Output the definition of this token as an enum.
193 m4_define([b4_token_enum],
197 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
198 # -----------------------------------------------------
199 # Output the definition of the tokens (if there are) as enums.
200 m4_define([b4_token_enums],
201 [m4_if([$@], [[]], [],
205 /* Put the tokens into the symbol table, so that GDB and other debuggers
208 m4_map_sep([ b4_token_enum], [,
216 # b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
217 # -------------------------------------------------------------
218 # Output the definition of the tokens (if there are) as enums and #defines.
219 m4_define([b4_token_enums_defines],
220 [b4_token_enums($@)b4_token_defines($@)
225 ## --------------------------------------------- ##
226 ## Defining C functions in both K&R and ANSI-C. ##
227 ## --------------------------------------------- ##
230 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
231 # ----------------------------------------------------------
232 # Declare the function NAME.
233 m4_define([b4_c_function_def],
234 [#if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus)
235 b4_c_ansi_function_def($@)
238 $1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
239 b4_c_knr_formal_decls(m4_shiftn(2, $@))
244 # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
245 # ---------------------------------------------------------------
246 # Declare the function NAME in ANSI.
247 m4_define([b4_c_ansi_function_def],
249 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
253 # b4_c_ansi_formals([DECL1, NAME1], ...)
254 # --------------------------------------
255 # Output the arguments ANSI-C definition.
256 m4_define([b4_c_ansi_formals],
260 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
262 m4_define([b4_c_ansi_formal],
266 # b4_c_knr_formal_names([DECL1, NAME1], ...)
267 # ------------------------------------------
268 # Output the argument names.
269 m4_define([b4_c_knr_formal_names],
270 [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
272 m4_define([b4_c_knr_formal_name],
276 # b4_c_knr_formal_decls([DECL1, NAME1], ...)
277 # ------------------------------------------
278 # Output the K&R argument declarations.
279 m4_define([b4_c_knr_formal_decls],
280 [m4_map_sep([b4_c_knr_formal_decl],
285 m4_define([b4_c_knr_formal_decl],
290 ## ------------------------------------------------------------ ##
291 ## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
292 ## ------------------------------------------------------------ ##
295 # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
296 # -----------------------------------------------------------
297 # Declare the function NAME.
298 m4_define([b4_c_function_decl],
299 [#if defined (__STDC__) || defined (__cplusplus)
300 b4_c_ansi_function_decl($@)
307 # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
308 # ----------------------------------------------------------------
309 # Declare the function NAME.
310 m4_define([b4_c_ansi_function_decl],
311 [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
317 ## --------------------- ##
318 ## Calling C functions. ##
319 ## --------------------- ##
322 # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
323 # -----------------------------------------------------------
324 # Call the function NAME with arguments NAME1, NAME2 etc.
325 m4_define([b4_c_function_call],
326 [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
330 # b4_c_args([DECL1, NAME1], ...)
331 # ------------------------------
332 # Output the arguments NAME1, NAME2...
333 m4_define([b4_c_args],
334 [m4_map_sep([b4_c_arg], [, ], [$@])])
336 m4_define([b4_c_arg],
344 # b4_syncline(LINE, FILE)
345 # -----------------------
346 m4_define([b4_syncline],
347 [m4_if(b4_synclines_flag, 1,
351 # b4_symbol_actions(FILENAME, LINENO,
352 # SYMBOL-TAG, SYMBOL-NUM,
353 # SYMBOL-ACTION, SYMBOL-TYPENAME)
354 # -------------------------------------------------
355 m4_define([b4_symbol_actions],
356 [m4_pushdef([b4_dollar_dollar],
357 [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl
358 m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
360 b4_syncline([$2], [$1])
362 b4_syncline([@oline@], [@ofile@])
364 m4_popdef([b4_at_dollar])dnl
365 m4_popdef([b4_dollar_dollar])dnl
369 # b4_yydestruct_generate(FUNCTION-DECLARATOR)
370 # -------------------------------------------
371 # Generate the "yydestruct" function, which declaration is issued using
372 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
373 # or "b4_c_function_def" for K&R.
374 m4_define_default([b4_yydestruct_generate],
375 [[/*-----------------------------------------------.
376 | Release the memory associated to this symbol. |
377 `-----------------------------------------------*/
381 [[const char *yymsg], [yymsg]],
382 [[int yytype], [yytype]],
383 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
384 b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
385 m4_ifset([b4_parse_param], [, b4_parse_param]))[
388 ]b4_location_if([ YYUSE (yylocationp);
392 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
396 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
404 # b4_yysymprint_generate(FUNCTION-DECLARATOR)
405 # -------------------------------------------
406 # Generate the "yysymprint" function, which declaration is issued using
407 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
408 # or "b4_c_function_def" for K&R.
409 m4_define_default([b4_yysymprint_generate],
410 [[/*--------------------------------.
411 | Print this symbol on YYOUTPUT. |
412 `--------------------------------*/
416 [[FILE *yyoutput], [yyoutput]],
417 [[int yytype], [yytype]],
418 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
419 b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
420 m4_ifset([b4_parse_param], [, b4_parse_param]))[
423 ]b4_location_if([ YYUSE (yylocationp);
426 if (yytype < YYNTOKENS)
427 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
429 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
431 ]b4_location_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
432 YYFPRINTF (yyoutput, ": ");
436 if (yytype < YYNTOKENS)
437 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
441 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
445 YYFPRINTF (yyoutput, ")");