]> git.saurik.com Git - bison.git/commitdiff
variables: accept dashes.
authorAkim Demaille <demaille@gostai.com>
Mon, 20 Apr 2009 10:24:23 +0000 (12:24 +0200)
committerJoel E. Denny <jdenny@ces.clemson.edu>
Wed, 29 Apr 2009 22:50:12 +0000 (18:50 -0400)
* src/scan-gram.l ({id}): Also accept dashes after the initial
letter.
({directive}): Use {id}.
* src/parse-gram.y: Comment and formatting changes.
* doc/bison.texinfo (Symbols): Adjust the lexical definitions of
symbols.
* src/complain.h, src/complain.c (yacc_at): New.
* src/symtab.c (symbol_new): Use yacc_at to report inappropriate
symbol names.
* src/output.c (token_definitions_output): Do not #define token
names with dashes.
(cherry picked from commit 4f646c3794c45940aaf96d5409eff02a2c74978e)

Conflicts:

data/bison.m4
src/parse-gram.y

ChangeLog
doc/bison.texinfo
src/complain.c
src/complain.h
src/output.c
src/parse-gram.c
src/parse-gram.h
src/parse-gram.y
src/scan-gram.l
src/symtab.c

index b42a91d0c4f660a6374e43ac9b2eb08b6d479f0a..69edc6bdcd6971ad3365d095d867c909291a55f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-04-20  Akim Demaille  <demaille@gostai.com>
+
+       variables: accept dashes.
+       * src/scan-gram.l ({id}): Also accept dashes after the initial
+       letter.
+       ({directive}): Use {id}.
+       * src/parse-gram.y: Comment and formatting changes.
+       * doc/bison.texinfo (Symbols): Adjust the lexical definitions of
+       symbols.
+       * src/complain.h, src/complain.c (yacc_at): New.
+       * src/symtab.c (symbol_new): Use yacc_at to report inappropriate
+       symbol names.
+       * src/output.c (token_definitions_output): Do not #define token
+       names with dashes.
+
 2009-04-24  Joel E. Denny  <jdenny@ces.clemson.edu>
 
        Clean up recent patches a little.
 2009-04-24  Joel E. Denny  <jdenny@ces.clemson.edu>
 
        Clean up recent patches a little.
index c52d7b8a14da96773d561265f3024bd12659f3d2..46c95f01c1ac1b9e792f0b767b343901af4f7e6a 100644 (file)
@@ -3051,8 +3051,12 @@ A @dfn{nonterminal symbol} stands for a class of syntactically
 equivalent groupings.  The symbol name is used in writing grammar rules.
 By convention, it should be all lower case.
 
 equivalent groupings.  The symbol name is used in writing grammar rules.
 By convention, it should be all lower case.
 
-Symbol names can contain letters, digits (not at the beginning),
-underscores and periods.  Periods make sense only in nonterminals.
+Symbol names can contain letters, underscores, period, and (not at the
+beginning) digits and dashes.  Dashes in symbol names are a GNU
+extension, incompatible with @acronym{POSIX} Yacc.  Terminal symbols
+that contain periods or dashes make little sense: since they are not
+valid symbols (in most programming languages) they are not exported as
+token names.
 
 There are three ways of writing terminal symbols in the grammar:
 
 
 There are three ways of writing terminal symbols in the grammar:
 
index 2c26c4e45e445388cdb73590309abd2eb65c4d45..4cc35c8a9506768cafed48fddc37dfaba97388b0 100644 (file)
@@ -1,6 +1,6 @@
 /* Declaration for error-reporting function for Bison.
 
 /* Declaration for error-reporting function for Bison.
 
-   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
+   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2009
    Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -120,6 +120,27 @@ complain (const char *message, ...)
 }
 
 
 }
 
 
+/*--------------------------------------------------------------.
+| An incompatibility with POSIX Yacc: mapped either to warn* or |
+| complain* depending on yacc_flag.                             |
+`--------------------------------------------------------------*/
+
+void
+yacc_at (location loc, const char *message, ...)
+{
+  if (yacc_flag)
+    {
+      ERROR_MESSAGE (&loc, NULL, message);
+      complaint_issued = true;
+    }
+  else if (warnings_flag & warnings_yacc)
+    {
+      set_warning_issued ();
+      ERROR_MESSAGE (&loc, _("warning"), message);
+    }
+}
+
+
 /*-------------------------------------------------.
 | A severe error has occurred, we cannot proceed.  |
 `-------------------------------------------------*/
 /*-------------------------------------------------.
 | A severe error has occurred, we cannot proceed.  |
 `-------------------------------------------------*/
index a633613c19476462cfa342bafae74b0adbf357d7..89cdd91d3dcc80f62ba998007af803d64f707bd3 100644 (file)
@@ -1,5 +1,5 @@
 /* Declaration for error-reporting function for Bison.
 /* Declaration for error-reporting function for Bison.
-   Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2006, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -39,6 +39,13 @@ void complain (char const *format, ...)
 void complain_at (location loc, char const *format, ...)
   __attribute__ ((__format__ (__printf__, 2, 3)));
 
 void complain_at (location loc, char const *format, ...)
   __attribute__ ((__format__ (__printf__, 2, 3)));
 
+/** An incompatibility with POSIX Yacc: mapped either to warn* or
+    complain* depending on yacc_flag. */
+
+void yacc_at (location loc, char const *format, ...)
+  __attribute__ ((__format__ (__printf__, 2, 3)));
+
+
 /** A fatal error, causing immediate exit.  */
 
 void fatal (char const *format, ...)
 /** A fatal error, causing immediate exit.  */
 
 void fatal (char const *format, ...)
index f72514733b41bbeb35ad697900575353b619ba82..e299230b02c87fa50b7a14e7383f3df136e45505 100644 (file)
@@ -363,9 +363,11 @@ token_definitions_output (FILE *out)
       if (sym->tag[0] == '\'' || sym->tag[0] == '\"')
        continue;
 
       if (sym->tag[0] == '\'' || sym->tag[0] == '\"')
        continue;
 
-      /* Don't #define nonliteral tokens whose names contain periods
-        or '$' (as does the default value of the EOF token).  */
-      if (strchr (sym->tag, '.') || strchr (sym->tag, '$'))
+      /* Don't #define nonliteral tokens whose names contain periods,
+         dashes or '$' (as does the default value of the EOF token).  */
+      if (strchr (sym->tag, '.')
+          || strchr (sym->tag, '-')
+          || strchr (sym->tag, '$'))
        continue;
 
       fprintf (out, "%s[[[%s]], %d]",
        continue;
 
       fprintf (out, "%s[[[%s]], %d]",
index acae131bf295e850e24b17742c8477f14f31fe2e..38e64d619ad307c58b1090ab0ac3e2f5ebfd03f6 100644 (file)
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.4.1.49-783b.  */
+/* A Bison parser, made by GNU Bison 2.4.1.52-77be.  */
 
 /* Skeleton implementation for Bison's Yacc-like parsers in C
    
 
 /* Skeleton implementation for Bison's Yacc-like parsers in C
    
@@ -45,7 +45,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.4.1.49-783b"
+#define YYBISON_VERSION "2.4.1.52-77be"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -672,8 +672,8 @@ static const yytype_uint16 yyrline[] =
      434,   435,   440,   442,   447,   448,   452,   453,   454,   455,
      460,   465,   470,   476,   482,   493,   494,   503,   504,   510,
      511,   512,   519,   519,   523,   524,   525,   530,   531,   533,
      434,   435,   440,   442,   447,   448,   452,   453,   454,   455,
      460,   465,   470,   476,   482,   493,   494,   503,   504,   510,
      511,   512,   519,   519,   523,   524,   525,   530,   531,   533,
-     535,   537,   539,   549,   550,   556,   559,   568,   588,   590,
-     599,   604,   605,   610,   617,   619
+     535,   537,   539,   549,   550,   555,   556,   565,   585,   587,
+     596,   601,   602,   607,   614,   616
 };
 #endif
 
 };
 #endif
 
@@ -2551,16 +2551,14 @@ yyreduce:
   case 95:
 
 /* Line 1456 of yacc.c  */
   case 95:
 
 /* Line 1456 of yacc.c  */
-#line 556 "parse-gram.y"
-    {
-      (yyval.chars) = "";
-    }
+#line 555 "parse-gram.y"
+    { (yyval.chars) = ""; }
     break;
 
   case 97:
 
 /* Line 1456 of yacc.c  */
     break;
 
   case 97:
 
 /* Line 1456 of yacc.c  */
-#line 569 "parse-gram.y"
+#line 566 "parse-gram.y"
     {
       code_props plain_code;
       (yyvsp[(1) - (1)].code)[strlen ((yyvsp[(1) - (1)].code)) - 1] = '\n';
     {
       code_props plain_code;
       (yyvsp[(1) - (1)].code)[strlen ((yyvsp[(1) - (1)].code)) - 1] = '\n';
@@ -2574,14 +2572,14 @@ yyreduce:
   case 98:
 
 /* Line 1456 of yacc.c  */
   case 98:
 
 /* Line 1456 of yacc.c  */
-#line 589 "parse-gram.y"
+#line 586 "parse-gram.y"
     { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
     break;
 
   case 99:
 
 /* Line 1456 of yacc.c  */
     { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
     break;
 
   case 99:
 
 /* Line 1456 of yacc.c  */
-#line 591 "parse-gram.y"
+#line 588 "parse-gram.y"
     {
       (yyval.symbol) = symbol_get (char_name ((yyvsp[(1) - (1)].character)), (yylsp[(1) - (1)]));
       symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
     {
       (yyval.symbol) = symbol_get (char_name ((yyvsp[(1) - (1)].character)), (yylsp[(1) - (1)]));
       symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
@@ -2592,14 +2590,14 @@ yyreduce:
   case 100:
 
 /* Line 1456 of yacc.c  */
   case 100:
 
 /* Line 1456 of yacc.c  */
-#line 599 "parse-gram.y"
+#line 596 "parse-gram.y"
     { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
     break;
 
   case 103:
 
 /* Line 1456 of yacc.c  */
     { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
     break;
 
   case 103:
 
 /* Line 1456 of yacc.c  */
-#line 611 "parse-gram.y"
+#line 608 "parse-gram.y"
     {
       (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[(1) - (1)].chars)), (yylsp[(1) - (1)]));
       symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
     {
       (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[(1) - (1)].chars)), (yylsp[(1) - (1)]));
       symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
@@ -2609,7 +2607,7 @@ yyreduce:
   case 105:
 
 /* Line 1456 of yacc.c  */
   case 105:
 
 /* Line 1456 of yacc.c  */
-#line 620 "parse-gram.y"
+#line 617 "parse-gram.y"
     {
       code_props plain_code;
       code_props_plain_init (&plain_code, (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)]));
     {
       code_props plain_code;
       code_props_plain_init (&plain_code, (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)]));
@@ -2623,7 +2621,7 @@ yyreduce:
 
 
 /* Line 1456 of yacc.c  */
 
 
 /* Line 1456 of yacc.c  */
-#line 2627 "parse-gram.c"
+#line 2625 "parse-gram.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -2842,7 +2840,7 @@ yyreturn:
 
 
 /* Line 1676 of yacc.c  */
 
 
 /* Line 1676 of yacc.c  */
-#line 630 "parse-gram.y"
+#line 627 "parse-gram.y"
 
 
 
 
 
 
index ae82cd453c253f5df00bb578fb21e37bb58a662b..fecb919913554353a765d6b6d7fa8a05a4c8060f 100644 (file)
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.4.1.49-783b.  */
+/* A Bison parser, made by GNU Bison 2.4.1.52-77be.  */
 
 /* Skeleton interface for Bison's Yacc-like parsers in C
    
 
 /* Skeleton interface for Bison's Yacc-like parsers in C
    
index 83b02e36b630e9c477cc11dcc3711629299fbadc..2e4168b77ae53e3a6328ce6d57a2ef0f02406381 100644 (file)
@@ -547,15 +547,12 @@ rhs:
 
 variable:
   ID
 
 variable:
   ID
-  | STRING { $$ = uniqstr_new ($1); } /* deprecated and not M4-friendly */
-  ;
+| STRING { $$ = uniqstr_new ($1); }
+;
 
 /* Some content or empty by default. */
 content.opt:
 
 /* Some content or empty by default. */
 content.opt:
-  /* Nothing. */
-    {
-      $$ = "";
-    }
+  /* Nothing. */   { $$ = ""; }
 | STRING
 ;
 
 | STRING
 ;
 
index 292960cb4aa033bcf1d13f36bf077150dcb74394..2ef4eb3b312651d0f7ac3282fe13755e9b833ac5 100644 (file)
@@ -90,8 +90,8 @@ static void unexpected_newline (boundary, char const *);
 %x SC_STRING SC_CHARACTER
 
 letter   [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
 %x SC_STRING SC_CHARACTER
 
 letter   [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
-id       {letter}({letter}|[0-9])*
-directive %{letter}({letter}|[0-9]|-)*
+id       {letter}({letter}|[0-9]|-)*
+directive %{id}
 int      [0-9]+
 
 /* POSIX says that a tag must be both an id and a C union member, but
 int      [0-9]+
 
 /* POSIX says that a tag must be both an id and a C union member, but
@@ -382,7 +382,7 @@ splice       (\\[ \f\t\v]*\n)*
     unexpected_eof (token_start, "'");
     STRING_FINISH;
     loc->start = token_start;
     unexpected_eof (token_start, "'");
     STRING_FINISH;
     loc->start = token_start;
-    if (strlen(last_string) > 1)
+    if (strlen (last_string) > 1)
       val->character = last_string[1];
     else
       val->character = last_string[0];
       val->character = last_string[1];
     else
       val->character = last_string[0];
index 1db83f63ad515740c93c52ff1242609bb197f7f6..f9560efab37729ad2432f4696e9670e70baa42d0 100644 (file)
@@ -1,6 +1,7 @@
 /* Symbol table manager for Bison.
 
 /* Symbol table manager for Bison.
 
-   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007,
+   2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
@@ -58,6 +59,13 @@ symbol_new (uniqstr tag, location loc)
   symbol *res = xmalloc (sizeof *res);
 
   uniqstr_assert (tag);
   symbol *res = xmalloc (sizeof *res);
 
   uniqstr_assert (tag);
+
+  /* If the tag is not a string (starts with a double quote), check
+     that it is valid for Yacc. */
+  if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-'))
+    yacc_at (loc, _("POSIX Yacc forbids dashes in symbol names: %s"),
+             tag);
+
   res->tag = tag;
   res->location = loc;
 
   res->tag = tag;
   res->location = loc;