bison-patches
[Top][All Lists]
Advanced

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

yacc: support parse.assert


From: Akim Demaille
Subject: yacc: support parse.assert
Date: Tue, 12 Feb 2019 06:22:44 +0100

I'm not entirely sure I want to leave the YY_ASSERT use when parse.assert is 
not set.  Opinions?

commit e42a7a1862e92d4cd69aa54e394128b601339996
Author: Akim Demaille <address@hidden>
Date:   Sun Feb 10 19:28:26 2019 +0100

    yacc: support parse.assert
    
    While hacking on the computation of the automaton, I had yystate being
    equal to -1, and the parser loops.  Let's catch this when
    parser.assert is enabled.
    
    * data/skeletons/yacc.c (YY_ASSERT): New.
    Use it.
    Not using the name YYASSERT, to make it clear that this is private.
    glr.c should probably move to YY_ASSERT too.
    Also, while at it, report 'Entering state...' even before growing the
    stacks.

diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 54e40e67..34e18618 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -411,6 +411,15 @@ typedef short yytype_int16;
 
 ]b4_attribute_define[
 
+]b4_parse_assert_if([[#ifdef NDEBUG
+# define YY_ASSERT(E) ((void) (0 && (E)))
+#else
+# include <assert.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_ASSERT(E) assert (E)
+#endif
+]],
+[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[
+
 #if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[
 
 /* The parser invokes alloca or malloc; define the necessary symbols.  */]dnl
@@ -1453,6 +1462,8 @@ yynewstate:
 | yynewstate -- set current state (the top of the stack) to yystate.  |
 `--------------------------------------------------------------------*/
 yysetstate:
+  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
   *yyssp = (yytype_int16) yystate;
 
   if (yyss + yystacksize - 1 <= yyssp)
@@ -1520,8 +1531,6 @@ yysetstate:
     }
 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
 
-  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
   if (yystate == YYFINAL)
     YYACCEPT;
 




reply via email to

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