]>
Commit | Line | Data |
---|---|---|
55b929ca | 1 | m4_divert(-1) -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
779e7ceb | 4 | # Copyright (C) 2002, 2004 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 | |
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 | # -------------------------- | |
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 | |
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 | # ----------------- | |
52 | m4_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 | ||
72 | m4_define_default([b4_epilogue], []) | |
73 | ||
74 | ||
75 | ||
2a8d363a AD |
76 | ## ------------------------ ## |
77 | ## Pure/impure interfaces. ## | |
78 | ## ------------------------ ## | |
79 | ||
80 | ||
81 | # b4_user_args | |
82 | # ------------ | |
83 | m4_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. | |
91 | m4_define_default([b4_parse_param]) | |
92 | m4_define([b4_parse_param], | |
93 | b4_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. | |
105 | m4_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). | |
113 | m4_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 | 116 | |
779e7ceb PE |
117 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
118 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
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). | |
129 | m4_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. | |
141 | m4_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. | |
150 | m4_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. | |
164 | m4_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. | |
172 | m4_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. | |
179 | m4_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 { | |
187 | m4_map_sep([ b4_token_enum], [, | |
188 | ], | |
189 | [$@]) | |
190 | }; | |
095b9f05 | 191 | #endif |
fb8135fa AD |
192 | m4_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 |
206 | m4_define([b4_c_function_def], |
207 | [#if defined (__STDC__) || defined (__cplusplus) | |
208 | b4_c_ansi_function_def($@) | |
4a2a22f4 | 209 | #else |
0245f82d AD |
210 | $2 |
211 | $1 (b4_c_knr_formal_names(m4_shiftn(2, $@))) | |
212 | b4_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. | |
220 | m4_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 |
229 | m4_define([b4_c_ansi_formals], |
230 | [m4_case([$@], | |
231 | [], [void], | |
232 | [[]], [void], | |
233 | [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) | |
4a2a22f4 | 234 | |
0245f82d AD |
235 | m4_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 |
242 | m4_define([b4_c_knr_formal_names], |
243 | [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])]) | |
4a2a22f4 | 244 | |
0245f82d | 245 | m4_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 |
252 | m4_define([b4_c_knr_formal_decls], |
253 | [m4_map_sep([b4_c_knr_formal_decl], | |
4a2a22f4 AD |
254 | [ |
255 | ], | |
256 | [$@])]) | |
257 | ||
0245f82d AD |
258 | m4_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. | |
271 | m4_define([b4_c_function_decl], | |
272 | [#if defined (__STDC__) || defined (__cplusplus) | |
273 | b4_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. | |
283 | m4_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. | |
298 | m4_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... | |
306 | m4_define([b4_c_args], | |
307 | [m4_map_sep([b4_c_arg], [, ], [$@])]) | |
308 | ||
309 | m4_define([b4_c_arg], | |
310 | [$2]) | |
437c2d80 AD |
311 | |
312 | ||
313 | ## ----------- ## | |
314 | ## Synclines. ## | |
315 | ## ----------- ## | |
316 | ||
317 | ||
318 | # b4_syncline(LINE, FILE) | |
319 | # ----------------------- | |
320 | m4_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 | # ------------------------------------------------- | |
329 | m4_define([b4_symbol_actions], | |
60c82948 PE |
330 | [m4_pushdef([b4_dollar_dollar], |
331 | [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl | |
7bd6c77e | 332 | m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl |
b0400cc6 AD |
333 | case $4: /* $3 */ |
334 | b4_syncline([$2], [$1]) | |
335 | $5; | |
336 | b4_syncline([@oline@], [@ofile@]) | |
337 | break; | |
338 | m4_popdef([b4_at_dollar])dnl | |
339 | m4_popdef([b4_dollar_dollar])dnl | |
340 | ]) | |
341 | ||
342 | ||
14740648 PE |
343 | # b4_yydestruct_generate(FUNCTION-DECLARATOR) |
344 | # ------------------------------------------- | |
b0400cc6 | 345 | # Generate the "yydestruct" function, which declaration is issued using |
14740648 | 346 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
b0400cc6 AD |
347 | # or "b4_c_function_def" for K&R. |
348 | m4_define([b4_yydestruct_generate], | |
349 | [[/*-----------------------------------------------. | |
350 | | Release the memory associated to this symbol. | | |
351 | `-----------------------------------------------*/ | |
352 | ||
353 | ]$1([yydestruct], | |
354 | [static void], | |
a0e68930 | 355 | [[const char *yymsg], [yymsg]], |
7bd6c77e AD |
356 | [[int yytype], [yytype]], |
357 | [[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([, | |
358 | [[YYLTYPE *yylocationp], [yylocationp]]]))[ | |
b0400cc6 AD |
359 | { |
360 | /* Pacify ``unused variable'' warnings. */ | |
7bd6c77e AD |
361 | (void) yyvaluep; |
362 | ]b4_location_if([ (void) yylocationp; | |
b0400cc6 | 363 | ])[ |
a0e68930 AD |
364 | if (!yymsg) |
365 | yymsg = "Deleting"; | |
366 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
367 | ||
b0400cc6 AD |
368 | switch (yytype) |
369 | { | |
370 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
371 | default: | |
372 | break; | |
373 | } | |
374 | }]dnl | |
375 | ]) | |
7bd6c77e AD |
376 | |
377 | ||
14740648 PE |
378 | # b4_yysymprint_generate(FUNCTION-DECLARATOR) |
379 | # ------------------------------------------- | |
7bd6c77e | 380 | # Generate the "yysymprint" function, which declaration is issued using |
14740648 | 381 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
7bd6c77e AD |
382 | # or "b4_c_function_def" for K&R. |
383 | m4_define([b4_yysymprint_generate], | |
14740648 PE |
384 | [[/*--------------------------------. |
385 | | Print this symbol on YYOUTPUT. | | |
386 | `--------------------------------*/ | |
7bd6c77e AD |
387 | |
388 | ]$1([yysymprint], | |
389 | [static void], | |
14740648 | 390 | [[FILE *yyoutput], [yyoutput]], |
7bd6c77e AD |
391 | [[int yytype], [yytype]], |
392 | [[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([, | |
393 | [[YYLTYPE *yylocationp], [yylocationp]]])) | |
394 | { | |
395 | /* Pacify ``unused variable'' warnings. */ | |
396 | (void) yyvaluep; | |
397 | b4_location_if([ (void) yylocationp; | |
398 | ])dnl | |
3fc16193 | 399 | [ |
7bd6c77e | 400 | if (yytype < YYNTOKENS) |
619404e3 | 401 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); |
7bd6c77e | 402 | else |
3fc16193 | 403 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); |
7bd6c77e | 404 | |
3fc16193 AD |
405 | ]b4_location_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); |
406 | fprintf (yyoutput, ": "); | |
407 | ])dnl | |
408 | [ | |
619404e3 AD |
409 | # ifdef YYPRINT |
410 | if (yytype < YYNTOKENS) | |
411 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
412 | # endif | |
7bd6c77e AD |
413 | switch (yytype) |
414 | { | |
3fc16193 AD |
415 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl |
416 | [ default: | |
7bd6c77e AD |
417 | break; |
418 | } | |
14740648 | 419 | YYFPRINTF (yyoutput, ")"); |
7bd6c77e | 420 | } |
3fc16193 | 421 | ]]) |