summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2021-01-06 19:22:18 +0100
committerAkim Demaille <akim.demaille@gmail.com>2021-01-07 06:31:28 +0100
commitf8594626580382f88f2767c55dfa42b6f8e8a799 (patch)
tree6658c69abb257bf4e69a155d9b1771a3f3efbf1b /examples
parentdc8b16424a89297368dbc66c69787ed0882966f0 (diff)
downloadbison-f8594626580382f88f2767c55dfa42b6f8e8a799.tar.gz
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.
Diffstat (limited to 'examples')
-rw-r--r--examples/d/calc/calc.y5
1 files changed, 5 insertions, 0 deletions
diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y
index 572b10b6..765ba382 100644
--- a/examples/d/calc/calc.y
+++ b/examples/d/calc/calc.y
@@ -21,6 +21,7 @@
%define api.parser.class {Calc}
%define parse.error verbose
+%define parse.trace
%locations
@@ -38,6 +39,7 @@
EOL "end of line"
%token <ival> NUM "number"
%type <ival> exp
+%printer { yyo.write($$); } <ival>
%left "-" "+"
%left "*" "/"
@@ -168,6 +170,9 @@ int main()
{
auto l = calcLexer(stdin);
auto p = new Calc(l);
+ import core.stdc.stdlib : getenv;
+ if (getenv("YYDEBUG"))
+ p.setDebugLevel(1);
p.parse();
return l.exit_status;
}