bison-patches
[Top][All Lists]
Advanced

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

[PATCH] yychar cannot be empty in yyerrlab.


From: Akim Demaille
Subject: [PATCH] yychar cannot be empty in yyerrlab.
Date: Tue, 11 Nov 2008 14:29:42 -0000

        * TODO (yychar == yyempty_): New.
        * data/lalr1.cc: Remove the handling of this case.
        This eases forthcoming changes related to yychar and yytranslate.
---
 ChangeLog     |    7 +++++++
 TODO          |   16 ++++++++++++++++
 data/lalr1.cc |   25 +++++++++++++------------
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 17023e2..e8e8ac2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-11-11  Akim Demaille  <address@hidden>
 
+       yychar cannot be empty in yyerrlab.
+       * TODO (yychar == yyempty_): New.
+       * data/lalr1.cc: Remove the handling of this case.
+       This eases forthcoming changes related to yychar and yytranslate.
+
+2008-11-11  Akim Demaille  <address@hidden>
+
        Bench: syntactic sugar for %define/#define.
        * etc/bench.pl.in (parse_dirs): Support %d and #d with arguments.
        (&bench_push_parser, bench_variant_parser): Use this feature.
diff --git a/TODO b/TODO
index 7b47309..918ca35 100644
--- a/TODO
+++ b/TODO
@@ -54,6 +54,22 @@ what it should look like.  For instance what follows crashes.
     return yyparse ();
   }
 
+** yychar == yyempty_
+The code in yyerrlab reads:
+
+      if (yychar <= YYEOF)
+       {
+         /* Return failure if at end of input.  */
+         if (yychar == YYEOF)
+           YYABORT;
+       }
+
+There are only two yychar that can be <= YYEOF: YYEMPTY and YYEOF.
+But I can't produce the situation where yychar is YYEMPTY here, is it
+really possible?  The test suite does not exercise this case.
+
+This shows that it would be interesting to manage to install skeleton
+coverage analysis to the test suite.
 
 * Header guards
 
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 4915caa..8c5b334 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -1281,18 +1281,19 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
     if (yyerrstatus_ == 3)
       {
        /* If just tried and failed to reuse lookahead token after an
-        error, discard it.  */
-
-       if (yychar <= yyeof_)
-         {
-            /* Return failure if at end of input.  */
-            if (yychar == yyeof_)
-              YYABORT;
-         }
-       else
-         {
-           yy_destroy_ ("Error: discarding", yyla);
-           yychar = yyempty_;
+           error, discard it.  */
+
+        /* Return failure if at end of input.  */
+        if (yychar == yyeof_)
+          YYABORT;
+        else
+          {]b4_assert_if([
+            // Previous version of this code was ready to handle
+            // yychar == yyempty_ (actually yychar <= yyeof_).  Can it
+            // really be triggered?
+            assert (yychar != yyempty_);])[
+            yy_destroy_ ("Error: discarding", yyla);
+            yychar = yyempty_;
          }
       }
 
-- 
1.6.0.2.588.g3102





reply via email to

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