mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
traces: show the stack after reading a token
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.
This commit is contained in:
@@ -854,6 +854,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
`-----------------------------------------------*/
|
`-----------------------------------------------*/
|
||||||
yynewstate:
|
yynewstate:
|
||||||
YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n';
|
YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n';
|
||||||
|
YY_STACK_PRINT ();
|
||||||
|
|
||||||
// Accept?
|
// Accept?
|
||||||
if (yystack_[0].state == yyfinal_)
|
if (yystack_[0].state == yyfinal_)
|
||||||
|
|||||||
@@ -476,7 +476,9 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
/* New state. Unlike in the C/C++ skeletons, the state is already
|
/* New state. Unlike in the C/C++ skeletons, the state is already
|
||||||
pushed when we come here. */
|
pushed when we come here. */
|
||||||
case YYNEWSTATE:]b4_parse_trace_if([[
|
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? */
|
/* Accept? */
|
||||||
if (yystate == yyfinal_)
|
if (yystate == yyfinal_)
|
||||||
|
|||||||
@@ -1596,6 +1596,7 @@ yysetstate:
|
|||||||
YY_IGNORE_USELESS_CAST_BEGIN
|
YY_IGNORE_USELESS_CAST_BEGIN
|
||||||
*yyssp = YY_CAST (yy_state_t, yystate);
|
*yyssp = YY_CAST (yy_state_t, yystate);
|
||||||
YY_IGNORE_USELESS_CAST_END
|
YY_IGNORE_USELESS_CAST_END
|
||||||
|
YY_STACK_PRINT (yyss, yyssp);
|
||||||
|
|
||||||
if (yyss + yystacksize - 1 <= yyssp)
|
if (yyss + yystacksize - 1 <= yyssp)
|
||||||
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
|
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ input:
|
|||||||
|
|
||||||
line:
|
line:
|
||||||
'\n'
|
'\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); }
|
| expr '\n' { printf ("%.10g\n", $1); }
|
||||||
| error '\n' { yyerrok; }
|
| error '\n' { yyerrok; }
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1123,22 +1123,27 @@ AT_PARSER_CHECK([input --debug], 1,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'a' (1.1: <> printer for 'a' @ 1)
|
Next token is token 'a' (1.1: <> printer for 'a' @ 1)
|
||||||
Shifting token 'a' (1.1: <> printer for 'a' @ 1)
|
Shifting token 'a' (1.1: <> printer for 'a' @ 1)
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||||
Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 1 3
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||||
Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 1 3 5
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'd' (1.4: <> printer for 'd' @ 4)
|
Next token is token 'd' (1.4: <> printer for 'd' @ 4)
|
||||||
Shifting token 'd' (1.4: <> printer for 'd' @ 4)
|
Shifting token 'd' (1.4: <> printer for 'd' @ 4)
|
||||||
Entering state 6
|
Entering state 6
|
||||||
|
Stack now 0 1 3 5 6
|
||||||
Reading a token
|
Reading a token
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
1.5: syntax error, unexpected $end, expecting 'e'
|
1.5: syntax error, unexpected $end, expecting 'e'
|
||||||
@@ -1237,30 +1242,37 @@ AT_PARSER_CHECK([input --debug], 1,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'a' (<*>/<field2>/e printer)
|
Next token is token 'a' (<*>/<field2>/e printer)
|
||||||
Shifting token 'a' (<*>/<field2>/e printer)
|
Shifting token 'a' (<*>/<field2>/e printer)
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'b' (<field1> printer)
|
Next token is token 'b' (<field1> printer)
|
||||||
Shifting token 'b' (<field1> printer)
|
Shifting token 'b' (<field1> printer)
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 1 3
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'c' ('c' printer)
|
Next token is token 'c' ('c' printer)
|
||||||
Shifting token 'c' ('c' printer)
|
Shifting token 'c' ('c' printer)
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 1 3 5
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'd' ('d' printer)
|
Next token is token 'd' ('d' printer)
|
||||||
Shifting token 'd' ('d' printer)
|
Shifting token 'd' ('d' printer)
|
||||||
Entering state 6
|
Entering state 6
|
||||||
|
Stack now 0 1 3 5 6
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'e' (<*>/<field2>/e printer)
|
Next token is token 'e' (<*>/<field2>/e printer)
|
||||||
Shifting token 'e' (<*>/<field2>/e printer)
|
Shifting token 'e' (<*>/<field2>/e printer)
|
||||||
Entering state 7
|
Entering state 7
|
||||||
|
Stack now 0 1 3 5 6 7
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'f' (<*>/<field2>/e printer)
|
Next token is token 'f' (<*>/<field2>/e printer)
|
||||||
Shifting token 'f' (<*>/<field2>/e printer)
|
Shifting token 'f' (<*>/<field2>/e printer)
|
||||||
Entering state 8
|
Entering state 8
|
||||||
|
Stack now 0 1 3 5 6 7 8
|
||||||
Reading a token
|
Reading a token
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
syntax error, unexpected $end, expecting 'g'
|
syntax error, unexpected $end, expecting 'g'
|
||||||
@@ -1370,15 +1382,18 @@ AT_PARSER_CHECK([input$1 --debug], 0,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reducing stack by rule 1 (line 49):
|
Reducing stack by rule 1 (line 49):
|
||||||
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reading a token
|
Reading a token
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
|
Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
|
||||||
Entering state 2
|
Entering state 2
|
||||||
Stack now 0 1 2
|
Stack now 0 1 2
|
||||||
|
Stack now 0 1 2
|
||||||
Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
|
Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
|
||||||
Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||||
]])
|
]])
|
||||||
@@ -1453,18 +1468,22 @@ AT_COMPILE([input])
|
|||||||
AT_PARSER_CHECK([input --debug], [1], [],
|
AT_PARSER_CHECK([input --debug], [1], [],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'a' ('a')
|
Next token is token 'a' ('a')
|
||||||
Shifting token 'a' ('a')
|
Shifting token 'a' ('a')
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'b' ('b')
|
Next token is token 'b' ('b')
|
||||||
syntax error
|
syntax error
|
||||||
Shifting token error ()
|
Shifting token error ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 1 3
|
||||||
Next token is token 'b' ('b')
|
Next token is token 'b' ('b')
|
||||||
Shifting token 'b' ('b')
|
Shifting token 'b' ('b')
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 1 3 5
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token $undefined ()
|
Next token is token $undefined ()
|
||||||
Error: popping token 'b' ('b')
|
Error: popping token 'b' ('b')
|
||||||
@@ -1474,12 +1493,14 @@ Error: popping token error ()
|
|||||||
Stack now 0 1
|
Stack now 0 1
|
||||||
Shifting token error ()
|
Shifting token error ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 1 3
|
||||||
Next token is token $undefined ()
|
Next token is token $undefined ()
|
||||||
Error: discarding token $undefined ()
|
Error: discarding token $undefined ()
|
||||||
Error: popping token error ()
|
Error: popping token error ()
|
||||||
Stack now 0 1
|
Stack now 0 1
|
||||||
Shifting token error ()
|
Shifting token error ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 1 3
|
||||||
Reading a token
|
Reading a token
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
Cleanup: discarding lookahead token $end ()
|
Cleanup: discarding lookahead token $end ()
|
||||||
@@ -1625,22 +1646,27 @@ AT_COMPILE([input])
|
|||||||
AT_PARSER_CHECK([input --debug], 1,,
|
AT_PARSER_CHECK([input --debug], 1,,
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reducing stack by rule 1 (line 30):
|
Reducing stack by rule 1 (line 30):
|
||||||
-> $$ = nterm $@1 (: )
|
-> $$ = nterm $@1 (: )
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Entering state 2
|
Entering state 2
|
||||||
|
Stack now 0 2
|
||||||
Reducing stack by rule 2 (line 31):
|
Reducing stack by rule 2 (line 31):
|
||||||
-> $$ = nterm @2 (: 2)
|
-> $$ = nterm @2 (: 2)
|
||||||
Stack now 0 2
|
Stack now 0 2
|
||||||
Entering state 4
|
Entering state 4
|
||||||
|
Stack now 0 2 4
|
||||||
Reducing stack by rule 3 (line 32):
|
Reducing stack by rule 3 (line 32):
|
||||||
-> $$ = nterm @3 (: 3)
|
-> $$ = nterm @3 (: 3)
|
||||||
Stack now 0 2 4
|
Stack now 0 2 4
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 2 4 5
|
||||||
Reducing stack by rule 4 (line 33):
|
Reducing stack by rule 4 (line 33):
|
||||||
-> $$ = nterm @4 (: 4)
|
-> $$ = nterm @4 (: 4)
|
||||||
Stack now 0 2 4 5
|
Stack now 0 2 4 5
|
||||||
Entering state 6
|
Entering state 6
|
||||||
|
Stack now 0 2 4 5 6
|
||||||
Reading a token
|
Reading a token
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
syntax error
|
syntax error
|
||||||
|
|||||||
@@ -648,25 +648,30 @@ AT_FULL_COMPILE([[input]])
|
|||||||
AT_PARSER_CHECK([[input]], [[0]], [[]],
|
AT_PARSER_CHECK([[input]], [[0]], [[]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token NUMBER (1)
|
Next token is token NUMBER (1)
|
||||||
Shifting token NUMBER (1)
|
Shifting token NUMBER (1)
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reducing stack by rule 1 (line 34):
|
Reducing stack by rule 1 (line 34):
|
||||||
$1 = token NUMBER (1)
|
$1 = token NUMBER (1)
|
||||||
-> $$ = nterm expr (10)
|
-> $$ = nterm expr (10)
|
||||||
destroy: 1
|
destroy: 1
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Entering state 2
|
Entering state 2
|
||||||
|
Stack now 0 2
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token NUMBER (30)
|
Next token is token NUMBER (30)
|
||||||
Reducing stack by rule 2 (line 35):
|
Reducing stack by rule 2 (line 35):
|
||||||
-> $$ = nterm @1 (20)
|
-> $$ = nterm @1 (20)
|
||||||
Stack now 0 2
|
Stack now 0 2
|
||||||
Entering state 4
|
Entering state 4
|
||||||
|
Stack now 0 2 4
|
||||||
Next token is token NUMBER (30)
|
Next token is token NUMBER (30)
|
||||||
Shifting token NUMBER (30)
|
Shifting token NUMBER (30)
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 2 4 5
|
||||||
Reducing stack by rule 3 (line 35):
|
Reducing stack by rule 3 (line 35):
|
||||||
$1 = nterm expr (10)
|
$1 = nterm expr (10)
|
||||||
$2 = nterm @1 (20)
|
$2 = nterm @1 (20)
|
||||||
@@ -678,11 +683,13 @@ destroy: 20
|
|||||||
destroy: 10
|
destroy: 10
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Entering state 2
|
Entering state 2
|
||||||
|
Stack now 0 2
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token EOI ()
|
Next token is token EOI ()
|
||||||
Shifting token EOI ()
|
Shifting token EOI ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
Stack now 0 2 3
|
Stack now 0 2 3
|
||||||
|
Stack now 0 2 3
|
||||||
Cleanup: popping token EOI ()
|
Cleanup: popping token EOI ()
|
||||||
Cleanup: popping nterm expr (40)
|
Cleanup: popping nterm expr (40)
|
||||||
destroy: 40
|
destroy: 40
|
||||||
|
|||||||
@@ -922,7 +922,7 @@ _AT_CHECK_CALC([$1],
|
|||||||
2^2^3 = 256
|
2^2^3 = 256
|
||||||
(2^2)^3 = 64],
|
(2^2)^3 = 64],
|
||||||
[[final: 64 12 0]],
|
[[final: 64 12 0]],
|
||||||
[931])
|
[1111])
|
||||||
|
|
||||||
# Some syntax errors.
|
# Some syntax errors.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 2],
|
_AT_CHECK_CALC_ERROR([$1], [1], [1 2],
|
||||||
|
|||||||
@@ -960,10 +960,12 @@ AT_PARSER_CHECK([input --debug], 1,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reducing stack by rule 1 (line 20):
|
Reducing stack by rule 1 (line 20):
|
||||||
-> $$ = nterm start ()
|
-> $$ = nterm start ()
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token 'a' (PRINTER)
|
Next token is token 'a' (PRINTER)
|
||||||
syntax error, unexpected 'a', expecting $end
|
syntax error, unexpected 'a', expecting $end
|
||||||
@@ -1441,6 +1443,7 @@ AT_LAC_CHECK([])
|
|||||||
AT_PARSER_CHECK([[input --debug]], [[2]], [],
|
AT_PARSER_CHECK([[input --debug]], [[2]], [],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reading a token
|
Reading a token
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
LAC: initial context established for $end
|
LAC: initial context established for $end
|
||||||
@@ -1456,6 +1459,7 @@ AT_LAC_CHECK([z], [[0]])
|
|||||||
AT_PARSER_CHECK([[input --debug]], [[2]], [],
|
AT_PARSER_CHECK([[input --debug]], [[2]], [],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reading a token
|
Reading a token
|
||||||
Next token is token $undefined ()
|
Next token is token $undefined ()
|
||||||
LAC: initial context established for $undefined
|
LAC: initial context established for $undefined
|
||||||
|
|||||||
@@ -417,7 +417,6 @@ AT_DATA_GRAMMAR([input.y],
|
|||||||
%}
|
%}
|
||||||
]$2[
|
]$2[
|
||||||
%define parse.error verbose
|
%define parse.error verbose
|
||||||
%debug
|
|
||||||
%token WAIT_FOR_EOF
|
%token WAIT_FOR_EOF
|
||||||
%%
|
%%
|
||||||
exp: WAIT_FOR_EOF exp | ;
|
exp: WAIT_FOR_EOF exp | ;
|
||||||
@@ -457,7 +456,7 @@ main (int argc, const char **argv)
|
|||||||
int count;
|
int count;
|
||||||
]m4_bmatch([$2], [api.push-pull both],
|
]m4_bmatch([$2], [api.push-pull both],
|
||||||
[[ yypstate *ps = yypstate_new ();
|
[[ yypstate *ps = yypstate_new ();
|
||||||
]])[ yydebug = 1;
|
]])[
|
||||||
for (count = 0; count < 2; ++count)
|
for (count = 0; count < 2; ++count)
|
||||||
{
|
{
|
||||||
int new_status;
|
int new_status;
|
||||||
|
|||||||
Reference in New Issue
Block a user