]>
Commit | Line | Data |
---|---|---|
08af01c2 | 1 | -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
7d424de1 | 4 | |
34136e65 | 5 | # Copyright (C) 2002, 2004-2012 Free Software Foundation, Inc. |
fb8135fa | 6 | |
f16b0819 | 7 | # This program is free software: you can redistribute it and/or modify |
fb8135fa | 8 | # it under the terms of the GNU General Public License as published by |
f16b0819 | 9 | # the Free Software Foundation, either version 3 of the License, or |
fb8135fa | 10 | # (at your option) any later version. |
f16b0819 | 11 | # |
fb8135fa AD |
12 | # This program is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
f16b0819 | 16 | # |
fb8135fa | 17 | # You should have received a copy of the GNU General Public License |
f16b0819 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
fb8135fa | 19 | |
2a8d363a AD |
20 | ## ---------------- ## |
21 | ## Identification. ## | |
22 | ## ---------------- ## | |
fb8135fa | 23 | |
6ab1adbe AD |
24 | # b4_comment_(TEXT, OPEN, CONTINUE, END) |
25 | # ------------------------------------- | |
30bb2edc AD |
26 | # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. |
27 | # Avoid adding indentation to the first line, as the indentation comes | |
6ab1adbe AD |
28 | # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). |
29 | # | |
30 | # Prefix all the output lines with PREFIX. | |
31 | m4_define([b4_comment_], [$2[]m4_bpatsubst([$1], [ | |
30bb2edc | 32 | \(.\)], [ |
6ab1adbe AD |
33 | $3\1])$4]) |
34 | ||
35 | ||
36 | # b4_c_comment(TEXT, [PREFIX]) | |
37 | # ---------------------------- | |
38 | # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. | |
39 | # Avoid adding indentation to the first line, as the indentation comes | |
40 | # from "/*". That's why we don't patsubst([$1], [^\(.\)], [ \1]). | |
41 | # | |
42 | # Prefix all the output lines with PREFIX. | |
43 | m4_define([b4_c_comment], | |
44 | [b4_comment_([$1], [$2/* ], [$2 ], [$2 */])]) | |
45 | ||
46 | ||
47 | # b4_comment(TEXT, [PREFIX]) | |
48 | # -------------------------- | |
49 | # By default, C comments. | |
50 | m4_define([b4_comment], [b4_c_comment($@)]) | |
51 | ||
fb8135fa | 52 | |
2a8d363a AD |
53 | # b4_identification |
54 | # ----------------- | |
d9df47b6 JD |
55 | # Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or |
56 | # b4_pull_flag if they use the values of the %define variables api.pure or | |
67212941 | 57 | # api.push-pull. |
2a8d363a | 58 | m4_define([b4_identification], |
d9df47b6 JD |
59 | [[/* Identify Bison output. */ |
60 | #define YYBISON 1 | |
2a8d363a | 61 | |
55f64b82 | 62 | /* Bison version. */ |
d9df47b6 | 63 | #define YYBISON_VERSION "]b4_version[" |
55f64b82 | 64 | |
2a8d363a | 65 | /* Skeleton name. */ |
d9df47b6 | 66 | #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ |
2a8d363a AD |
67 | |
68 | /* Pure parsers. */ | |
d9df47b6 JD |
69 | #define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[ |
70 | ||
71 | /* Push parsers. */ | |
72 | #define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[ | |
73 | ||
74 | /* Pull parsers. */ | |
75 | #define YYPULL ]b4_pull_flag])[ | |
2a8d363a AD |
76 | |
77 | /* Using locations. */ | |
bc0f5737 | 78 | #define YYLSP_NEEDED ]b4_locations_if([1], [0])[ |
d9df47b6 | 79 | ]]) |
2a8d363a AD |
80 | |
81 | ||
7ec2d4cd AD |
82 | ## ---------------- ## |
83 | ## Default values. ## | |
84 | ## ---------------- ## | |
85 | ||
1b818f33 AD |
86 | # If the %union is not named, its name is YYSTYPE. |
87 | m4_define_default([b4_union_name], [YYSTYPE]) | |
7ec2d4cd | 88 | |
90b9908d PB |
89 | # If the %name-prefix is not given, it is yy. |
90 | m4_define_default([b4_prefix], [yy]) | |
cd48d21d | 91 | |
2a8d363a AD |
92 | ## ------------------------ ## |
93 | ## Pure/impure interfaces. ## | |
94 | ## ------------------------ ## | |
95 | ||
2a8d363a AD |
96 | # b4_user_args |
97 | # ------------ | |
98 | m4_define([b4_user_args], | |
99 | [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])]) | |
100 | ||
101 | ||
102 | # b4_parse_param | |
103 | # -------------- | |
104 | # If defined, b4_parse_param arrives double quoted, but below we prefer | |
105 | # it to be single quoted. | |
2a8d363a | 106 | m4_define([b4_parse_param], |
7ecec4dd | 107 | b4_parse_param) |
2a8d363a | 108 | |
8f7e3cf9 | 109 | |
613d8952 AD |
110 | # b4_parse_param_for(DECL, FORMAL, BODY) |
111 | # --------------------------------------- | |
112 | # Iterate over the user parameters, binding the declaration to DECL, | |
113 | # the formal name to FORMAL, and evaluating the BODY. | |
114 | m4_define([b4_parse_param_for], | |
115 | [m4_foreach([$1_$2], m4_defn([b4_parse_param]), | |
6bbb2ed5 | 116 | [m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl |
613d8952 AD |
117 | m4_pushdef([$2], m4_shift($1_$2))dnl |
118 | $3[]dnl | |
119 | m4_popdef([$2])dnl | |
120 | m4_popdef([$1])dnl | |
121 | ])]) | |
122 | ||
beadb220 AD |
123 | # b4_parse_param_use([VAL], [LOC]) |
124 | # -------------------------------- | |
125 | # `YYUSE' VAL, LOC if locations are enabled, and all the parse-params. | |
613d8952 | 126 | m4_define([b4_parse_param_use], |
beadb220 AD |
127 | [m4_ifval([$1], [ YYUSE([$1]); |
128 | ])dnl | |
129 | m4_ifval([$2], [b4_locations_if([ YYUSE ([$2]); | |
130 | ])])dnl | |
131 | b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); | |
613d8952 AD |
132 | ])dnl |
133 | ]) | |
2a8d363a | 134 | |
8e1687ae | 135 | |
fb8135fa AD |
136 | ## ------------ ## |
137 | ## Data Types. ## | |
138 | ## ------------ ## | |
139 | ||
a762e609 AD |
140 | # b4_int_type(MIN, MAX) |
141 | # --------------------- | |
142 | # Return the smallest int type able to handle numbers ranging from | |
143 | # MIN to MAX (included). | |
144 | m4_define([b4_int_type], | |
145 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 146 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 | 147 | |
779e7ceb PE |
148 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
149 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
150 | |
151 | m4_eval([0 <= $1]), [1], [unsigned int], | |
152 | ||
e9690142 | 153 | [int])]) |
a762e609 | 154 | |
f1886bb2 | 155 | |
a762e609 AD |
156 | # b4_int_type_for(NAME) |
157 | # --------------------- | |
158 | # Return the smallest int type able to handle numbers ranging from | |
159 | # `NAME_min' to `NAME_max' (included). | |
160 | m4_define([b4_int_type_for], | |
161 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa | 162 | |
cf98343c | 163 | |
87412882 JD |
164 | # b4_table_value_equals(TABLE, VALUE, LITERAL) |
165 | # -------------------------------------------- | |
166 | # Without inducing a comparison warning from the compiler, check if the | |
167 | # literal value LITERAL equals VALUE from table TABLE, which must have | |
f2b30bdf JD |
168 | # TABLE_min and TABLE_max defined. YYID must be defined as an identity |
169 | # function that suppresses warnings about constant conditions. | |
87412882 JD |
170 | m4_define([b4_table_value_equals], |
171 | [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) | |
172 | || m4_indir([b4_]$1[_max]) < $3), [1], | |
173 | [[YYID (0)]], | |
174 | [[((]$2[) == (]$3[))]])]) | |
cf98343c | 175 | |
8e1687ae PE |
176 | ## ---------## |
177 | ## Values. ## | |
178 | ## ---------## | |
179 | ||
180 | # b4_null | |
181 | --------- | |
182 | # Return a null pointer constant. NULL infringes on the user name | |
183 | # space in C, so use 0 rather than NULL. | |
184 | m4_define([b4_null], [0]) | |
185 | ||
186 | ||
ba206cf4 AD |
187 | # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) |
188 | # ------------------------------------------------------------- | |
0991e29b | 189 | # Define "yy<TABLE-NAME>" which contents is CONTENT. |
ba206cf4 | 190 | m4_define([b4_integral_parser_table_define], |
0991e29b AD |
191 | [m4_ifval([$3], [b4_c_comment([$3], [ ]) |
192 | ])dnl | |
193 | static const b4_int_type_for([$2]) yy$1[[]] = | |
194 | { | |
195 | $2 | |
196 | };dnl | |
197 | ]) | |
cf98343c AD |
198 | |
199 | ||
fb8135fa AD |
200 | ## ------------------------- ## |
201 | ## Assigning token numbers. ## | |
202 | ## ------------------------- ## | |
203 | ||
204 | # b4_token_define(TOKEN-NAME, TOKEN-NUMBER) | |
205 | # ----------------------------------------- | |
206 | # Output the definition of this token as #define. | |
207 | m4_define([b4_token_define], | |
4c6622c2 | 208 | [#define b4_percent_define_get([api.tokens.prefix])$1 $2 |
fb8135fa AD |
209 | ]) |
210 | ||
211 | ||
cf147260 AD |
212 | # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
213 | # ------------------------------------------------------- | |
214 | # Output the definition of the tokens (if there are) as #defines. | |
215 | m4_define([b4_token_defines], | |
6bbb2ed5 | 216 | [m4_if([$#$1], [1], [], |
cf147260 AD |
217 | [/* Tokens. */ |
218 | m4_map([b4_token_define], [$@])]) | |
219 | ]) | |
220 | ||
221 | ||
fb8135fa AD |
222 | # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) |
223 | # --------------------------------------- | |
224 | # Output the definition of this token as an enum. | |
225 | m4_define([b4_token_enum], | |
4c6622c2 | 226 | [b4_percent_define_get([api.tokens.prefix])$1 = $2]) |
fb8135fa AD |
227 | |
228 | ||
cf147260 AD |
229 | # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
230 | # ----------------------------------------------------- | |
231 | # Output the definition of the tokens (if there are) as enums. | |
232 | m4_define([b4_token_enums], | |
6bbb2ed5 | 233 | [m4_if([$#$1], [1], [], |
fb8135fa | 234 | [/* Tokens. */ |
6b8c3254 PE |
235 | #ifndef YYTOKENTYPE |
236 | # define YYTOKENTYPE | |
fb8135fa AD |
237 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
238 | know about them. */ | |
239 | enum yytokentype { | |
240 | m4_map_sep([ b4_token_enum], [, | |
241 | ], | |
e9690142 | 242 | [$@]) |
fb8135fa | 243 | }; |
095b9f05 | 244 | #endif |
cf147260 AD |
245 | ])]) |
246 | ||
247 | ||
248 | # b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) | |
249 | # ------------------------------------------------------------- | |
b931235e JD |
250 | # Output the definition of the tokens (if there are any) as enums and, if POSIX |
251 | # Yacc is enabled, as #defines. | |
cf147260 | 252 | m4_define([b4_token_enums_defines], |
b931235e | 253 | [b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], []) |
fb8135fa | 254 | ]) |
4a2a22f4 AD |
255 | |
256 | ||
1fa5d8bb AD |
257 | ## ----------------- ## |
258 | ## Semantic Values. ## | |
259 | ## ----------------- ## | |
260 | ||
261 | ||
262 | # b4_symbol_value(VAL, [TYPE]) | |
263 | # ---------------------------- | |
264 | # Given a semantic value VAL ($$, $1 etc.), extract its value of type | |
265 | # TYPE if TYPE is given, otherwise just return VAL. The result can be | |
266 | # used safetly, it is put in parens to avoid nasty precedence issues. | |
267 | # TYPE is *not* put in braces, provide some if needed. | |
268 | m4_define([b4_symbol_value], | |
269 | [($1[]m4_ifval([$2], [.$2]))]) | |
270 | ||
271 | ||
ae7453f2 | 272 | |
0245f82d AD |
273 | ## --------------------------------------------- ## |
274 | ## Defining C functions in both K&R and ANSI-C. ## | |
275 | ## --------------------------------------------- ## | |
4a2a22f4 AD |
276 | |
277 | ||
1b9c21fb PE |
278 | # b4_modern_c |
279 | # ----------- | |
280 | # A predicate useful in #if to determine whether C is ancient or modern. | |
281 | # | |
282 | # If __STDC__ is defined, the compiler is modern. IBM xlc 7.0 when run | |
283 | # as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic | |
284 | # reasons, but it defines __C99__FUNC__ so check that as well. | |
285 | # Microsoft C normally doesn't define these macros, but it defines _MSC_VER. | |
7a0db73e | 286 | # Consider a C++ compiler to be modern if it defines __cplusplus. |
1b9c21fb PE |
287 | # |
288 | m4_define([b4_c_modern], | |
02650b7f PE |
289 | [[(defined __STDC__ || defined __C99__FUNC__ \ |
290 | || defined __cplusplus || defined _MSC_VER)]]) | |
1b9c21fb | 291 | |
0245f82d AD |
292 | # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
293 | # ---------------------------------------------------------- | |
4a2a22f4 | 294 | # Declare the function NAME. |
0245f82d | 295 | m4_define([b4_c_function_def], |
1b9c21fb | 296 | [#if b4_c_modern |
0245f82d | 297 | b4_c_ansi_function_def($@) |
4a2a22f4 | 298 | #else |
0245f82d | 299 | $2 |
a3764451 EB |
300 | $1 (b4_c_knr_formal_names(m4_shift2($@))) |
301 | b4_c_knr_formal_decls(m4_shift2($@)) | |
4a2a22f4 AD |
302 | #endif[]dnl |
303 | ]) | |
304 | ||
305 | ||
0245f82d AD |
306 | # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
307 | # --------------------------------------------------------------- | |
308 | # Declare the function NAME in ANSI. | |
309 | m4_define([b4_c_ansi_function_def], | |
310 | [$2 | |
a3764451 | 311 | $1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl |
0245f82d AD |
312 | ]) |
313 | ||
314 | ||
315 | # b4_c_ansi_formals([DECL1, NAME1], ...) | |
316 | # -------------------------------------- | |
4a2a22f4 | 317 | # Output the arguments ANSI-C definition. |
0245f82d | 318 | m4_define([b4_c_ansi_formals], |
6bbb2ed5 EB |
319 | [m4_if([$#], [0], [void], |
320 | [$#$1], [1], [void], | |
e9690142 | 321 | [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) |
4a2a22f4 | 322 | |
0245f82d AD |
323 | m4_define([b4_c_ansi_formal], |
324 | [$1]) | |
4a2a22f4 AD |
325 | |
326 | ||
0245f82d AD |
327 | # b4_c_knr_formal_names([DECL1, NAME1], ...) |
328 | # ------------------------------------------ | |
4a2a22f4 | 329 | # Output the argument names. |
0245f82d AD |
330 | m4_define([b4_c_knr_formal_names], |
331 | [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])]) | |
4a2a22f4 | 332 | |
0245f82d | 333 | m4_define([b4_c_knr_formal_name], |
4a2a22f4 AD |
334 | [$2]) |
335 | ||
336 | ||
0245f82d AD |
337 | # b4_c_knr_formal_decls([DECL1, NAME1], ...) |
338 | # ------------------------------------------ | |
4a2a22f4 | 339 | # Output the K&R argument declarations. |
0245f82d AD |
340 | m4_define([b4_c_knr_formal_decls], |
341 | [m4_map_sep([b4_c_knr_formal_decl], | |
e9690142 | 342 | [ |
4a2a22f4 | 343 | ], |
e9690142 | 344 | [$@])]) |
4a2a22f4 | 345 | |
0245f82d AD |
346 | m4_define([b4_c_knr_formal_decl], |
347 | [ $1;]) | |
21964f43 AD |
348 | |
349 | ||
350 | ||
0245f82d AD |
351 | ## ------------------------------------------------------------ ## |
352 | ## Declaring (prototyping) C functions in both K&R and ANSI-C. ## | |
353 | ## ------------------------------------------------------------ ## | |
21964f43 AD |
354 | |
355 | ||
0245f82d AD |
356 | # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
357 | # ----------------------------------------------------------- | |
358 | # Declare the function NAME. | |
359 | m4_define([b4_c_function_decl], | |
6ceccee8 | 360 | [#if b4_c_modern |
0245f82d AD |
361 | b4_c_ansi_function_decl($@) |
362 | #else | |
363 | $2 $1 (); | |
364 | #endif[]dnl | |
365 | ]) | |
21964f43 AD |
366 | |
367 | ||
0245f82d AD |
368 | # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
369 | # ---------------------------------------------------------------- | |
370 | # Declare the function NAME. | |
371 | m4_define([b4_c_ansi_function_decl], | |
a3764451 | 372 | [$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl |
0245f82d AD |
373 | ]) |
374 | ||
375 | ||
376 | ||
377 | ||
378 | ## --------------------- ## | |
379 | ## Calling C functions. ## | |
380 | ## --------------------- ## | |
381 | ||
382 | ||
383 | # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) | |
384 | # ----------------------------------------------------------- | |
385 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
386 | m4_define([b4_c_function_call], | |
a3764451 | 387 | [$1 (b4_c_args(m4_shift2($@)))[]dnl |
0245f82d AD |
388 | ]) |
389 | ||
390 | ||
391 | # b4_c_args([DECL1, NAME1], ...) | |
392 | # ------------------------------ | |
393 | # Output the arguments NAME1, NAME2... | |
394 | m4_define([b4_c_args], | |
395 | [m4_map_sep([b4_c_arg], [, ], [$@])]) | |
396 | ||
397 | m4_define([b4_c_arg], | |
398 | [$2]) | |
437c2d80 AD |
399 | |
400 | ||
401 | ## ----------- ## | |
402 | ## Synclines. ## | |
403 | ## ----------- ## | |
404 | ||
90b9908d | 405 | # b4_sync_start(LINE, FILE) |
8ec0a172 | 406 | # ----------------------- |
90b9908d | 407 | m4_define([b4_sync_start], [[#]line $1 $2]) |
8ec0a172 | 408 | |
613d8952 AD |
409 | |
410 | ## -------------- ## | |
411 | ## User actions. ## | |
412 | ## -------------- ## | |
413 | ||
8e1687ae PE |
414 | # b4_case(LABEL, STATEMENTS) |
415 | # -------------------------- | |
416 | m4_define([b4_case], | |
417 | [ case $1: | |
418 | $2 | |
2141aded | 419 | b4_syncline([@oline@], [@ofile@]) |
8e1687ae PE |
420 | break;]) |
421 | ||
b0400cc6 | 422 | |
ca2a6d15 PH |
423 | # b4_predicate_case(LABEL, CONDITIONS) |
424 | # ------------------------------------ | |
425 | m4_define([b4_predicate_case], | |
426 | [ case $1: | |
427 | if (! ($2)) YYERROR; | |
428 | b4_syncline([@oline@], [@ofile@]) | |
429 | break;]) | |
430 | ||
431 | ||
14740648 PE |
432 | # b4_yydestruct_generate(FUNCTION-DECLARATOR) |
433 | # ------------------------------------------- | |
b0400cc6 | 434 | # Generate the "yydestruct" function, which declaration is issued using |
14740648 | 435 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
b0400cc6 | 436 | # or "b4_c_function_def" for K&R. |
cf147260 | 437 | m4_define_default([b4_yydestruct_generate], |
b0400cc6 AD |
438 | [[/*-----------------------------------------------. |
439 | | Release the memory associated to this symbol. | | |
440 | `-----------------------------------------------*/ | |
441 | ||
12ce2df6 | 442 | /*ARGSUSED*/ |
b0400cc6 AD |
443 | ]$1([yydestruct], |
444 | [static void], | |
a0e68930 | 445 | [[const char *yymsg], [yymsg]], |
7bd6c77e | 446 | [[int yytype], [yytype]], |
4b367315 | 447 | [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl |
327afc7c | 448 | b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl |
4b367315 | 449 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
b0400cc6 | 450 | { |
beadb220 | 451 | ]b4_parse_param_use([yyvaluep], [yylocationp])[ |
a0e68930 AD |
452 | if (!yymsg) |
453 | yymsg = "Deleting"; | |
454 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
455 | ||
b0400cc6 AD |
456 | switch (yytype) |
457 | { | |
3bb21113 AD |
458 | ]b4_symbol_foreach([b4_symbol_destructor])dnl |
459 | [ default: | |
e9690142 | 460 | break; |
b0400cc6 AD |
461 | } |
462 | }]dnl | |
463 | ]) | |
7bd6c77e AD |
464 | |
465 | ||
a0af42fc AD |
466 | # b4_yy_symbol_print_generate(FUNCTION-DECLARATOR) |
467 | # ------------------------------------------------ | |
468 | # Generate the "yy_symbol_print" function, which declaration is issued using | |
14740648 | 469 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
7bd6c77e | 470 | # or "b4_c_function_def" for K&R. |
a0af42fc AD |
471 | m4_define_default([b4_yy_symbol_print_generate], |
472 | [[ | |
473 | /*--------------------------------. | |
14740648 PE |
474 | | Print this symbol on YYOUTPUT. | |
475 | `--------------------------------*/ | |
7bd6c77e | 476 | |
12ce2df6 | 477 | /*ARGSUSED*/ |
a0af42fc | 478 | ]$1([yy_symbol_value_print], |
7bd6c77e | 479 | [static void], |
e9690142 JD |
480 | [[FILE *yyoutput], [yyoutput]], |
481 | [[int yytype], [yytype]], | |
482 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl | |
50cce58e | 483 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl |
4b367315 | 484 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
7bd6c77e | 485 | { |
9bfbf75b | 486 | ]b4_parse_param_use([yyoutput], [yylocationp])[ |
05449a2c JD |
487 | if (!yyvaluep) |
488 | return; | |
beadb220 | 489 | # ifdef YYPRINT |
619404e3 AD |
490 | if (yytype < YYNTOKENS) |
491 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
492 | # endif | |
7bd6c77e AD |
493 | switch (yytype) |
494 | { | |
3bb21113 | 495 | ]b4_symbol_foreach([b4_symbol_printer])dnl |
3fc16193 | 496 | [ default: |
e9690142 | 497 | break; |
7bd6c77e | 498 | } |
a0af42fc AD |
499 | } |
500 | ||
501 | ||
502 | /*--------------------------------. | |
503 | | Print this symbol on YYOUTPUT. | | |
504 | `--------------------------------*/ | |
505 | ||
506 | ]$1([yy_symbol_print], | |
507 | [static void], | |
e9690142 JD |
508 | [[FILE *yyoutput], [yyoutput]], |
509 | [[int yytype], [yytype]], | |
510 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl | |
50cce58e | 511 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl |
a0af42fc AD |
512 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
513 | { | |
514 | if (yytype < YYNTOKENS) | |
515 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
516 | else | |
517 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
518 | ||
327afc7c | 519 | ]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); |
a0af42fc AD |
520 | YYFPRINTF (yyoutput, ": "); |
521 | ])dnl | |
522 | [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl | |
327afc7c | 523 | b4_locations_if([, yylocationp])[]b4_user_args[); |
2f4f028d | 524 | YYFPRINTF (yyoutput, ")"); |
4b367315 AD |
525 | }]dnl |
526 | ]) |