d, java: use traces more alike that of C

Same order, same places, same content.

* data/skeletons/lalr1.d, data/skeletons/lalr1.java: here.
This commit is contained in:
Akim Demaille
2020-01-14 07:27:41 +01:00
parent 187c2ac344
commit c894a6e2ce
2 changed files with 26 additions and 11 deletions

View File

@@ -261,6 +261,11 @@ b4_user_union_members
public final void setDebugLevel(int level) { yydebug = level; } public final void setDebugLevel(int level) { yydebug = level; }
protected final void yycdebug (string s) { protected final void yycdebug (string s) {
if (0 < yydebug)
yyDebugStream.write (s);
}
protected final void yycdebugln (string s) {
if (0 < yydebug) if (0 < yydebug)
yyDebugStream.writeln (s); yyDebugStream.writeln (s);
} }
@@ -339,6 +344,9 @@ b4_user_union_members
yystack.pop (yylen); yystack.pop (yylen);
yylen = 0; yylen = 0;
]b4_parse_trace_if([[
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
/* Shift the result of the reduction. */ /* Shift the result of the reduction. */
yyn = yyr1_[yyn]; yyn = yyr1_[yyn];
@@ -407,7 +415,7 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
else else
message ~= format ("%s", &yyvaluep); message ~= format ("%s", &yyvaluep);
message ~= ")"; message ~= ")";
yycdebug (message); yycdebugln (message);
} }
} }
]])[ ]])[
@@ -445,9 +453,9 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
/// Semantic value of the lookahead. /// Semantic value of the lookahead.
]b4_yystype[ yylval; ]b4_yystype[ yylval;
int yyresult;]b4_parse_trace_if([[ bool yyresult;]b4_parse_trace_if([[
yycdebug ("Starting parse\n");]])[ yycdebugln ("Starting parse");]])[
yyerrstatus_ = 0; yyerrstatus_ = 0;
]m4_ifdef([b4_initial_action], [ ]m4_ifdef([b4_initial_action], [
@@ -468,9 +476,7 @@ 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([[
yycdebug (format("Entering state %d\n", yystate)); yycdebugln (format("Entering state %d", yystate));]])[
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
/* Accept? */ /* Accept? */
if (yystate == yyfinal_) if (yystate == yyfinal_)
@@ -655,11 +661,20 @@ m4_popdef([b4_at_dollar])])dnl
/* Accept. */ /* Accept. */
case YYACCEPT: case YYACCEPT:
return true; yyresult = true;
label = YYRETURN;
break;
/* Abort. */ /* Abort. */
case YYABORT: case YYABORT:
return false; yyresult = false;
label = YYRETURN;
break;
case YYRETURN:]b4_parse_trace_if([[
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
return yyresult;
} }
} }
@@ -788,8 +803,8 @@ m4_popdef([b4_at_dollar])])dnl
int yylno = yyrline_[yyrule]; int yylno = yyrline_[yyrule];
int yynrhs = yyr2_[yyrule]; int yynrhs = yyr2_[yyrule];
/* Print the symbols being reduced, and their result. */ /* Print the symbols being reduced, and their result. */
yycdebug (format("Reducing stack by rule %d (line %d), ", yycdebugln (format("Reducing stack by rule %d (line %d):",
yyrule - 1, yylno)); yyrule - 1, yylno));
/* The symbols being reduced. */ /* The symbols being reduced. */
for (int yyi = 0; yyi < yynrhs; yyi++) for (int yyi = 0; yyi < yynrhs; yyi++)

View File

@@ -996,7 +996,7 @@ b4_dollar_popdef[]dnl
int yynrhs = yyr2_[yyrule]; int yynrhs = yyr2_[yyrule];
/* Print the symbols being reduced, and their result. */ /* Print the symbols being reduced, and their result. */
yycdebug ("Reducing stack by rule " + (yyrule - 1) yycdebug ("Reducing stack by rule " + (yyrule - 1)
+ " (line " + yylno + "), "); + " (line " + yylno + "):");
/* The symbols being reduced. */ /* The symbols being reduced. */
for (int yyi = 0; yyi < yynrhs; yyi++) for (int yyi = 0; yyi < yynrhs; yyi++)