Hi Lars, > Le 10 oct. 2019 à 23:56, Lars Maier <[email protected]> a écrit : > > Hi, > > I was debugging a GLR C parser and noticed that, while for the deterministic > LR parser the used rules come with line numbers, this is not true in > non-deterministic mode. > > > $ diff glr2.c bison-3.4.2/data/skeletons/glr.c > 1464c1464 > < "Reduced stack %lu by rule #%d (line %lu); action > deferred. " > --- > > "Reduced stack %lu by rule #%d; action deferred. " > 1466c1466 > < (unsigned long) yyk, yyrule - 1, (unsigned long) > yyrline[yyrule], yynewLRState)); > --- > > (unsigned long) yyk, yyrule - 1, yynewLRState)); > > > This is such a small change but might help others to debug their parsers.
You're right. I installed this. Thanks! commit 2c20ae9b418f4687d643d3d266ac4b123b29d744 Author: Akim Demaille <[email protected]> Date: Fri Oct 11 07:06:39 2019 +0200 glr: display line numbers in traces Suggested by Lars Maier. * data/skeletons/glr.c: Also display rule locations when rules are deferred, and rejected. diff --git a/THANKS b/THANKS index 569ba173..c29797e9 100644 --- a/THANKS +++ b/THANKS @@ -95,8 +95,9 @@ Kees Zeelenberg [email protected] Keith Browne [email protected] Ken Moffat [email protected] Kiyoshi Kanazawa [email protected] -Laurent Mascherpa [email protected] +Lars Maier [email protected] László Várady [email protected] +Laurent Mascherpa [email protected] Lie Yan [email protected] Magnus Fromreide [email protected] Marc Autret [email protected] diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c index af7a78c3..7184a35a 100644 --- a/data/skeletons/glr.c +++ b/data/skeletons/glr.c @@ -1442,8 +1442,9 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule, YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[); if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR) { - YYDPRINTF ((stderr, "Parse on stack %ld rejected by rule #%d.\n", - (long) yyk, yyrule - 1)); + YYDPRINTF ((stderr, + "Parse on stack %ld rejected by rule %d (line %d).\n", + (long) yyk, yyrule - 1, yyrline[yyrule - 1])); } if (yyflag != yyok) return yyflag; @@ -1469,9 +1470,9 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule, yyupdateSplit (yystackp, yys); yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); YYDPRINTF ((stderr, - "Reduced stack %ld by rule #%d; action deferred. " + "Reduced stack %ld by rule %d (line %d); action deferred. " "Now in state %d.\n", - (long) yyk, yyrule - 1, yynewLRState)); + (long) yyk, yyrule - 1, yyrline[yyrule - 1], yynewLRState)); for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR) { diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 1d4a5581..e6b8c01a 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -1711,10 +1711,10 @@ Reading a token: Now at end of input. Stack 0 Entering state 7 Now at end of input. Splitting off stack 1 from 0. -Reduced stack 1 by rule #2; action deferred. Now in state 2. +Reduced stack 1 by rule 2 (line 24); action deferred. Now in state 2. Stack 1 Entering state 2 Now at end of input. -Reduced stack 0 by rule #1; action deferred. Now in state 2. +Reduced stack 0 by rule 1 (line 24); action deferred. Now in state 2. Merging stack 0 into stack 1. Stack 1 Entering state 2 Now at end of input.
