]>
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 | |
cd735a8c | 20 | m4_include(b4_pkgdatadir/[c-like.m4]) |
22172d47 AD |
21 | |
22 | # b4_tocpp(STRING) | |
23 | # ---------------- | |
24 | # Convert STRING into a valid C macro name. | |
25 | m4_define([b4_tocpp], | |
26 | [m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))]) | |
27 | ||
28 | ||
29 | # b4_cpp_guard(FILE) | |
30 | # ------------------ | |
31 | # A valid C macro name to use as a CPP header guard for FILE. | |
32 | m4_define([b4_cpp_guard], | |
33 | [b4_tocpp(m4_defn([b4_prefix])/[$1])]) | |
34 | ||
35 | ||
36 | # b4_cpp_guard_open(FILE) | |
37 | # b4_cpp_guard_close(FILE) | |
38 | # ------------------------ | |
39 | # Open/close CPP inclusion guards for FILE. | |
40 | m4_define([b4_cpp_guard_open], | |
41 | [#ifndef b4_cpp_guard([$1]) | |
42 | # define b4_cpp_guard([$1])]) | |
43 | ||
44 | m4_define([b4_cpp_guard_close], | |
45 | [#endif b4_comment([!b4_cpp_guard([$1])])]) | |
46 | ||
47 | ||
2a8d363a AD |
48 | ## ---------------- ## |
49 | ## Identification. ## | |
50 | ## ---------------- ## | |
fb8135fa | 51 | |
6ab1adbe | 52 | # b4_comment_(TEXT, OPEN, CONTINUE, END) |
15f66669 | 53 | # -------------------------------------- |
30bb2edc AD |
54 | # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. |
55 | # Avoid adding indentation to the first line, as the indentation comes | |
6ab1adbe AD |
56 | # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). |
57 | # | |
58 | # Prefix all the output lines with PREFIX. | |
59 | m4_define([b4_comment_], [$2[]m4_bpatsubst([$1], [ | |
30bb2edc | 60 | \(.\)], [ |
6ab1adbe AD |
61 | $3\1])$4]) |
62 | ||
63 | ||
15f66669 AD |
64 | # b4_comment(TEXT, [PREFIX]) |
65 | # -------------------------- | |
6ab1adbe AD |
66 | # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. |
67 | # Avoid adding indentation to the first line, as the indentation comes | |
68 | # from "/*". That's why we don't patsubst([$1], [^\(.\)], [ \1]). | |
69 | # | |
70 | # Prefix all the output lines with PREFIX. | |
15f66669 | 71 | m4_define([b4_comment], |
6ab1adbe AD |
72 | [b4_comment_([$1], [$2/* ], [$2 ], [$2 */])]) |
73 | ||
74 | ||
2a8d363a AD |
75 | # b4_identification |
76 | # ----------------- | |
d9df47b6 JD |
77 | # Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or |
78 | # b4_pull_flag if they use the values of the %define variables api.pure or | |
67212941 | 79 | # api.push-pull. |
2a8d363a | 80 | m4_define([b4_identification], |
d9df47b6 JD |
81 | [[/* Identify Bison output. */ |
82 | #define YYBISON 1 | |
2a8d363a | 83 | |
55f64b82 | 84 | /* Bison version. */ |
d9df47b6 | 85 | #define YYBISON_VERSION "]b4_version[" |
55f64b82 | 86 | |
2a8d363a | 87 | /* Skeleton name. */ |
d9df47b6 | 88 | #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ |
2a8d363a AD |
89 | |
90 | /* Pure parsers. */ | |
d9df47b6 JD |
91 | #define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[ |
92 | ||
93 | /* Push parsers. */ | |
94 | #define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[ | |
95 | ||
96 | /* Pull parsers. */ | |
97 | #define YYPULL ]b4_pull_flag])[ | |
d9df47b6 | 98 | ]]) |
2a8d363a AD |
99 | |
100 | ||
7ec2d4cd AD |
101 | ## ---------------- ## |
102 | ## Default values. ## | |
103 | ## ---------------- ## | |
104 | ||
4b3847c3 AD |
105 | # b4_api_prefix, b4_api_PREFIX |
106 | # ---------------------------- | |
107 | # Corresponds to %define api.prefix | |
108 | b4_percent_define_default([[api.prefix]], [[yy]]) | |
109 | m4_define([b4_api_prefix], | |
110 | [b4_percent_define_get([[api.prefix]])]) | |
111 | m4_define([b4_api_PREFIX], | |
112 | [m4_toupper(b4_api_prefix)]) | |
113 | ||
114 | ||
115 | # b4_prefix | |
116 | # --------- | |
117 | # If the %name-prefix is not given, it is api.prefix. | |
118 | m4_define_default([b4_prefix], [b4_api_prefix]) | |
119 | ||
1b818f33 | 120 | # If the %union is not named, its name is YYSTYPE. |
4b3847c3 | 121 | m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE]) |
7ec2d4cd | 122 | |
cd48d21d | 123 | |
2a8d363a AD |
124 | ## ------------------------ ## |
125 | ## Pure/impure interfaces. ## | |
126 | ## ------------------------ ## | |
127 | ||
2a8d363a AD |
128 | # b4_user_args |
129 | # ------------ | |
130 | m4_define([b4_user_args], | |
15f66669 | 131 | [m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])]) |
2a8d363a AD |
132 | |
133 | ||
134 | # b4_parse_param | |
135 | # -------------- | |
136 | # If defined, b4_parse_param arrives double quoted, but below we prefer | |
137 | # it to be single quoted. | |
2a8d363a | 138 | m4_define([b4_parse_param], |
7ecec4dd | 139 | b4_parse_param) |
2a8d363a | 140 | |
8f7e3cf9 | 141 | |
613d8952 AD |
142 | # b4_parse_param_for(DECL, FORMAL, BODY) |
143 | # --------------------------------------- | |
144 | # Iterate over the user parameters, binding the declaration to DECL, | |
145 | # the formal name to FORMAL, and evaluating the BODY. | |
146 | m4_define([b4_parse_param_for], | |
147 | [m4_foreach([$1_$2], m4_defn([b4_parse_param]), | |
6bbb2ed5 | 148 | [m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl |
613d8952 AD |
149 | m4_pushdef([$2], m4_shift($1_$2))dnl |
150 | $3[]dnl | |
151 | m4_popdef([$2])dnl | |
152 | m4_popdef([$1])dnl | |
153 | ])]) | |
154 | ||
beadb220 AD |
155 | # b4_parse_param_use([VAL], [LOC]) |
156 | # -------------------------------- | |
157 | # `YYUSE' VAL, LOC if locations are enabled, and all the parse-params. | |
613d8952 | 158 | m4_define([b4_parse_param_use], |
1e5d6540 AD |
159 | [m4_ifvaln([$1], [ YYUSE([$1]);])dnl |
160 | b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl | |
beadb220 | 161 | b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); |
613d8952 AD |
162 | ])dnl |
163 | ]) | |
2a8d363a | 164 | |
8e1687ae | 165 | |
fb8135fa AD |
166 | ## ------------ ## |
167 | ## Data Types. ## | |
168 | ## ------------ ## | |
169 | ||
a762e609 AD |
170 | # b4_int_type(MIN, MAX) |
171 | # --------------------- | |
172 | # Return the smallest int type able to handle numbers ranging from | |
173 | # MIN to MAX (included). | |
174 | m4_define([b4_int_type], | |
175 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 176 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 | 177 | |
779e7ceb PE |
178 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
179 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
180 | |
181 | m4_eval([0 <= $1]), [1], [unsigned int], | |
182 | ||
e9690142 | 183 | [int])]) |
a762e609 | 184 | |
f1886bb2 | 185 | |
a762e609 AD |
186 | # b4_int_type_for(NAME) |
187 | # --------------------- | |
188 | # Return the smallest int type able to handle numbers ranging from | |
189 | # `NAME_min' to `NAME_max' (included). | |
190 | m4_define([b4_int_type_for], | |
191 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa | 192 | |
cf98343c | 193 | |
87412882 JD |
194 | # b4_table_value_equals(TABLE, VALUE, LITERAL) |
195 | # -------------------------------------------- | |
196 | # Without inducing a comparison warning from the compiler, check if the | |
197 | # literal value LITERAL equals VALUE from table TABLE, which must have | |
f2b30bdf JD |
198 | # TABLE_min and TABLE_max defined. YYID must be defined as an identity |
199 | # function that suppresses warnings about constant conditions. | |
87412882 JD |
200 | m4_define([b4_table_value_equals], |
201 | [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) | |
202 | || m4_indir([b4_]$1[_max]) < $3), [1], | |
203 | [[YYID (0)]], | |
204 | [[((]$2[) == (]$3[))]])]) | |
cf98343c | 205 | |
ef51bfa7 | 206 | |
8e1687ae PE |
207 | ## ---------## |
208 | ## Values. ## | |
209 | ## ---------## | |
210 | ||
8e1687ae | 211 | |
ef51bfa7 AD |
212 | # b4_null_define |
213 | # -------------- | |
214 | # Portability issues: define a YY_NULL appropriate for the current | |
215 | # language (C, C++98, or C++11). | |
216 | m4_define([b4_null_define], | |
217 | [# ifndef YY_NULL | |
218 | # if defined __cplusplus && 201103L <= __cplusplus | |
219 | # define YY_NULL nullptr | |
220 | # else | |
221 | # define YY_NULL 0 | |
222 | # endif | |
223 | # endif[]dnl | |
224 | ]) | |
225 | ||
226 | ||
227 | # b4_null | |
228 | # ------- | |
229 | # Return a null pointer constant. | |
230 | m4_define([b4_null], [YY_NULL]) | |
8e1687ae | 231 | |
ba206cf4 AD |
232 | # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) |
233 | # ------------------------------------------------------------- | |
0991e29b | 234 | # Define "yy<TABLE-NAME>" which contents is CONTENT. |
ba206cf4 | 235 | m4_define([b4_integral_parser_table_define], |
15f66669 | 236 | [m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl |
0991e29b AD |
237 | static const b4_int_type_for([$2]) yy$1[[]] = |
238 | { | |
239 | $2 | |
240 | };dnl | |
241 | ]) | |
cf98343c AD |
242 | |
243 | ||
fb8135fa AD |
244 | ## ------------------------- ## |
245 | ## Assigning token numbers. ## | |
246 | ## ------------------------- ## | |
247 | ||
e3990e3c AD |
248 | # b4_token_define(TOKEN-NUM) |
249 | # -------------------------- | |
fb8135fa AD |
250 | # Output the definition of this token as #define. |
251 | m4_define([b4_token_define], | |
e3990e3c | 252 | [b4_token_format([#define %s %s], [$1])]) |
fb8135fa | 253 | |
e3990e3c AD |
254 | # b4_token_defines |
255 | # ---------------- | |
256 | # Output the definition of the tokens. | |
cf147260 | 257 | m4_define([b4_token_defines], |
e3990e3c AD |
258 | [b4_any_token_visible_if([/* Tokens. */ |
259 | m4_join([ | |
260 | ], b4_symbol_map([b4_token_define])) | |
261 | ])]) | |
cf147260 AD |
262 | |
263 | ||
e3990e3c AD |
264 | # b4_token_enum(TOKEN-NUM) |
265 | # ------------------------ | |
fb8135fa AD |
266 | # Output the definition of this token as an enum. |
267 | m4_define([b4_token_enum], | |
e3990e3c | 268 | [b4_token_format([%s = %s], [$1])]) |
fb8135fa AD |
269 | |
270 | ||
e3990e3c AD |
271 | # b4_token_enums |
272 | # -------------- | |
cf147260 AD |
273 | # Output the definition of the tokens (if there are) as enums. |
274 | m4_define([b4_token_enums], | |
e3990e3c | 275 | [b4_any_token_visible_if([[/* Tokens. */ |
4b3847c3 AD |
276 | #ifndef ]b4_api_PREFIX[TOKENTYPE |
277 | # define ]b4_api_PREFIX[TOKENTYPE | |
e3990e3c AD |
278 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
279 | know about them. */ | |
280 | enum ]b4_api_prefix[tokentype | |
281 | { | |
282 | ]m4_join([, | |
283 | ], | |
284 | b4_symbol_map([b4_token_enum]))[ | |
285 | }; | |
095b9f05 | 286 | #endif |
4b3847c3 | 287 | ]])]) |
cf147260 AD |
288 | |
289 | ||
e3990e3c AD |
290 | # b4_token_enums_defines |
291 | # ---------------------- | |
292 | # Output the definition of the tokens (if there are any) as enums and, | |
293 | # if POSIX Yacc is enabled, as #defines. | |
cf147260 | 294 | m4_define([b4_token_enums_defines], |
e3990e3c | 295 | [b4_token_enums[]b4_yacc_if([b4_token_defines])]) |
4a2a22f4 AD |
296 | |
297 | ||
1fa5d8bb AD |
298 | ## ----------------- ## |
299 | ## Semantic Values. ## | |
300 | ## ----------------- ## | |
301 | ||
302 | ||
303 | # b4_symbol_value(VAL, [TYPE]) | |
304 | # ---------------------------- | |
305 | # Given a semantic value VAL ($$, $1 etc.), extract its value of type | |
306 | # TYPE if TYPE is given, otherwise just return VAL. The result can be | |
307 | # used safetly, it is put in parens to avoid nasty precedence issues. | |
308 | # TYPE is *not* put in braces, provide some if needed. | |
309 | m4_define([b4_symbol_value], | |
310 | [($1[]m4_ifval([$2], [.$2]))]) | |
311 | ||
312 | ||
ae7453f2 | 313 | |
71b56f46 AD |
314 | ## ---------------------- ## |
315 | ## Defining C functions. ## | |
316 | ## ---------------------- ## | |
4a2a22f4 AD |
317 | |
318 | ||
15f66669 AD |
319 | # b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
320 | # ----------------------------------------------------------- | |
71b56f46 | 321 | # Declare the function NAME in C. |
15f66669 | 322 | m4_define([b4_function_define], |
0245f82d | 323 | [$2 |
15f66669 | 324 | $1 (b4_formals(m4_shift2($@)))[]dnl |
0245f82d AD |
325 | ]) |
326 | ||
327 | ||
15f66669 AD |
328 | # b4_formals([DECL1, NAME1], ...) |
329 | # ------------------------------- | |
71b56f46 | 330 | # The formal arguments of a C function definition. |
15f66669 | 331 | m4_define([b4_formals], |
6bbb2ed5 EB |
332 | [m4_if([$#], [0], [void], |
333 | [$#$1], [1], [void], | |
15f66669 | 334 | [m4_map_sep([b4_formal], [, ], [$@])])]) |
4a2a22f4 | 335 | |
15f66669 | 336 | m4_define([b4_formal], |
0245f82d | 337 | [$1]) |
4a2a22f4 AD |
338 | |
339 | ||
4a2a22f4 | 340 | |
71b56f46 AD |
341 | ## ----------------------- ## |
342 | ## Declaring C functions. ## | |
343 | ## ----------------------- ## | |
21964f43 AD |
344 | |
345 | ||
15f66669 AD |
346 | # b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
347 | # ------------------------------------------------------------ | |
0245f82d | 348 | # Declare the function NAME. |
15f66669 AD |
349 | m4_define([b4_function_declare], |
350 | [$2 $1 (b4_formals(m4_shift2($@)));[]dnl | |
0245f82d AD |
351 | ]) |
352 | ||
353 | ||
354 | ||
355 | ||
356 | ## --------------------- ## | |
357 | ## Calling C functions. ## | |
358 | ## --------------------- ## | |
359 | ||
360 | ||
15f66669 | 361 | # b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
0245f82d AD |
362 | # ----------------------------------------------------------- |
363 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
15f66669 AD |
364 | m4_define([b4_function_call], |
365 | [$1 (b4_args(m4_shift2($@)))[]dnl | |
0245f82d AD |
366 | ]) |
367 | ||
368 | ||
15f66669 AD |
369 | # b4_args([DECL1, NAME1], ...) |
370 | # ---------------------------- | |
0245f82d | 371 | # Output the arguments NAME1, NAME2... |
15f66669 AD |
372 | m4_define([b4_args], |
373 | [m4_map_sep([b4_arg], [, ], [$@])]) | |
0245f82d | 374 | |
15f66669 | 375 | m4_define([b4_arg], |
0245f82d | 376 | [$2]) |
437c2d80 AD |
377 | |
378 | ||
379 | ## ----------- ## | |
380 | ## Synclines. ## | |
381 | ## ----------- ## | |
382 | ||
90b9908d | 383 | # b4_sync_start(LINE, FILE) |
15f66669 | 384 | # ------------------------- |
90b9908d | 385 | m4_define([b4_sync_start], [[#]line $1 $2]) |
8ec0a172 | 386 | |
613d8952 AD |
387 | |
388 | ## -------------- ## | |
389 | ## User actions. ## | |
390 | ## -------------- ## | |
391 | ||
8e1687ae PE |
392 | # b4_case(LABEL, STATEMENTS) |
393 | # -------------------------- | |
394 | m4_define([b4_case], | |
395 | [ case $1: | |
396 | $2 | |
2141aded | 397 | b4_syncline([@oline@], [@ofile@]) |
8e1687ae PE |
398 | break;]) |
399 | ||
b0400cc6 | 400 | |
ca2a6d15 PH |
401 | # b4_predicate_case(LABEL, CONDITIONS) |
402 | # ------------------------------------ | |
403 | m4_define([b4_predicate_case], | |
404 | [ case $1: | |
405 | if (! ($2)) YYERROR; | |
406 | b4_syncline([@oline@], [@ofile@]) | |
407 | break;]) | |
408 | ||
409 | ||
e3f12e08 AD |
410 | # b4_yydestruct_define |
411 | # -------------------- | |
d00ff612 | 412 | # Define the "yydestruct" function. |
e3f12e08 | 413 | m4_define_default([b4_yydestruct_define], |
b0400cc6 AD |
414 | [[/*-----------------------------------------------. |
415 | | Release the memory associated to this symbol. | | |
416 | `-----------------------------------------------*/ | |
417 | ||
12ce2df6 | 418 | /*ARGSUSED*/ |
d00ff612 | 419 | ]b4_function_define([yydestruct], |
b0400cc6 | 420 | [static void], |
a0e68930 | 421 | [[const char *yymsg], [yymsg]], |
7bd6c77e | 422 | [[int yytype], [yytype]], |
4b367315 | 423 | [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl |
327afc7c | 424 | b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl |
4b367315 | 425 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
b0400cc6 | 426 | { |
1e5d6540 AD |
427 | ]b4_parse_param_use([yyvaluep], [yylocationp])dnl |
428 | [ if (!yymsg) | |
a0e68930 AD |
429 | yymsg = "Deleting"; |
430 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
431 | ||
b0400cc6 AD |
432 | switch (yytype) |
433 | { | |
3bb21113 AD |
434 | ]b4_symbol_foreach([b4_symbol_destructor])dnl |
435 | [ default: | |
e9690142 | 436 | break; |
b0400cc6 AD |
437 | } |
438 | }]dnl | |
439 | ]) | |
7bd6c77e AD |
440 | |
441 | ||
e3f12e08 AD |
442 | # b4_yy_symbol_print_define |
443 | # ------------------------- | |
d00ff612 | 444 | # Define the "yy_symbol_print" function. |
e3f12e08 | 445 | m4_define_default([b4_yy_symbol_print_define], |
a0af42fc AD |
446 | [[ |
447 | /*--------------------------------. | |
14740648 PE |
448 | | Print this symbol on YYOUTPUT. | |
449 | `--------------------------------*/ | |
7bd6c77e | 450 | |
12ce2df6 | 451 | /*ARGSUSED*/ |
d00ff612 | 452 | ]b4_function_define([yy_symbol_value_print], |
7bd6c77e | 453 | [static void], |
e9690142 JD |
454 | [[FILE *yyoutput], [yyoutput]], |
455 | [[int yytype], [yytype]], | |
456 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl | |
50cce58e | 457 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl |
4b367315 | 458 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
7bd6c77e | 459 | { |
c5026327 AD |
460 | FILE *yyo = yyoutput; |
461 | ]b4_parse_param_use([yyo], [yylocationp])dnl | |
1e5d6540 | 462 | [ if (!yyvaluep) |
fc257703 AD |
463 | return;] |
464 | dnl glr.c does not feature yytoknum. | |
465 | m4_if(b4_skeleton, ["yacc.c"], | |
466 | [[# ifdef YYPRINT | |
619404e3 AD |
467 | if (yytype < YYNTOKENS) |
468 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
469 | # endif | |
fc257703 AD |
470 | ]])dnl |
471 | [ switch (yytype) | |
7bd6c77e | 472 | { |
3bb21113 | 473 | ]b4_symbol_foreach([b4_symbol_printer])dnl |
3fc16193 | 474 | [ default: |
e9690142 | 475 | break; |
7bd6c77e | 476 | } |
a0af42fc AD |
477 | } |
478 | ||
479 | ||
480 | /*--------------------------------. | |
481 | | Print this symbol on YYOUTPUT. | | |
482 | `--------------------------------*/ | |
483 | ||
d00ff612 | 484 | ]b4_function_define([yy_symbol_print], |
a0af42fc | 485 | [static void], |
e9690142 JD |
486 | [[FILE *yyoutput], [yyoutput]], |
487 | [[int yytype], [yytype]], | |
488 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl | |
50cce58e | 489 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl |
a0af42fc AD |
490 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
491 | { | |
492 | if (yytype < YYNTOKENS) | |
493 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
494 | else | |
495 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
496 | ||
327afc7c | 497 | ]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); |
a0af42fc AD |
498 | YYFPRINTF (yyoutput, ": "); |
499 | ])dnl | |
500 | [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl | |
327afc7c | 501 | b4_locations_if([, yylocationp])[]b4_user_args[); |
2f4f028d | 502 | YYFPRINTF (yyoutput, ")"); |
4b367315 AD |
503 | }]dnl |
504 | ]) | |
c0828abf AD |
505 | |
506 | ## -------------- ## | |
507 | ## Declarations. ## | |
508 | ## -------------- ## | |
509 | ||
510 | # b4_declare_yylstype | |
4b3847c3 | 511 | # ------------------- |
756257ee AD |
512 | # Declarations that might either go into the header (if --defines) or |
513 | # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. | |
c0828abf | 514 | m4_define([b4_declare_yylstype], |
4b3847c3 | 515 | [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED |
c0828abf AD |
516 | ]m4_ifdef([b4_stype], |
517 | [[typedef union ]b4_union_name[ | |
518 | { | |
519 | ]b4_user_stype[ | |
4b3847c3 AD |
520 | } ]b4_api_PREFIX[STYPE; |
521 | # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]], | |
c0828abf | 522 | [m4_if(b4_tag_seen_flag, 0, |
4b3847c3 AD |
523 | [[typedef int ]b4_api_PREFIX[STYPE; |
524 | # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]])])[ | |
4b3847c3 | 525 | # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 |
c0828abf AD |
526 | #endif]b4_locations_if([[ |
527 | ||
4b3847c3 AD |
528 | #if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED |
529 | typedef struct ]b4_api_PREFIX[LTYPE | |
c0828abf AD |
530 | { |
531 | int first_line; | |
532 | int first_column; | |
533 | int last_line; | |
534 | int last_column; | |
4b3847c3 | 535 | } ]b4_api_PREFIX[LTYPE; |
4b3847c3 AD |
536 | # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 |
537 | # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 | |
c0828abf | 538 | #endif]]) |
756257ee | 539 | |
4b3847c3 AD |
540 | b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval; |
541 | ]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl | |
c0828abf | 542 | ]) |
56ca3d8f | 543 | |
5f108727 | 544 | # b4_YYDEBUG_define |
56ca3d8f | 545 | # ------------------ |
5f108727 | 546 | m4_define([b4_YYDEBUG_define], |
56ca3d8f | 547 | [[/* Enabling traces. */ |
5f108727 AD |
548 | ]m4_if(b4_api_prefix, [yy], |
549 | [[#ifndef YYDEBUG | |
e436fa67 | 550 | # define YYDEBUG ]b4_parse_trace_if([1], [0])[ |
5f108727 AD |
551 | #endif]], |
552 | [[#ifndef ]b4_api_PREFIX[DEBUG | |
553 | # if defined YYDEBUG | |
56ca3d8f | 554 | #if YYDEBUG |
5f108727 AD |
555 | # define ]b4_api_PREFIX[DEBUG 1 |
556 | # else | |
557 | # define ]b4_api_PREFIX[DEBUG 0 | |
558 | # endif | |
559 | # else /* ! defined YYDEBUG */ | |
ccdc1577 | 560 | # define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[ |
5f108727 AD |
561 | # endif /* ! defined ]b4_api_PREFIX[DEBUG */ |
562 | #endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl | |
563 | ]) | |
564 | ||
565 | # b4_declare_yydebug | |
566 | # ------------------ | |
567 | m4_define([b4_declare_yydebug], | |
568 | [b4_YYDEBUG_define[ | |
569 | #if ]b4_api_PREFIX[DEBUG | |
56ca3d8f AD |
570 | extern int ]b4_prefix[debug; |
571 | #endif][]dnl | |
572 | ]) | |
426903aa AD |
573 | |
574 | # b4_yylloc_default_define | |
575 | # ------------------------ | |
576 | # Define YYLLOC_DEFAULT. | |
577 | m4_define([b4_yylloc_default_define], | |
578 | [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
579 | If N is 0, then set CURRENT to the empty location which ends | |
580 | the previous symbol: RHS[0] (always defined). */ | |
581 | ||
582 | #ifndef YYLLOC_DEFAULT | |
583 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
584 | do \ | |
585 | if (YYID (N)) \ | |
586 | { \ | |
587 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ | |
588 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ | |
589 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ | |
590 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ | |
591 | } \ | |
592 | else \ | |
593 | { \ | |
594 | (Current).first_line = (Current).last_line = \ | |
595 | YYRHSLOC (Rhs, 0).last_line; \ | |
596 | (Current).first_column = (Current).last_column = \ | |
597 | YYRHSLOC (Rhs, 0).last_column; \ | |
598 | } \ | |
599 | while (YYID (0)) | |
600 | #endif | |
601 | ]]) |