]> git.saurik.com Git - bison.git/commitdiff
* data/bison.c++ (yy::b4_name::error_): New method, replaces yyerror in
authorRobert Anisko <robert@lrde.epita.fr>
Thu, 7 Feb 2002 11:35:40 +0000 (11:35 +0000)
committerRobert Anisko <robert@lrde.epita.fr>
Thu, 7 Feb 2002 11:35:40 +0000 (11:35 +0000)
C++ parsers.
(yy::b4_name::parse): Build verbose error messages, and use error_.

ChangeLog
data/bison.c++

index 30f36ac1710de9e2c3b2d713c4b7e3ee3953d880..15424ae5efd80ecf2e4793e78ca4a64a3ef28978 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-02-07  Robert Anisko  <robert@lrde.epita.fr>
+
+       * data/bison.c++ (yy::b4_name::error_): New method, replaces yyerror in
+       C++ parsers.
+       (yy::b4_name::parse): Build verbose error messages, and use error_.
+
 2002-02-06  Robert Anisko  <robert@lrde.epita.fr>
 
        * data/bison.c++: Fix m4 quoting in comments.
index e5c283dbb0def5bf15f1efadf27c45d90a212069..2d2e2ed9c5378caff11fb75aaa639258f9e84343 100644 (file)
@@ -80,11 +80,13 @@ namespace yy
 
   private:
 
+    virtual void error_ ();
+
     /* Call to lexical analyser.  */
-    virtual 
-    void 
-    lex () 
-    { 
+    virtual
+    void
+    lex ()
+    {
       looka = yylex (&value, &location);
     }
 
@@ -124,11 +126,14 @@ namespace yy
     int len;
     int debug_;
     int state;
-    
+
     /* Lookahead.  */
     int looka;
     int ilooka;
-    
+
+    /* Message.  */
+    std::string message;
+
     /* @$ and $$.  */
     SemanticType value;
     LocationType location;
@@ -169,6 +174,9 @@ b4_tokendef
 int
 yy::b4_name::parse ()
 {
+  int nerrs = 0;
+  int errstatus = 0;
+
   /* Initialize stack.  */
   state_stack = StateStack (0);
   semantic_stack = SemanticStack (1);
@@ -333,7 +341,39 @@ yy::b4_name::parse ()
 
   /* Report and recover from errors.  This is very incomplete.  */
  yyerrlab:
-  std::cerr << "Parse error." << std::endl; // FIXME: Need something like yyerror?
+  /* If not already recovering from an error, report this error.  */
+  if (!errstatus)
+    {
+      ++nerrs;
+      
+      // FIXME: Should be #if YYERROR_VERBOSE from here...
+      n = pact_[[state]];
+      if (n > b4_flag && n < b4_last)
+       {
+         message = "parse error, unexpected ";
+         message += name_[[ilooka]];
+         {
+           int count = 0;
+           for (int x = (n < 0 ? -n : 0); x < b4_ntokens + b4_nnts; ++x)
+             if (check_[[x + n]] == x)
+               ++count;
+           if (count < 5)
+             {
+               count = 0;
+               for (int x = (n < 0 ? -n : 0); x < b4_ntokens + b4_nnts; ++x)
+                 if (check_[[x + n]] == x)
+                   {
+                     message += (!count++) ? ", expecting " : " or "; 
+                     message += name_[[x]];
+                   }
+             }
+         }
+       }
+      else
+      // FIXME: to there...
+       message = "parse error";
+    }
+  error_ ();
   return 1;
   
   /* Accept.  */