traces: write the "Reading a token" alone on its line

The Java skeleton displays

    Reading a token:
    Next token is token "number" (1)

while the other display

    Reading a token: Next token is token "number" (1)

When generating logs in the scanner, the first part is separated from
the second, and the end of the scanner logs have the second part
pasted in.  So let's propagate the Java way, but with the colon.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Do it.
Adjust test cases and doc.
This commit is contained in:
Akim Demaille
2020-02-04 06:43:45 +01:00
parent fe14fb1c40
commit bba2f0a3a0
11 changed files with 85 additions and 47 deletions

View File

@@ -824,7 +824,7 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
]b4_parse_param_use()dnl ]b4_parse_param_use()dnl
[ if (*yycharp == YYEMPTY) [ if (*yycharp == YYEMPTY)
{ {
YY_DPRINTF ((stderr, "Reading a token: "));]b4_glr_cc_if([[ YY_DPRINTF ((stderr, "Reading a token\n"));]b4_glr_cc_if([[
#if YY_EXCEPTIONS #if YY_EXCEPTIONS
try try
{ {

View File

@@ -874,7 +874,7 @@ b4_dollar_popdef])[]dnl
// Read a lookahead token. // Read a lookahead token.
if (yyla.empty ()) if (yyla.empty ())
{ {
YYCDEBUG << "Reading a token: "; YYCDEBUG << "Reading a token\n";
#if YY_EXCEPTIONS #if YY_EXCEPTIONS
try try
#endif // YY_EXCEPTIONS #endif // YY_EXCEPTIONS

View File

@@ -493,7 +493,7 @@ m4_popdef([b4_at_dollar])])dnl
/* Read a lookahead token. */ /* Read a lookahead token. */
if (yychar == yyempty_) if (yychar == yyempty_)
{]b4_parse_trace_if([[ {]b4_parse_trace_if([[
yycdebug ("Reading a token: ");]])[ yycdebugln ("Reading a token");]])[
yychar = yylex ();]b4_locations_if([[ yychar = yylex ();]b4_locations_if([[
static if (yy_location_is_class) { static if (yy_location_is_class) {
yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos); yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos);

View File

@@ -586,7 +586,7 @@ b4_dollar_pushdef([yylval], [], [], [yylloc])dnl
b4_user_initial_action b4_user_initial_action
b4_dollar_popdef[]dnl b4_dollar_popdef[]dnl
])[]b4_parse_trace_if([[ ])[]b4_parse_trace_if([[
yycdebug ("Starting parse\n");]])[ yycdebug ("Starting parse");]])[
yyerrstatus_ = 0; yyerrstatus_ = 0;
} else } else
label = YYGETTOKEN; label = YYGETTOKEN;
@@ -624,12 +624,12 @@ b4_dollar_popdef[]dnl
]b4_push_if([[ ]b4_push_if([[
if (!push_token_consumed) if (!push_token_consumed)
return YYPUSH_MORE;]b4_parse_trace_if([[ return YYPUSH_MORE;]b4_parse_trace_if([[
yycdebug ("Reading a token: ");]])[ yycdebug ("Reading a token");]])[
yychar = yylextoken; yychar = yylextoken;
yylval = yylexval;]b4_locations_if([ yylval = yylexval;]b4_locations_if([
yylloc = yylexloc;])[ yylloc = yylexloc;])[
push_token_consumed = false;]], [b4_parse_trace_if([[ push_token_consumed = false;]], [b4_parse_trace_if([[
yycdebug ("Reading a token: ");]])[ yycdebug ("Reading a token");]])[
yychar = yylexer.yylex (); yychar = yylexer.yylex ();
yylval = yylexer.getLVal ();]b4_locations_if([ yylval = yylexer.getLVal ();]b4_locations_if([
yylloc = new b4_location_type (yylexer.getStartPos (), yylloc = new b4_location_type (yylexer.getStartPos (),

View File

@@ -1702,7 +1702,7 @@ yybackup:
yylval = yypushed_val;]b4_locations_if([[ yylval = yypushed_val;]b4_locations_if([[
yylloc = yypushed_loc;]])])[ yylloc = yypushed_loc;]])])[
yyread_pushed_token:]])[ yyread_pushed_token:]])[
YYDPRINTF ((stderr, "Reading a token: "));]b4_push_if([b4_pure_if([[ YYDPRINTF ((stderr, "Reading a token\n"));]b4_push_if([b4_pure_if([[
yychar = yypushed_char; yychar = yypushed_char;
if (yypushed_val) if (yypushed_val)
yylval = *yypushed_val;]b4_locations_if([[ yylval = *yypushed_val;]b4_locations_if([[

View File

@@ -10177,7 +10177,8 @@ a valueless (@samp{()}) @code{input} nonterminal (@code{nterm}).
Then the parser calls the scanner. Then the parser calls the scanner.
@example @example
Reading a token: Next token is token FUN (sin()) Reading a token
Next token is token FUN (sin())
Shifting token FUN (sin()) Shifting token FUN (sin())
Entering state 6 Entering state 6
@end example @end example
@@ -10189,10 +10190,12 @@ The parser stores (@code{Shifting}) that token, and others, until it can do
something about it. something about it.
@example @example
Reading a token: Next token is token '(' () Reading a token
Next token is token '(' ()
Shifting token '(' () Shifting token '(' ()
Entering state 14 Entering state 14
Reading a token: Next token is token NUM (1.000000) Reading a token
Next token is token NUM (1.000000)
Shifting token NUM (1.000000) Shifting token NUM (1.000000)
Entering state 4 Entering state 4
Reducing stack by rule 6 (line 44): Reducing stack by rule 6 (line 44):
@@ -10208,10 +10211,12 @@ The previous reduction demonstrates the @code{%printer} directive for
@code{exp} have @samp{1} as value. @code{exp} have @samp{1} as value.
@example @example
Reading a token: Next token is token '-' () Reading a token
Next token is token '-' ()
Shifting token '-' () Shifting token '-' ()
Entering state 17 Entering state 17
Reading a token: Next token is token NUM (1.000000) Reading a token
Next token is token NUM (1.000000)
Shifting token NUM (1.000000) Shifting token NUM (1.000000)
Entering state 4 Entering state 4
Reducing stack by rule 6 (line 44): Reducing stack by rule 6 (line 44):
@@ -10219,7 +10224,8 @@ Reducing stack by rule 6 (line 44):
-> $$ = nterm exp (1.000000) -> $$ = nterm exp (1.000000)
Stack now 0 1 6 14 24 17 Stack now 0 1 6 14 24 17
Entering state 26 Entering state 26
Reading a token: Next token is token ')' () Reading a token
Next token is token ')' ()
Reducing stack by rule 11 (line 49): Reducing stack by rule 11 (line 49):
$1 = nterm exp (1.000000) $1 = nterm exp (1.000000)
$2 = token '-' () $2 = token '-' ()
@@ -10252,7 +10258,8 @@ Finally, the end-of-line allow the parser to complete the computation, and
display its result. display its result.
@example @example
Reading a token: Next token is token '\n' () Reading a token
Next token is token '\n' ()
Shifting token '\n' () Shifting token '\n' ()
Entering state 22 Entering state 22
Reducing stack by rule 4 (line 40): Reducing stack by rule 4 (line 40):
@@ -10275,7 +10282,8 @@ expression to evaluate, or for the end-of-file token, which causes the
completion of the parsing. completion of the parsing.
@example @example
Reading a token: Now at end of input. Reading a token
Now at end of input.
Shifting token $end () Shifting token $end ()
Entering state 2 Entering state 2
Stack now 0 1 2 Stack now 0 1 2

View File

@@ -1123,19 +1123,24 @@ AT_PARSER_CHECK([input --debug], 1,
]], ]],
[[Starting parse [[Starting parse
Entering state 0 Entering state 0
Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1) Reading a token
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
Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2) 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) Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
Entering state 3 Entering state 3
Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 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) Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
Entering state 5 Entering state 5
Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4) Reading a token
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
Reading a token: Now at end of input. Reading a token
Now at end of input.
1.5: syntax error, unexpected $end, expecting 'e' 1.5: syntax error, unexpected $end, expecting 'e'
Error: popping token 'd' (1.4: <> printer for 'd' @ 4) Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
Stack now 0 1 3 5 Stack now 0 1 3 5
@@ -1232,25 +1237,32 @@ AT_PARSER_CHECK([input --debug], 1,
]], ]],
[[Starting parse [[Starting parse
Entering state 0 Entering state 0
Reading a token: Next token is token 'a' (<*>/<field2>/e printer) Reading a token
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
Reading a token: Next token is token 'b' (<field1> printer) Reading a token
Next token is token 'b' (<field1> printer)
Shifting token 'b' (<field1> printer) Shifting token 'b' (<field1> printer)
Entering state 3 Entering state 3
Reading a token: Next token is token 'c' ('c' printer) Reading a token
Next token is token 'c' ('c' printer)
Shifting token 'c' ('c' printer) Shifting token 'c' ('c' printer)
Entering state 5 Entering state 5
Reading a token: Next token is token 'd' ('d' printer) Reading a token
Next token is token 'd' ('d' printer)
Shifting token 'd' ('d' printer) Shifting token 'd' ('d' printer)
Entering state 6 Entering state 6
Reading a token: Next token is token 'e' (<*>/<field2>/e printer) Reading a token
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
Reading a token: Next token is token 'f' (<*>/<field2>/e printer) Reading a token
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
Reading a token: Now at end of input. Reading a token
Now at end of input.
syntax error, unexpected $end, expecting 'g' syntax error, unexpected $end, expecting 'g'
Error: popping token 'f' (<*>/<field2>/e printer) Error: popping token 'f' (<*>/<field2>/e printer)
Stack now 0 1 3 5 6 7 Stack now 0 1 3 5 6 7
@@ -1362,7 +1374,8 @@ 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
Reading a token: Now at end of input. Reading a token
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
@@ -1440,17 +1453,20 @@ 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
Reading a token: Next token is token 'a' ('a') Reading a token
Next token is token 'a' ('a')
Shifting token 'a' ('a') Shifting token 'a' ('a')
Entering state 1 Entering state 1
Reading a token: Next token is token 'b' ('b') Reading a token
Next token is token 'b' ('b')
syntax error syntax error
Shifting token error () Shifting token error ()
Entering state 3 Entering state 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
Reading a token: Next token is token $undefined () Reading a token
Next token is token $undefined ()
Error: popping token 'b' ('b') Error: popping token 'b' ('b')
DESTROY 'b' DESTROY 'b'
Stack now 0 1 3 Stack now 0 1 3
@@ -1464,7 +1480,8 @@ Error: popping token error ()
Stack now 0 1 Stack now 0 1
Shifting token error () Shifting token error ()
Entering state 3 Entering state 3
Reading a token: Now at end of input. Reading a token
Now at end of input.
Cleanup: discarding lookahead token $end () Cleanup: discarding lookahead token $end ()
Stack now 0 1 3 Stack now 0 1 3
Cleanup: popping token error () Cleanup: popping token error ()
@@ -1624,7 +1641,8 @@ 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
Reading a token: Now at end of input. Reading a token
Now at end of input.
syntax error syntax error
Error: popping nterm @4 (: 4) Error: popping nterm @4 (: 4)
DESTROY 4 DESTROY 4
@@ -1790,9 +1808,9 @@ AT_PARSER_CHECK([input --debug], 0, [], [stderr])
# Don't be too picky on the traces, GLR is not exactly the same. Keep # Don't be too picky on the traces, GLR is not exactly the same. Keep
# only the lines from the printer. # only the lines from the printer.
AT_CHECK([[sed -ne '/ival:/p' stderr]], 0, AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
[[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1) [[Next token is token UNTYPED (ival: 10, fval: 0.1)
Shifting token UNTYPED (ival: 10, fval: 0.1) Shifting token UNTYPED (ival: 10, fval: 0.1)
Reading a token: Next token is token INT (ival: 20, fval: 0.2) Next token is token INT (ival: 20, fval: 0.2)
Shifting token INT (ival: 20, fval: 0.2) Shifting token INT (ival: 20, fval: 0.2)
$][1 = token UNTYPED (ival: 10, fval: 0.1) $][1 = token UNTYPED (ival: 10, fval: 0.1)
$][2 = token INT (ival: 20, fval: 0.2) $][2 = token INT (ival: 20, fval: 0.2)

View File

@@ -648,7 +648,8 @@ AT_FULL_COMPILE([[input]])
AT_PARSER_CHECK([[input]], [[0]], [[]], AT_PARSER_CHECK([[input]], [[0]], [[]],
[[Starting parse [[Starting parse
Entering state 0 Entering state 0
Reading a token: Next token is token NUMBER (1) Reading a token
Next token is token NUMBER (1)
Shifting token NUMBER (1) Shifting token NUMBER (1)
Entering state 1 Entering state 1
Reducing stack by rule 1 (line 34): Reducing stack by rule 1 (line 34):
@@ -657,7 +658,8 @@ Reducing stack by rule 1 (line 34):
destroy: 1 destroy: 1
Stack now 0 Stack now 0
Entering state 2 Entering state 2
Reading a token: Next token is token NUMBER (30) Reading a token
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
@@ -676,7 +678,8 @@ destroy: 20
destroy: 10 destroy: 10
Stack now 0 Stack now 0
Entering state 2 Entering state 2
Reading a token: Next token is token EOI () Reading a token
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

View File

@@ -780,7 +780,9 @@ AT_JAVA_IF(
[AT_PARSER_CHECK([calc input], 0, [AT_PARAM_IF([m4_n([$3])])], [stderr])]) [AT_PARSER_CHECK([calc input], 0, [AT_PARAM_IF([m4_n([$3])])], [stderr])])
AT_LANG_MATCH([c\|c++], AT_LANG_MATCH([c\|c++],
[AT_GLR_IF([], [AT_GLR_IF([],
[AT_CHECK([cat stderr | wc -l], [0], [m4_n([AT_DEBUG_IF([$4], [0])])])])]) [AT_CHECK([grep -v 'Return for a new token:' stderr | wc -l],
[0],
[m4_n([AT_DEBUG_IF([$4], [0])])])])])
]) ])
@@ -920,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]],
[AT_PUSH_IF([930], [846])]) [931])
# Some syntax errors. # Some syntax errors.
_AT_CHECK_CALC_ERROR([$1], [1], [1 2], _AT_CHECK_CALC_ERROR([$1], [1], [1 2],

View File

@@ -1709,23 +1709,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
Reading a token: Next token is token 'a' () Reading a token
Next token is token 'a' ()
Shifting token 'a' () Shifting token 'a' ()
Entering state 1 Entering state 1
Reading a token: Next token is token 'b' () Reading a token
Next token is token 'b' ()
Shifting token 'b' () Shifting token 'b' ()
Entering state 3 Entering state 3
Reducing stack 0 by rule 3 (line 27): Reducing stack 0 by rule 3 (line 27):
$1 = token 'b' () $1 = token 'b' ()
-> $$ = nterm b () -> $$ = nterm b ()
Entering state 4 Entering state 4
Reading a token: Next token is token 'c' () Reading a token
Next token is token 'c' ()
Shifting token 'c' () Shifting token 'c' ()
Entering state 6 Entering state 6
Reducing stack 0 by rule 4 (line 28): Reducing stack 0 by rule 4 (line 28):
-> $$ = nterm d () -> $$ = nterm d ()
Entering state 7 Entering state 7
Reading a token: Now at end of input. Reading a token
Now at end of input.
Stack 0 Entering state 7 Stack 0 Entering state 7
Now at end of input. Now at end of input.
Splitting off stack 1 from 0. Splitting off stack 1 from 0.

View File

@@ -964,7 +964,8 @@ Reducing stack by rule 1 (line 20):
-> $$ = nterm start () -> $$ = nterm start ()
Stack now 0 Stack now 0
Entering state 1 Entering state 1
Reading a token: Next token is token 'a' (PRINTER) Reading a token
Next token is token 'a' (PRINTER)
syntax error, unexpected 'a', expecting $end syntax error, unexpected 'a', expecting $end
Error: popping nterm start () Error: popping nterm start ()
Stack now 0 Stack now 0
@@ -1440,7 +1441,8 @@ 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
Reading a token: Now at end of input. Reading a token
Now at end of input.
LAC: initial context established for $end LAC: initial context established for $end
LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded) LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
memory exhausted memory exhausted
@@ -1454,7 +1456,8 @@ 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
Reading a token: Next token is token $undefined () Reading a token
Next token is token $undefined ()
LAC: initial context established for $undefined LAC: initial context established for $undefined
LAC: checking lookahead $undefined: Always Err LAC: checking lookahead $undefined: Always Err
Constructing syntax error message Constructing syntax error message