]> 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)
committerAkim Demaille <demaille@gostai.com>
Mon, 20 Apr 2009 21:17:51 +0000 (23:17 +0200)
* data/bison.m4 (b4_percent_define_if_define_): Also map dashes to
underscores.
* 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.

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

index ff36a3425884a6c16be4cb56562b4664251cf34a..b8a5748b4c6b1b0efccac5034b79745e07d511bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2009-04-20  Akim Demaille  <demaille@gostai.com>
+
+       variables: accept dashes.
+       * data/bison.m4 (b4_percent_define_if_define_): Also map dashes to
+       underscores.
+       * 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-20  Akim Demaille  <demaille@gostai.com>
 
        Consistently refer to Yacc, not YACC.
 2009-04-20  Akim Demaille  <demaille@gostai.com>
 
        Consistently refer to Yacc, not YACC.
index 2b4e504645262b9eeb69a5927f2aa328cee6b08a..384f875a01e7b0572d80fb7e26aab2f0b132e459 100644 (file)
@@ -668,9 +668,10 @@ m4_define([b4_percent_define_default],
 # b4_percent_define_if_define(VARIABLE)
 # -------------------------------------
 # Define b4_VARIABLE_if that executes its $1 or $2 depending whether
 # b4_percent_define_if_define(VARIABLE)
 # -------------------------------------
 # Define b4_VARIABLE_if that executes its $1 or $2 depending whether
-# VARIABLE was %defined.  The character `.' in VARIABLE is mapped to `_'.
+# VARIABLE was %defined.  The characters `.' and `-' in VARIABLE are mapped
+# to `_'.
 m4_define([b4_percent_define_if_define_],
 m4_define([b4_percent_define_if_define_],
-[m4_define(m4_bpatsubst([b4_$1_if], [[.]], [_]),
+[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
            [b4_percent_define_flag_if([$1], [$2], [$3])])])
 m4_define([b4_percent_define_if_define],
 [b4_percent_define_default([[$1]], [[false]])
            [b4_percent_define_flag_if([$1], [$2], [$3])])])
 m4_define([b4_percent_define_if_define],
 [b4_percent_define_default([[$1]], [[false]])
index fbe9ac9d35990e45af2de3fc9391d551b0a6d27b..a3a85a2b35617e173492bf12a773ad9979b2c6eb 100644 (file)
@@ -3053,8 +3053,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 12204461d0c6bd8862ac0989ac99febf67fd9545..0a08fc4584883f4fed301074abf559feb355189f 100644 (file)
@@ -490,9 +490,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 20dee8c30af549c39d676492425bc02bd0b6dd1a..caa3d3098de65f60f493ae23fe0da154b7a68cef 100644 (file)
@@ -535,15 +535,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 478d0967642c65bf624a133eb2aeec06245b3e69..bc7592ec3e996f9143119c3cfad5043ca49cdb1c 100644 (file)
@@ -99,8 +99,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
@@ -411,7 +411,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 b65bdd48ae02a76d9d20335829c3882020ab8d8b..c956e72d6d0ae1f41f5788d0a7474eeed6b40deb 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;