]> git.saurik.com Git - bison.git/blobdiff - src/parse-gram.y
* src/parse-gram.y (add_param): Strip the leading and trailing
[bison.git] / src / parse-gram.y
index 642a97ccb750f63a7d782f829b7239cb61857525..40117c53ec508ebffedbbbac489f5e64ffc923e7 100644 (file)
@@ -1,6 +1,6 @@
-/* Bison Grammar Parser                             -*- C -*-
+%{/* Bison Grammar Parser                             -*- C -*-
 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
    02111-1307  USA
 */
 
-
-%debug
-%defines
-%locations
-%pure-parser
-%error-verbose
-%defines
-%name-prefix="gram_"
-
-%{
 #include "system.h"
 
 #include "complain.h"
@@ -45,6 +35,9 @@
 #define YYLLOC_DEFAULT(Current, Rhs, N)  (Current) = lloc_default (Rhs, N)
 static YYLTYPE lloc_default (YYLTYPE const *, int);
 
+#define YY_LOCATION_PRINT(File, Loc) \
+          location_print (File, Loc)
+
 /* Request detailed syntax error messages, and pass them to GRAM_ERROR.
    FIXME: depends on the undocumented availability of YYLLOC.  */
 #undef  yyerror
@@ -66,6 +59,14 @@ assoc current_assoc;
 int current_prec = 0;
 %}
 
+%debug
+%defines
+%locations
+%pure-parser
+%error-verbose
+%defines
+%name-prefix="gram_"
+
 %initial-action
 {
   /* Bison's grammar can initial empty locations, hence a default
@@ -120,12 +121,14 @@ int current_prec = 0;
   PERCENT_DEFINES         "%defines"
   PERCENT_ERROR_VERBOSE   "%error-verbose"
   PERCENT_EXPECT          "%expect"
+  PERCENT_EXPECT_RR      "%expect-rr"
   PERCENT_FILE_PREFIX     "%file-prefix"
   PERCENT_GLR_PARSER      "%glr-parser"
   PERCENT_INITIAL_ACTION  "%initial-action {...}"
   PERCENT_LEX_PARAM       "%lex-param {...}"
   PERCENT_LOCATIONS       "%locations"
   PERCENT_NAME_PREFIX     "%name-prefix"
+  PERCENT_NO_DEFAULT_PREC "%no-default-prec"
   PERCENT_NO_LINES        "%no-lines"
   PERCENT_NONDETERMINISTIC_PARSER
                           "%nondeterministic-parser"
@@ -188,7 +191,8 @@ declaration:
 | "%define" string_content string_content  { muscle_insert ($2, $3); }
 | "%defines"                               { defines_flag = true; }
 | "%error-verbose"                         { error_verbose = true; }
-| "%expect" INT                            { expected_conflicts = $2; }
+| "%expect" INT                            { expected_sr_conflicts = $2; }
+| "%expect-rr" INT                        { expected_rr_conflicts = $2; }
 | "%file-prefix" "=" string_content        { spec_file_prefix = $3; }
 | "%glr-parser"
   {
@@ -241,12 +245,13 @@ grammar_declaration:
        symbol_printer_set (list->sym, $1, list->location);
       symbol_list_free ($2);
     }
-| "%default-prec" INT
+| "%default-prec"
+    {
+      default_prec = true;
+    }
+| "%no-default-prec"
     {
-      if (0 <= $2 && $2 <= 1)
-       default_prec = $2;
-      else
-       complain_at (@1, _("invalid value for `%default-prec'"));
+      default_prec = false;
     }
 ;
 
@@ -441,7 +446,11 @@ lloc_default (YYLTYPE const *rhs, int n)
 {
   int i;
   YYLTYPE loc;
-  loc.start = loc.end = rhs[n].end;
+
+  /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
+     The bug is fixed in 7.4.2m, but play it safe for now.  */
+  loc.start = rhs[n].end;
+  loc.end = rhs[n].end;
 
   /* Ignore empty nonterminals the start of the the right-hand side.
      Do not bother to ignore them at the end of the right-hand side,
@@ -468,6 +477,7 @@ add_param (char const *type, char *decl, location loc)
     "abcdefghijklmnopqrstuvwxyz"
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     "_";
+  static char const blank[] = " \t";
   char const *alpha = alphanum + 10;
   char const *name_start = NULL;
   char *p;
@@ -478,7 +488,13 @@ add_param (char const *type, char *decl, location loc)
 
   /* Strip the surrounding '{' and '}'.  */
   decl++;
-  p[-1] = '\0';
+  *--p = '\0';
+
+  /* Strip surrounding white spaces.  */
+  while (strchr (blank, *decl))
+    ++decl;
+  while (strchr (blank, p[-1]))
+    *--p = '\0';
 
   if (! name_start)
     complain_at (loc, _("missing identifier in parameter declaration"));