d: add support for %printer

Currently we display the addresses of the semantic values.  Instead,
print the values.

Add support for YY_USE across languages.

* data/skeletons/c.m4, data/skeletons/d.m4 (b4_use): New.
* data/skeletons/bison.m4 (b4_symbol_actions): Use b4_use to be
portable to D.

Add support for %printer, and use it.

* data/skeletons/d.m4: Instead of duplicating what's already in
c-like.m4, include it.
(b4_symbol_action): New.
Differs from the one in bison.m4 in that it uses yyval/yyloc instead
of *yyvaluep and *yylocationp.

* data/skeletons/lalr1.d (yy_symbol_print): Avoid calls to formatting,
just call write directly.
Use the %printer.
* examples/d/calc/calc.y: Specify a printer.
Enable traces when $YYDEBUG is set.
* tests/calc.at: Fix the use of %printer with D.
This commit is contained in:
Akim Demaille
2021-01-06 19:22:18 +01:00
parent dc8b16424a
commit f859462658
6 changed files with 50 additions and 32 deletions

View File

@@ -163,13 +163,20 @@ m4_popdef([$2])dnl
m4_popdef([$1])dnl
])])
# b4_use(EXPR)
# ------------
# Pacify the compiler about some maybe unused value.
m4_define([b4_use],
[YY_USE ($1)])
# b4_parse_param_use([VAL], [LOC])
# --------------------------------
# 'YY_USE' VAL, LOC if locations are enabled, and all the parse-params.
m4_define([b4_parse_param_use],
[m4_ifvaln([$1], [ YY_USE ([$1]);])dnl
b4_locations_if([m4_ifvaln([$2], [ YY_USE ([$2]);])])dnl
b4_parse_param_for([Decl], [Formal], [ YY_USE (Formal);
[m4_ifvaln([$1], [ b4_use([$1]);])dnl
b4_locations_if([m4_ifvaln([$2], [ b4_use([$2]);])])dnl
b4_parse_param_for([Decl], [Formal], [ b4_use(Formal);
])dnl
])