]> git.saurik.com Git - bison.git/blame - data/c.m4
* data/glr.c (yyexpandGLRStack): Declare only if defined.
[bison.git] / data / c.m4
CommitLineData
55b929ca 1m4_divert(-1) -*- Autoconf -*-
fb8135fa
AD
2
3# C M4 Macros for Bison.
9662b512 4# Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
fb8135fa
AD
5
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.
10
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.
15
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
0fb669f9
PE
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19# 02110-1301 USA
fb8135fa
AD
20
21
2a8d363a
AD
22## ---------------- ##
23## Identification. ##
24## ---------------- ##
fb8135fa
AD
25
26# b4_copyright(TITLE, YEARS)
27# --------------------------
28m4_define([b4_copyright],
fa3f2a88 29[/* A Bison parser, made by GNU Bison b4_version. */
fb8135fa
AD
30
31/* $1,
c76e14da 32 Copyright (C) $2 Free Software Foundation, Inc.
fb8135fa
AD
33
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)
37 any later version.
38
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.
43
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
0fb669f9
PE
46 Foundation, Inc., 51 Franklin Street, Fifth Floor,
47 Boston, MA 02110-1301, USA. */])
fb8135fa
AD
48
49
2a8d363a
AD
50# b4_identification
51# -----------------
52m4_define([b4_identification],
53[/* Identify Bison output. */
54[#]define YYBISON 1
55
55f64b82
PE
56/* Bison version. */
57[#]define YYBISON_VERSION "b4_version"
58
2a8d363a 59/* Skeleton name. */
fa3f2a88 60[#]define YYSKELETON_NAME b4_skeleton
2a8d363a
AD
61
62/* Pure parsers. */
63[#]define YYPURE b4_pure
64
65/* Using locations. */
66[#]define YYLSP_NEEDED b4_locations_flag
67])
68
69
70
7ec2d4cd
AD
71## ---------------- ##
72## Default values. ##
73## ---------------- ##
74
75m4_define_default([b4_epilogue], [])
76
77
78
2a8d363a
AD
79## ------------------------ ##
80## Pure/impure interfaces. ##
81## ------------------------ ##
82
83
84# b4_user_args
85# ------------
86m4_define([b4_user_args],
87[m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])])
88
89
90# b4_parse_param
91# --------------
92# If defined, b4_parse_param arrives double quoted, but below we prefer
93# it to be single quoted.
94m4_define_default([b4_parse_param])
95m4_define([b4_parse_param],
96b4_parse_param))
97
98
fb8135fa
AD
99## ------------ ##
100## Data Types. ##
101## ------------ ##
102
fb8135fa 103
a762e609
AD
104# b4_ints_in(INT1, INT2, LOW, HIGH)
105# ---------------------------------
106# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
107m4_define([b4_ints_in],
108[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
109
110
111# b4_int_type(MIN, MAX)
112# ---------------------
113# Return the smallest int type able to handle numbers ranging from
114# MIN to MAX (included).
115m4_define([b4_int_type],
116[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
f1886bb2 117 b4_ints_in($@, [-128], [127]), [1], [signed char],
a762e609 118
779e7ceb
PE
119 b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
120 b4_ints_in($@, [-32768], [32767]), [1], [short int],
a762e609
AD
121
122 m4_eval([0 <= $1]), [1], [unsigned int],
123
04098407 124 [int])])
a762e609 125
f1886bb2 126
a762e609
AD
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).
131m4_define([b4_int_type_for],
132[b4_int_type($1_min, $1_max)])
fb8135fa
AD
133
134
0245f82d
AD
135## ------------------ ##
136## Decoding options. ##
137## ------------------ ##
138
139
d4fb5e3c
AD
140# b4_error_verbose_if(IF-TRUE, IF-FALSE)
141# --------------------------------------
142# Expand IF-TRUE, if errors are verbose, IF-FALSE otherwise.
143m4_define([b4_error_verbose_if],
144[m4_if(b4_error_verbose, [1],
145 [$1],
146 [$2])])
147
148
0245f82d
AD
149# b4_location_if(IF-TRUE, IF-FALSE)
150# ---------------------------------
151# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
152m4_define([b4_location_if],
153[m4_if(b4_locations_flag, [1],
154 [$1],
155 [$2])])
156
157
158# b4_pure_if(IF-TRUE, IF-FALSE)
159# -----------------------------
160# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
161m4_define([b4_pure_if],
162[m4_if(b4_pure, [1],
163 [$1],
164 [$2])])
165
166
167
fb8135fa
AD
168## ------------------------- ##
169## Assigning token numbers. ##
170## ------------------------- ##
171
172# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
173# -----------------------------------------
174# Output the definition of this token as #define.
175m4_define([b4_token_define],
176[#define $1 $2
177])
178
179
cf147260
AD
180# b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
181# -------------------------------------------------------
182# Output the definition of the tokens (if there are) as #defines.
183m4_define([b4_token_defines],
184[m4_if([$@], [[]], [],
185[/* Tokens. */
186m4_map([b4_token_define], [$@])])
187])
188
189
fb8135fa
AD
190# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
191# ---------------------------------------
192# Output the definition of this token as an enum.
193m4_define([b4_token_enum],
194[$1 = $2])
195
196
cf147260
AD
197# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
198# -----------------------------------------------------
199# Output the definition of the tokens (if there are) as enums.
200m4_define([b4_token_enums],
fb8135fa
AD
201[m4_if([$@], [[]], [],
202[/* Tokens. */
6b8c3254
PE
203#ifndef YYTOKENTYPE
204# define YYTOKENTYPE
fb8135fa
AD
205 /* Put the tokens into the symbol table, so that GDB and other debuggers
206 know about them. */
207 enum yytokentype {
208m4_map_sep([ b4_token_enum], [,
209],
210 [$@])
211 };
095b9f05 212#endif
cf147260
AD
213])])
214
215
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.
219m4_define([b4_token_enums_defines],
220[b4_token_enums($@)b4_token_defines($@)
fb8135fa 221])
4a2a22f4
AD
222
223
ae7453f2 224
0245f82d
AD
225## --------------------------------------------- ##
226## Defining C functions in both K&R and ANSI-C. ##
227## --------------------------------------------- ##
4a2a22f4
AD
228
229
0245f82d
AD
230# b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
231# ----------------------------------------------------------
4a2a22f4 232# Declare the function NAME.
0245f82d 233m4_define([b4_c_function_def],
ba0fe3c7 234[#if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus)
0245f82d 235b4_c_ansi_function_def($@)
4a2a22f4 236#else
0245f82d
AD
237$2
238$1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
239b4_c_knr_formal_decls(m4_shiftn(2, $@))
4a2a22f4
AD
240#endif[]dnl
241])
242
243
0245f82d
AD
244# b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
245# ---------------------------------------------------------------
246# Declare the function NAME in ANSI.
247m4_define([b4_c_ansi_function_def],
248[$2
249$1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
250])
251
252
253# b4_c_ansi_formals([DECL1, NAME1], ...)
254# --------------------------------------
4a2a22f4 255# Output the arguments ANSI-C definition.
0245f82d
AD
256m4_define([b4_c_ansi_formals],
257[m4_case([$@],
258 [], [void],
259 [[]], [void],
260 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
4a2a22f4 261
0245f82d
AD
262m4_define([b4_c_ansi_formal],
263[$1])
4a2a22f4
AD
264
265
0245f82d
AD
266# b4_c_knr_formal_names([DECL1, NAME1], ...)
267# ------------------------------------------
4a2a22f4 268# Output the argument names.
0245f82d
AD
269m4_define([b4_c_knr_formal_names],
270[m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
4a2a22f4 271
0245f82d 272m4_define([b4_c_knr_formal_name],
4a2a22f4
AD
273[$2])
274
275
0245f82d
AD
276# b4_c_knr_formal_decls([DECL1, NAME1], ...)
277# ------------------------------------------
4a2a22f4 278# Output the K&R argument declarations.
0245f82d
AD
279m4_define([b4_c_knr_formal_decls],
280[m4_map_sep([b4_c_knr_formal_decl],
4a2a22f4
AD
281 [
282],
283 [$@])])
284
0245f82d
AD
285m4_define([b4_c_knr_formal_decl],
286[ $1;])
21964f43
AD
287
288
289
0245f82d
AD
290## ------------------------------------------------------------ ##
291## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
292## ------------------------------------------------------------ ##
21964f43
AD
293
294
0245f82d
AD
295# b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
296# -----------------------------------------------------------
297# Declare the function NAME.
298m4_define([b4_c_function_decl],
299[#if defined (__STDC__) || defined (__cplusplus)
300b4_c_ansi_function_decl($@)
301#else
302$2 $1 ();
303#endif[]dnl
304])
21964f43
AD
305
306
0245f82d
AD
307# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
308# ----------------------------------------------------------------
309# Declare the function NAME.
310m4_define([b4_c_ansi_function_decl],
311[$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
312])
313
314
315
316
317## --------------------- ##
318## Calling C functions. ##
319## --------------------- ##
320
321
322# b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
323# -----------------------------------------------------------
324# Call the function NAME with arguments NAME1, NAME2 etc.
325m4_define([b4_c_function_call],
326[$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
327])
328
329
330# b4_c_args([DECL1, NAME1], ...)
331# ------------------------------
332# Output the arguments NAME1, NAME2...
333m4_define([b4_c_args],
334[m4_map_sep([b4_c_arg], [, ], [$@])])
335
336m4_define([b4_c_arg],
337[$2])
437c2d80
AD
338
339
340## ----------- ##
341## Synclines. ##
342## ----------- ##
343
437c2d80
AD
344# b4_syncline(LINE, FILE)
345# -----------------------
346m4_define([b4_syncline],
347[m4_if(b4_synclines_flag, 1,
fa3f2a88 348 [[#]line $1 $2])])
b0400cc6
AD
349
350
351# b4_symbol_actions(FILENAME, LINENO,
352# SYMBOL-TAG, SYMBOL-NUM,
353# SYMBOL-ACTION, SYMBOL-TYPENAME)
354# -------------------------------------------------
355m4_define([b4_symbol_actions],
60c82948
PE
356[m4_pushdef([b4_dollar_dollar],
357 [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl
7bd6c77e 358m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
b0400cc6
AD
359 case $4: /* $3 */
360b4_syncline([$2], [$1])
361 $5;
362b4_syncline([@oline@], [@ofile@])
363 break;
364m4_popdef([b4_at_dollar])dnl
365m4_popdef([b4_dollar_dollar])dnl
366])
367
368
14740648
PE
369# b4_yydestruct_generate(FUNCTION-DECLARATOR)
370# -------------------------------------------
b0400cc6 371# Generate the "yydestruct" function, which declaration is issued using
14740648 372# FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
b0400cc6 373# or "b4_c_function_def" for K&R.
cf147260 374m4_define_default([b4_yydestruct_generate],
b0400cc6
AD
375[[/*-----------------------------------------------.
376| Release the memory associated to this symbol. |
377`-----------------------------------------------*/
378
379]$1([yydestruct],
380 [static void],
a0e68930 381 [[const char *yymsg], [yymsg]],
7bd6c77e 382 [[int yytype], [yytype]],
4b367315
AD
383 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
384b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
385m4_ifset([b4_parse_param], [, b4_parse_param]))[
b0400cc6 386{
2a4647a3
PE
387 YYUSE (yyvaluep);
388]b4_location_if([ YYUSE (yylocationp);
b0400cc6 389])[
a0e68930
AD
390 if (!yymsg)
391 yymsg = "Deleting";
392 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
393
b0400cc6
AD
394 switch (yytype)
395 {
396]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
397 default:
398 break;
399 }
400}]dnl
401])
7bd6c77e
AD
402
403
14740648
PE
404# b4_yysymprint_generate(FUNCTION-DECLARATOR)
405# -------------------------------------------
7bd6c77e 406# Generate the "yysymprint" function, which declaration is issued using
14740648 407# FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
7bd6c77e 408# or "b4_c_function_def" for K&R.
cf147260 409m4_define_default([b4_yysymprint_generate],
14740648
PE
410[[/*--------------------------------.
411| Print this symbol on YYOUTPUT. |
412`--------------------------------*/
7bd6c77e
AD
413
414]$1([yysymprint],
415 [static void],
62b08cfc
AD
416 [[FILE *yyoutput], [yyoutput]],
417 [[int yytype], [yytype]],
418 [[const YYSTYPE * const yyvaluep], [yyvaluep]][]dnl
419b4_location_if([, [[const YYLTYPE * const yylocationp], [yylocationp]]])[]dnl
4b367315 420m4_ifset([b4_parse_param], [, b4_parse_param]))[
7bd6c77e 421{
2a4647a3 422 YYUSE (yyvaluep);
4b367315 423]b4_location_if([ YYUSE (yylocationp);
7bd6c77e 424])dnl
3fc16193 425[
7bd6c77e 426 if (yytype < YYNTOKENS)
619404e3 427 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
7bd6c77e 428 else
3fc16193 429 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
7bd6c77e 430
3fc16193 431]b4_location_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
2f4f028d 432 YYFPRINTF (yyoutput, ": ");
3fc16193
AD
433])dnl
434[
619404e3
AD
435# ifdef YYPRINT
436 if (yytype < YYNTOKENS)
437 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
438# endif
7bd6c77e
AD
439 switch (yytype)
440 {
3fc16193
AD
441]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
442[ default:
7bd6c77e
AD
443 break;
444 }
2f4f028d 445 YYFPRINTF (yyoutput, ")");
4b367315
AD
446}]dnl
447])