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