]>
Commit | Line | Data |
---|---|---|
55b929ca | 1 | m4_divert(-1) -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
e2a21b6f | 4 | # Copyright (C) 2002, 2004, 2005, 2006 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 | ||
8f7e3cf9 | 98 | |
613d8952 AD |
99 | # b4_parse_param_for(DECL, FORMAL, BODY) |
100 | # --------------------------------------- | |
101 | # Iterate over the user parameters, binding the declaration to DECL, | |
102 | # the formal name to FORMAL, and evaluating the BODY. | |
103 | m4_define([b4_parse_param_for], | |
104 | [m4_foreach([$1_$2], m4_defn([b4_parse_param]), | |
105 | [m4_pushdef([$1], m4_fst($1_$2))dnl | |
106 | m4_pushdef([$2], m4_shift($1_$2))dnl | |
107 | $3[]dnl | |
108 | m4_popdef([$2])dnl | |
109 | m4_popdef([$1])dnl | |
110 | ])]) | |
111 | ||
112 | # b4_parse_param_use | |
113 | # ------------------ | |
114 | # `YYUSE' all the parse-params. | |
613d8952 AD |
115 | m4_define([b4_parse_param_use], |
116 | [b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); | |
117 | ])dnl | |
118 | ]) | |
2a8d363a | 119 | |
fb8135fa AD |
120 | ## ------------ ## |
121 | ## Data Types. ## | |
122 | ## ------------ ## | |
123 | ||
fb8135fa | 124 | |
a762e609 AD |
125 | # b4_ints_in(INT1, INT2, LOW, HIGH) |
126 | # --------------------------------- | |
127 | # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. | |
128 | m4_define([b4_ints_in], | |
129 | [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) | |
130 | ||
131 | ||
132 | # b4_int_type(MIN, MAX) | |
133 | # --------------------- | |
134 | # Return the smallest int type able to handle numbers ranging from | |
135 | # MIN to MAX (included). | |
136 | m4_define([b4_int_type], | |
137 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 138 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 | 139 | |
779e7ceb PE |
140 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
141 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
142 | |
143 | m4_eval([0 <= $1]), [1], [unsigned int], | |
144 | ||
04098407 | 145 | [int])]) |
a762e609 | 146 | |
f1886bb2 | 147 | |
a762e609 AD |
148 | # b4_int_type_for(NAME) |
149 | # --------------------- | |
150 | # Return the smallest int type able to handle numbers ranging from | |
151 | # `NAME_min' to `NAME_max' (included). | |
152 | m4_define([b4_int_type_for], | |
153 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa AD |
154 | |
155 | ||
0245f82d AD |
156 | ## ------------------ ## |
157 | ## Decoding options. ## | |
158 | ## ------------------ ## | |
159 | ||
160 | ||
d4fb5e3c AD |
161 | # b4_error_verbose_if(IF-TRUE, IF-FALSE) |
162 | # -------------------------------------- | |
163 | # Expand IF-TRUE, if errors are verbose, IF-FALSE otherwise. | |
164 | m4_define([b4_error_verbose_if], | |
165 | [m4_if(b4_error_verbose, [1], | |
166 | [$1], | |
167 | [$2])]) | |
168 | ||
169 | ||
0245f82d AD |
170 | # b4_location_if(IF-TRUE, IF-FALSE) |
171 | # --------------------------------- | |
172 | # Expand IF-TRUE, if locations are used, IF-FALSE otherwise. | |
173 | m4_define([b4_location_if], | |
174 | [m4_if(b4_locations_flag, [1], | |
175 | [$1], | |
176 | [$2])]) | |
177 | ||
178 | ||
179 | # b4_pure_if(IF-TRUE, IF-FALSE) | |
180 | # ----------------------------- | |
181 | # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise. | |
182 | m4_define([b4_pure_if], | |
183 | [m4_if(b4_pure, [1], | |
184 | [$1], | |
185 | [$2])]) | |
186 | ||
187 | ||
188 | ||
fb8135fa AD |
189 | ## ------------------------- ## |
190 | ## Assigning token numbers. ## | |
191 | ## ------------------------- ## | |
192 | ||
193 | # b4_token_define(TOKEN-NAME, TOKEN-NUMBER) | |
194 | # ----------------------------------------- | |
195 | # Output the definition of this token as #define. | |
196 | m4_define([b4_token_define], | |
197 | [#define $1 $2 | |
198 | ]) | |
199 | ||
200 | ||
cf147260 AD |
201 | # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
202 | # ------------------------------------------------------- | |
203 | # Output the definition of the tokens (if there are) as #defines. | |
204 | m4_define([b4_token_defines], | |
205 | [m4_if([$@], [[]], [], | |
206 | [/* Tokens. */ | |
207 | m4_map([b4_token_define], [$@])]) | |
208 | ]) | |
209 | ||
210 | ||
fb8135fa AD |
211 | # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) |
212 | # --------------------------------------- | |
213 | # Output the definition of this token as an enum. | |
214 | m4_define([b4_token_enum], | |
215 | [$1 = $2]) | |
216 | ||
217 | ||
cf147260 AD |
218 | # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
219 | # ----------------------------------------------------- | |
220 | # Output the definition of the tokens (if there are) as enums. | |
221 | m4_define([b4_token_enums], | |
fb8135fa AD |
222 | [m4_if([$@], [[]], [], |
223 | [/* Tokens. */ | |
6b8c3254 PE |
224 | #ifndef YYTOKENTYPE |
225 | # define YYTOKENTYPE | |
fb8135fa AD |
226 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
227 | know about them. */ | |
228 | enum yytokentype { | |
229 | m4_map_sep([ b4_token_enum], [, | |
230 | ], | |
231 | [$@]) | |
232 | }; | |
095b9f05 | 233 | #endif |
cf147260 AD |
234 | ])]) |
235 | ||
236 | ||
237 | # b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) | |
238 | # ------------------------------------------------------------- | |
239 | # Output the definition of the tokens (if there are) as enums and #defines. | |
240 | m4_define([b4_token_enums_defines], | |
241 | [b4_token_enums($@)b4_token_defines($@) | |
fb8135fa | 242 | ]) |
4a2a22f4 AD |
243 | |
244 | ||
ae7453f2 | 245 | |
0245f82d AD |
246 | ## --------------------------------------------- ## |
247 | ## Defining C functions in both K&R and ANSI-C. ## | |
248 | ## --------------------------------------------- ## | |
4a2a22f4 AD |
249 | |
250 | ||
0245f82d AD |
251 | # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
252 | # ---------------------------------------------------------- | |
4a2a22f4 | 253 | # Declare the function NAME. |
0245f82d | 254 | m4_define([b4_c_function_def], |
ba0fe3c7 | 255 | [#if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus) |
0245f82d | 256 | b4_c_ansi_function_def($@) |
4a2a22f4 | 257 | #else |
0245f82d AD |
258 | $2 |
259 | $1 (b4_c_knr_formal_names(m4_shiftn(2, $@))) | |
260 | b4_c_knr_formal_decls(m4_shiftn(2, $@)) | |
4a2a22f4 AD |
261 | #endif[]dnl |
262 | ]) | |
263 | ||
264 | ||
0245f82d AD |
265 | # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
266 | # --------------------------------------------------------------- | |
267 | # Declare the function NAME in ANSI. | |
268 | m4_define([b4_c_ansi_function_def], | |
269 | [$2 | |
270 | $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl | |
271 | ]) | |
272 | ||
273 | ||
274 | # b4_c_ansi_formals([DECL1, NAME1], ...) | |
275 | # -------------------------------------- | |
4a2a22f4 | 276 | # Output the arguments ANSI-C definition. |
0245f82d AD |
277 | m4_define([b4_c_ansi_formals], |
278 | [m4_case([$@], | |
279 | [], [void], | |
280 | [[]], [void], | |
281 | [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) | |
4a2a22f4 | 282 | |
0245f82d AD |
283 | m4_define([b4_c_ansi_formal], |
284 | [$1]) | |
4a2a22f4 AD |
285 | |
286 | ||
0245f82d AD |
287 | # b4_c_knr_formal_names([DECL1, NAME1], ...) |
288 | # ------------------------------------------ | |
4a2a22f4 | 289 | # Output the argument names. |
0245f82d AD |
290 | m4_define([b4_c_knr_formal_names], |
291 | [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])]) | |
4a2a22f4 | 292 | |
0245f82d | 293 | m4_define([b4_c_knr_formal_name], |
4a2a22f4 AD |
294 | [$2]) |
295 | ||
296 | ||
0245f82d AD |
297 | # b4_c_knr_formal_decls([DECL1, NAME1], ...) |
298 | # ------------------------------------------ | |
4a2a22f4 | 299 | # Output the K&R argument declarations. |
0245f82d AD |
300 | m4_define([b4_c_knr_formal_decls], |
301 | [m4_map_sep([b4_c_knr_formal_decl], | |
4a2a22f4 AD |
302 | [ |
303 | ], | |
304 | [$@])]) | |
305 | ||
0245f82d AD |
306 | m4_define([b4_c_knr_formal_decl], |
307 | [ $1;]) | |
21964f43 AD |
308 | |
309 | ||
310 | ||
0245f82d AD |
311 | ## ------------------------------------------------------------ ## |
312 | ## Declaring (prototyping) C functions in both K&R and ANSI-C. ## | |
313 | ## ------------------------------------------------------------ ## | |
21964f43 AD |
314 | |
315 | ||
0245f82d AD |
316 | # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
317 | # ----------------------------------------------------------- | |
318 | # Declare the function NAME. | |
319 | m4_define([b4_c_function_decl], | |
320 | [#if defined (__STDC__) || defined (__cplusplus) | |
321 | b4_c_ansi_function_decl($@) | |
322 | #else | |
323 | $2 $1 (); | |
324 | #endif[]dnl | |
325 | ]) | |
21964f43 AD |
326 | |
327 | ||
0245f82d AD |
328 | # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
329 | # ---------------------------------------------------------------- | |
330 | # Declare the function NAME. | |
331 | m4_define([b4_c_ansi_function_decl], | |
332 | [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl | |
333 | ]) | |
334 | ||
335 | ||
336 | ||
337 | ||
338 | ## --------------------- ## | |
339 | ## Calling C functions. ## | |
340 | ## --------------------- ## | |
341 | ||
342 | ||
343 | # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) | |
344 | # ----------------------------------------------------------- | |
345 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
346 | m4_define([b4_c_function_call], | |
347 | [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl | |
348 | ]) | |
349 | ||
350 | ||
351 | # b4_c_args([DECL1, NAME1], ...) | |
352 | # ------------------------------ | |
353 | # Output the arguments NAME1, NAME2... | |
354 | m4_define([b4_c_args], | |
355 | [m4_map_sep([b4_c_arg], [, ], [$@])]) | |
356 | ||
357 | m4_define([b4_c_arg], | |
358 | [$2]) | |
437c2d80 AD |
359 | |
360 | ||
361 | ## ----------- ## | |
362 | ## Synclines. ## | |
363 | ## ----------- ## | |
364 | ||
437c2d80 AD |
365 | # b4_syncline(LINE, FILE) |
366 | # ----------------------- | |
367 | m4_define([b4_syncline], | |
368 | [m4_if(b4_synclines_flag, 1, | |
fa3f2a88 | 369 | [[#]line $1 $2])]) |
b0400cc6 AD |
370 | |
371 | ||
613d8952 AD |
372 | |
373 | ## -------------- ## | |
374 | ## User actions. ## | |
375 | ## -------------- ## | |
376 | ||
b0400cc6 AD |
377 | # b4_symbol_actions(FILENAME, LINENO, |
378 | # SYMBOL-TAG, SYMBOL-NUM, | |
379 | # SYMBOL-ACTION, SYMBOL-TYPENAME) | |
380 | # ------------------------------------------------- | |
381 | m4_define([b4_symbol_actions], | |
60c82948 PE |
382 | [m4_pushdef([b4_dollar_dollar], |
383 | [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl | |
7bd6c77e | 384 | m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl |
b0400cc6 AD |
385 | case $4: /* $3 */ |
386 | b4_syncline([$2], [$1]) | |
387 | $5; | |
388 | b4_syncline([@oline@], [@ofile@]) | |
389 | break; | |
390 | m4_popdef([b4_at_dollar])dnl | |
391 | m4_popdef([b4_dollar_dollar])dnl | |
392 | ]) | |
393 | ||
394 | ||
14740648 PE |
395 | # b4_yydestruct_generate(FUNCTION-DECLARATOR) |
396 | # ------------------------------------------- | |
b0400cc6 | 397 | # Generate the "yydestruct" function, which declaration is issued using |
14740648 | 398 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
b0400cc6 | 399 | # or "b4_c_function_def" for K&R. |
cf147260 | 400 | m4_define_default([b4_yydestruct_generate], |
b0400cc6 AD |
401 | [[/*-----------------------------------------------. |
402 | | Release the memory associated to this symbol. | | |
403 | `-----------------------------------------------*/ | |
404 | ||
12ce2df6 | 405 | /*ARGSUSED*/ |
b0400cc6 AD |
406 | ]$1([yydestruct], |
407 | [static void], | |
a0e68930 | 408 | [[const char *yymsg], [yymsg]], |
7bd6c77e | 409 | [[int yytype], [yytype]], |
4b367315 AD |
410 | [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl |
411 | b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl | |
412 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ | |
b0400cc6 | 413 | { |
2a4647a3 PE |
414 | YYUSE (yyvaluep); |
415 | ]b4_location_if([ YYUSE (yylocationp); | |
613d8952 AD |
416 | ])dnl |
417 | b4_parse_param_use[]dnl | |
418 | [ | |
a0e68930 AD |
419 | if (!yymsg) |
420 | yymsg = "Deleting"; | |
421 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
422 | ||
b0400cc6 AD |
423 | switch (yytype) |
424 | { | |
425 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
426 | default: | |
427 | break; | |
428 | } | |
429 | }]dnl | |
430 | ]) | |
7bd6c77e AD |
431 | |
432 | ||
a0af42fc AD |
433 | # b4_yy_symbol_print_generate(FUNCTION-DECLARATOR) |
434 | # ------------------------------------------------ | |
435 | # Generate the "yy_symbol_print" function, which declaration is issued using | |
14740648 | 436 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
7bd6c77e | 437 | # or "b4_c_function_def" for K&R. |
a0af42fc AD |
438 | m4_define_default([b4_yy_symbol_print_generate], |
439 | [[ | |
440 | /*--------------------------------. | |
14740648 PE |
441 | | Print this symbol on YYOUTPUT. | |
442 | `--------------------------------*/ | |
7bd6c77e | 443 | |
12ce2df6 | 444 | /*ARGSUSED*/ |
a0af42fc | 445 | ]$1([yy_symbol_value_print], |
7bd6c77e | 446 | [static void], |
62b08cfc AD |
447 | [[FILE *yyoutput], [yyoutput]], |
448 | [[int yytype], [yytype]], | |
449 | [[const YYSTYPE * const yyvaluep], [yyvaluep]][]dnl | |
450 | b4_location_if([, [[const YYLTYPE * const yylocationp], [yylocationp]]])[]dnl | |
4b367315 | 451 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
7bd6c77e | 452 | { |
2a4647a3 | 453 | YYUSE (yyvaluep); |
4b367315 | 454 | ]b4_location_if([ YYUSE (yylocationp); |
7bd6c77e | 455 | ])dnl |
613d8952 | 456 | b4_parse_param_use[]dnl |
a0af42fc | 457 | [# ifdef YYPRINT |
619404e3 AD |
458 | if (yytype < YYNTOKENS) |
459 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
460 | # endif | |
7bd6c77e AD |
461 | switch (yytype) |
462 | { | |
3fc16193 AD |
463 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl |
464 | [ default: | |
7bd6c77e AD |
465 | break; |
466 | } | |
a0af42fc AD |
467 | } |
468 | ||
469 | ||
470 | /*--------------------------------. | |
471 | | Print this symbol on YYOUTPUT. | | |
472 | `--------------------------------*/ | |
473 | ||
474 | ]$1([yy_symbol_print], | |
475 | [static void], | |
476 | [[FILE *yyoutput], [yyoutput]], | |
477 | [[int yytype], [yytype]], | |
478 | [[const YYSTYPE * const yyvaluep], [yyvaluep]][]dnl | |
479 | b4_location_if([, [[const YYLTYPE * const yylocationp], [yylocationp]]])[]dnl | |
480 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ | |
481 | { | |
482 | if (yytype < YYNTOKENS) | |
483 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
484 | else | |
485 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
486 | ||
487 | ]b4_location_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); | |
488 | YYFPRINTF (yyoutput, ": "); | |
489 | ])dnl | |
490 | [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl | |
491 | b4_location_if([, yylocationp])[]b4_user_args[); | |
2f4f028d | 492 | YYFPRINTF (yyoutput, ")"); |
4b367315 AD |
493 | }]dnl |
494 | ]) |