bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 02/13] traces: show the stack after reading a token


From: Akim Demaille
Subject: [PATCH 02/13] traces: show the stack after reading a token
Date: Wed, 5 Feb 2020 18:04:54 +0100

Currently, if we have long rules and series of shift, we stack states
without showing stack.  Let's be more incremental, and do how the Java
skeleton does.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/yacc.c:
Here.
Adjust test cases.
* tests/torture.at (AT_DATA_STACK_TORTURE): Disable stack traces: this
test produces a very large stack, and showing the stack each time we
shift a token goes quadatric.
---
 data/skeletons/lalr1.cc |  1 +
 data/skeletons/lalr1.d  |  4 +++-
 data/skeletons/yacc.c   |  1 +
 examples/c/calc/calc.y  |  1 +
 tests/actions.at        | 26 ++++++++++++++++++++++++++
 tests/c++.at            |  7 +++++++
 tests/calc.at           |  2 +-
 tests/regression.at     |  4 ++++
 tests/torture.at        |  3 +--
 9 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 80a2ad4b..7e080ec0 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -854,6 +854,7 @@ b4_dollar_popdef])[]dnl
   `-----------------------------------------------*/
   yynewstate:
     YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n';
+    YY_STACK_PRINT ();
 
     // Accept?
     if (yystack_[0].state == yyfinal_)
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 9eb71958..1b4fda0e 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -476,7 +476,9 @@ m4_popdef([b4_at_dollar])])dnl
         /* New state.  Unlike in the C/C++ skeletons, the state is already
            pushed when we come here.  */
       case YYNEWSTATE:]b4_parse_trace_if([[
-        yycdebugln (format("Entering state %d", yystate));]])[
+        yycdebugln (format("Entering state %d", yystate));
+        if (0 < yydebug)
+          yystack.print (yyDebugStream);]])[
 
         /* Accept?  */
         if (yystate == yyfinal_)
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 6c7c0732..72e6cd47 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1596,6 +1596,7 @@ yysetstate:
   YY_IGNORE_USELESS_CAST_BEGIN
   *yyssp = YY_CAST (yy_state_t, yystate);
   YY_IGNORE_USELESS_CAST_END
+  YY_STACK_PRINT (yyss, yyssp);
 
   if (yyss + yystacksize - 1 <= yyssp)
 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
diff --git a/examples/c/calc/calc.y b/examples/c/calc/calc.y
index 7757648d..1a6980fe 100644
--- a/examples/c/calc/calc.y
+++ b/examples/c/calc/calc.y
@@ -34,6 +34,7 @@ input:
 
 line:
   '\n'
+  | 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' 'a' { printf 
("a\n"); }
 | expr '\n'  { printf ("%.10g\n", $1); }
 | error '\n' { yyerrok; }
 ;
diff --git a/tests/actions.at b/tests/actions.at
index e0e325e4..a5796e5d 100644
--- a/tests/actions.at
+++ b/tests/actions.at
@@ -1123,22 +1123,27 @@ AT_PARSER_CHECK([input --debug], 1,
 ]],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reading a token
 Next token is token 'a' (1.1: <> printer for 'a' @ 1)
 Shifting token 'a' (1.1: <> printer for 'a' @ 1)
 Entering state 1
+Stack now 0 1
 Reading a token
 Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
 Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
 Entering state 3
+Stack now 0 1 3
 Reading a token
 Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
 Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
 Entering state 5
+Stack now 0 1 3 5
 Reading a token
 Next token is token 'd' (1.4: <> printer for 'd' @ 4)
 Shifting token 'd' (1.4: <> printer for 'd' @ 4)
 Entering state 6
+Stack now 0 1 3 5 6
 Reading a token
 Now at end of input.
 1.5: syntax error, unexpected $end, expecting 'e'
@@ -1237,30 +1242,37 @@ AT_PARSER_CHECK([input --debug], 1,
 ]],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reading a token
 Next token is token 'a' (<*>/<field2>/e printer)
 Shifting token 'a' (<*>/<field2>/e printer)
 Entering state 1
+Stack now 0 1
 Reading a token
 Next token is token 'b' (<field1> printer)
 Shifting token 'b' (<field1> printer)
 Entering state 3
+Stack now 0 1 3
 Reading a token
 Next token is token 'c' ('c' printer)
 Shifting token 'c' ('c' printer)
 Entering state 5
+Stack now 0 1 3 5
 Reading a token
 Next token is token 'd' ('d' printer)
 Shifting token 'd' ('d' printer)
 Entering state 6
+Stack now 0 1 3 5 6
 Reading a token
 Next token is token 'e' (<*>/<field2>/e printer)
 Shifting token 'e' (<*>/<field2>/e printer)
 Entering state 7
+Stack now 0 1 3 5 6 7
 Reading a token
 Next token is token 'f' (<*>/<field2>/e printer)
 Shifting token 'f' (<*>/<field2>/e printer)
 Entering state 8
+Stack now 0 1 3 5 6 7 8
 Reading a token
 Now at end of input.
 syntax error, unexpected $end, expecting 'g'
@@ -1370,15 +1382,18 @@ AT_PARSER_CHECK([input$1 --debug], 0,
 ]],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reducing stack by rule 1 (line 49):
 -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
 Stack now 0
 Entering state 1
+Stack now 0 1
 Reading a token
 Now at end of input.
 Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
 Entering state 2
 Stack now 0 1 2
+Stack now 0 1 2
 Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
 Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
 ]])
@@ -1453,18 +1468,22 @@ AT_COMPILE([input])
 AT_PARSER_CHECK([input --debug], [1], [],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reading a token
 Next token is token 'a' ('a')
 Shifting token 'a' ('a')
 Entering state 1
+Stack now 0 1
 Reading a token
 Next token is token 'b' ('b')
 syntax error
 Shifting token error ()
 Entering state 3
+Stack now 0 1 3
 Next token is token 'b' ('b')
 Shifting token 'b' ('b')
 Entering state 5
+Stack now 0 1 3 5
 Reading a token
 Next token is token $undefined ()
 Error: popping token 'b' ('b')
@@ -1474,12 +1493,14 @@ Error: popping token error ()
 Stack now 0 1
 Shifting token error ()
 Entering state 3
+Stack now 0 1 3
 Next token is token $undefined ()
 Error: discarding token $undefined ()
 Error: popping token error ()
 Stack now 0 1
 Shifting token error ()
 Entering state 3
+Stack now 0 1 3
 Reading a token
 Now at end of input.
 Cleanup: discarding lookahead token $end ()
@@ -1625,22 +1646,27 @@ AT_COMPILE([input])
 AT_PARSER_CHECK([input --debug], 1,,
 [[Starting parse
 Entering state 0
+Stack now 0
 Reducing stack by rule 1 (line 30):
 -> $$ = nterm $@1 (: )
 Stack now 0
 Entering state 2
+Stack now 0 2
 Reducing stack by rule 2 (line 31):
 -> $$ = nterm @2 (: 2)
 Stack now 0 2
 Entering state 4
+Stack now 0 2 4
 Reducing stack by rule 3 (line 32):
 -> $$ = nterm @3 (: 3)
 Stack now 0 2 4
 Entering state 5
+Stack now 0 2 4 5
 Reducing stack by rule 4 (line 33):
 -> $$ = nterm @4 (: 4)
 Stack now 0 2 4 5
 Entering state 6
+Stack now 0 2 4 5 6
 Reading a token
 Now at end of input.
 syntax error
diff --git a/tests/c++.at b/tests/c++.at
index 52b959fb..c87adc1e 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -648,25 +648,30 @@ AT_FULL_COMPILE([[input]])
 AT_PARSER_CHECK([[input]], [[0]], [[]],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reading a token
 Next token is token NUMBER (1)
 Shifting token NUMBER (1)
 Entering state 1
+Stack now 0 1
 Reducing stack by rule 1 (line 34):
    $1 = token NUMBER (1)
 -> $$ = nterm expr (10)
 destroy: 1
 Stack now 0
 Entering state 2
+Stack now 0 2
 Reading a token
 Next token is token NUMBER (30)
 Reducing stack by rule 2 (line 35):
 -> $$ = nterm @1 (20)
 Stack now 0 2
 Entering state 4
+Stack now 0 2 4
 Next token is token NUMBER (30)
 Shifting token NUMBER (30)
 Entering state 5
+Stack now 0 2 4 5
 Reducing stack by rule 3 (line 35):
    $1 = nterm expr (10)
    $2 = nterm @1 (20)
@@ -678,11 +683,13 @@ destroy: 20
 destroy: 10
 Stack now 0
 Entering state 2
+Stack now 0 2
 Reading a token
 Next token is token EOI ()
 Shifting token EOI ()
 Entering state 3
 Stack now 0 2 3
+Stack now 0 2 3
 Cleanup: popping token EOI ()
 Cleanup: popping nterm expr (40)
 destroy: 40
diff --git a/tests/calc.at b/tests/calc.at
index 1392d1bb..c46cccdc 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -922,7 +922,7 @@ _AT_CHECK_CALC([$1],
 2^2^3 = 256
 (2^2)^3 = 64],
 [[final: 64 12 0]],
-               [931])
+               [1111])
 
 # Some syntax errors.
 _AT_CHECK_CALC_ERROR([$1], [1], [1 2],
diff --git a/tests/regression.at b/tests/regression.at
index 9e52cd7e..240f33ae 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -960,10 +960,12 @@ AT_PARSER_CHECK([input --debug], 1,
 ]],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reducing stack by rule 1 (line 20):
 -> $$ = nterm start ()
 Stack now 0
 Entering state 1
+Stack now 0 1
 Reading a token
 Next token is token 'a' (PRINTER)
 syntax error, unexpected 'a', expecting $end
@@ -1441,6 +1443,7 @@ AT_LAC_CHECK([])
 AT_PARSER_CHECK([[input --debug]], [[2]], [],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reading a token
 Now at end of input.
 LAC: initial context established for $end
@@ -1456,6 +1459,7 @@ AT_LAC_CHECK([z], [[0]])
 AT_PARSER_CHECK([[input --debug]], [[2]], [],
 [[Starting parse
 Entering state 0
+Stack now 0
 Reading a token
 Next token is token $undefined ()
 LAC: initial context established for $undefined
diff --git a/tests/torture.at b/tests/torture.at
index 71adb2a0..245cac62 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -417,7 +417,6 @@ AT_DATA_GRAMMAR([input.y],
 %}
 ]$2[
 %define parse.error verbose
-%debug
 %token WAIT_FOR_EOF
 %%
 exp: WAIT_FOR_EOF exp | ;
@@ -457,7 +456,7 @@ main (int argc, const char **argv)
   int count;
 ]m4_bmatch([$2], [api.push-pull both],
 [[  yypstate *ps = yypstate_new ();
-]])[  yydebug = 1;
+]])[
   for (count = 0; count < 2; ++count)
     {
       int new_status;
-- 
2.25.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]