bison-patches
[Top][All Lists]
Advanced

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

Re: Bison patches


From: Paul Eggert
Subject: Re: Bison patches
Date: 01 Oct 2003 14:36:04 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Akim Demaille <address@hidden> writes:

> Why an argument instead of %no-default-prec and %default-prec?

I was thinking that we should allow future extensions, in
which there are different flavors of default precedences.  This might
become more of an issue with non-LALR parsers.  (I'm being vague here,
because I haven't thought it through.)

But on second thought let's just go with %no-default-prec for now.
Frank's original proposal was more that way, anyway.  We can worry
about future extensions (if any) later.

So I installed this:

2003-10-01  Paul Eggert  <address@hidden>

        * src/parse-gram.h (PERCENT_NO_DEFAULT_PREC): New token.
        (grammar_declaration): Use it.
        * src/scan-gram.l: New token %no-default-prec.
        * tests/conflicts.at: Revamp tests to use %no-default-prec.
        * NEWS, doc/bison.texinfo: Document the above.

Index: NEWS
===================================================================
RCS file: /cvsroot/bison/bison/NEWS,v
retrieving revision 1.97
diff -p -u -r1.97 NEWS
--- NEWS        30 Sep 2003 20:20:25 -0000      1.97
+++ NEWS        1 Oct 2003 20:41:17 -0000
@@ -3,8 +3,8 @@ Bison News
 
 Changes in version 1.875c:
 
-* New %default-prec declaration, to enable (the default) or disable
-  default rule precedences.
+* New %no-default-prec declaration, to disable default rule precedences.
+  New %default-prec declaration, to reestablish the default.
 
 Changes in version 1.875b, 2003-06-17:
 
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.112
diff -p -u -r1.112 bison.texinfo
--- doc/bison.texinfo   30 Sep 2003 20:11:29 -0000      1.112
+++ doc/bison.texinfo   1 Oct 2003 20:41:27 -0000
@@ -3684,8 +3684,7 @@ Using it in a way that would be associat
 @end deffn
 
 @deffn {Directive} %default-prec
-Specify whether to assign a precedence to rules lacking an
-explicit @code{%prec} modifier
+Assign a precedence to rules lacking an explicit @code{%prec} modifier
 (@pxref{Contextual Precedence, ,Context-Dependent Precedence}).
 @end deffn
 
@@ -3759,6 +3758,12 @@ and so on.  @xref{Multiple Parsers, ,Mul
 Program}.
 @end deffn
 
address@hidden {Directive} %no-default-prec
+Do not assign a precedence to rules lacking an explicit @code{%prec}
+modifier (@pxref{Contextual Precedence, ,Context-Dependent
+Precedence}).
address@hidden deffn
+
 @deffn {Directive} %no-parser
 Do not include any C code in the parser file; generate tables only.  The
 parser file contains just @code{#define} directives and static variable
@@ -4862,20 +4867,20 @@ minus, Bison silently assumes that minus
 This kind of problem can be tricky to debug, since one typically
 discovers the mistake only by testing the code.
 
-The @code{%default-prec 0;} declaration makes it easier to discover
+The @code{%no-default-prec;} declaration makes it easier to discover
 this kind of problem systematically.  It causes rules that lack a
 @code{%prec} modifier to have no precedence, even if the last terminal
 symbol mentioned in their components has a declared precedence.
 
-If @code{%default-prec 0;} is in effect, you must specify @code{%prec}
+If @code{%no-default-prec;} is in effect, you must specify @code{%prec}
 for all rules that participate in precedence conflict resolution.
 Then you will see any shift/reduce conflict until you tell Bison how
 to resolve it, either by changing your grammar or by adding an
 explicit precedence.  This will probably add declarations to the
 grammar, but it helps to protect against incorrect rule precedences.
 
-The effect of @code{%default-prec 0;} can be reversed by giving
address@hidden 1;}, which is the default.
+The effect of @code{%no-default-prec;} can be reversed by giving
address@hidden;}, which is the default.
 
 @node Parser States
 @section Parser States
@@ -6808,10 +6813,10 @@ parsing.  @xref{Parser Function, ,The Pa
 Equip the parser for debugging.  @xref{Decl Summary}.
 @end deffn
 
address@hidden {Directive} %default-prec @var{state};
-Bison declaration to specify whether to assign a precedence to rules
-that lack an explicit @samp{%prec} modifier.  @xref{Contextual
-Precedence, ,Context-Dependent Precedence}.
address@hidden {Directive} %default-prec
+Assign a precedence to rules that lack an explicit @samp{%prec}
+modifier.  @xref{Contextual Precedence, ,Context-Dependent
+Precedence}.
 @end deffn
 
 @deffn {Directive} %defines
@@ -6865,6 +6870,12 @@ function is applied to the two semantic 
 
 @deffn {Directive} %name-prefix="@var{prefix}"
 Bison declaration to rename the external symbols.  @xref{Decl Summary}.
address@hidden deffn
+
address@hidden {Directive} %no-default-prec
+Do not assign a precedence to rules that lack an explicit @samp{%prec}
+modifier.  @xref{Contextual Precedence, ,Context-Dependent
+Precedence}.
 @end deffn
 
 @deffn {Directive} %no-lines
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.44
diff -p -u -r1.44 parse-gram.y
--- src/parse-gram.y    30 Sep 2003 20:11:29 -0000      1.44
+++ src/parse-gram.y    1 Oct 2003 20:41:46 -0000
@@ -126,6 +126,7 @@ int current_prec = 0;
   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"
@@ -241,12 +242,13 @@ grammar_declaration:
        symbol_printer_set (list->sym, $1, list->location);
       symbol_list_free ($2);
     }
-| "%default-prec" INT
+| "%default-prec"
     {
-      if (0 <= $2 && $2 <= 1)
-       default_prec = $2;
-      else
-       complain_at (@1, _("invalid value for `%default-prec'"));
+      default_prec = true;
+    }
+| "%no-default-prec"
+    {
+      default_prec = false;
     }
 ;
 
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.64
diff -p -u -r1.64 scan-gram.l
--- src/scan-gram.l     30 Sep 2003 20:11:29 -0000      1.64
+++ src/scan-gram.l     1 Oct 2003 20:41:47 -0000
@@ -198,6 +198,7 @@ splice       (\\[ \f\t\v]*\n)*
   "%locations"            return PERCENT_LOCATIONS;
   "%merge"               return PERCENT_MERGE;
   "%name"[-_]"prefix"     return PERCENT_NAME_PREFIX;
+  "%no"[-_]"default"[-_]"prec" return PERCENT_NO_DEFAULT_PREC;
   "%no"[-_]"lines"        return PERCENT_NO_LINES;
   "%nonassoc"             return PERCENT_NONASSOC;
   "%nondeterministic-parser"   return PERCENT_NONDETERMINISTIC_PARSER;
Index: tests/conflicts.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/conflicts.at,v
retrieving revision 1.26
diff -p -u -r1.26 conflicts.at
--- tests/conflicts.at  30 Sep 2003 20:11:29 -0000      1.26
+++ tests/conflicts.at  1 Oct 2003 20:41:47 -0000
@@ -550,11 +550,11 @@ input.y: warning: expected 0 reduce/redu
 AT_CLEANUP
 
 
-## ---------------------------- ##
-## %default-prec without %prec  ##
-## ---------------------------- ##
+## ------------------------------- ##
+## %no-default-prec without %prec  ##
+## ------------------------------- ##
 
-AT_SETUP([%default-prec without %prec])
+AT_SETUP([%no-default-prec without %prec])
 
 AT_DATA([[input.y]],
 [[%left '+'
@@ -562,7 +562,7 @@ AT_DATA([[input.y]],
 
 %%
 
-%default-prec 0;
+%no-default-prec;
 
 e:   e '+' e
    | e '*' e
@@ -576,11 +576,11 @@ AT_CHECK([bison -o input.c input.y], 0, 
 AT_CLEANUP
 
 
-## ------------------------- ##
-## %default-prec with %prec  ##
-## ------------------------- ##
+## ---------------------------- ##
+## %no-default-prec with %prec  ##
+## ---------------------------- ##
 
-AT_SETUP([%default-prec with %prec])
+AT_SETUP([%no-default-prec with %prec])
 
 AT_DATA([[input.y]],
 [[%left '+'
@@ -588,7 +588,7 @@ AT_DATA([[input.y]],
 
 %%
 
-%default-prec 0;
+%no-default-prec;
 
 e:   e '+' e %prec '+'
    | e '*' e %prec '*'
@@ -601,10 +601,10 @@ AT_CLEANUP
 
 
 ## ---------------- ##
-## %default-prec 1  ##
+## %default-prec    ##
 ## ---------------- ##
 
-AT_SETUP([%default-prec 1])
+AT_SETUP([%default-prec])
 
 AT_DATA([[input.y]],
 [[%left '+'
@@ -612,7 +612,7 @@ AT_DATA([[input.y]],
 
 %%
 
-%default-prec 1;
+%default-prec;
 
 e:   e '+' e
    | e '*' e




reply via email to

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