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