bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] Implement %define lr.default_rules.


From: Joel E. Denny
Subject: Re: [PATCH] Implement %define lr.default_rules.
Date: Thu, 23 Apr 2009 04:19:36 -0400 (EDT)

On Tue, 21 Apr 2009, Joel E. Denny wrote:

> > > I haven't pushed yet because I would really like to rename "default rule"
> > > to "default reduction" throughout Bison first:
> 
> > > Does my argument make sense to anyone else?  Is this terminology too
> > > standard to change now?  If you agree with the change, should it be
> > > "default reduction" or "default reduce"?  Thanks.
> > 
> > I agree with the change, and I would use "default reduction".
> 
> Thanks.  I'll work on a patch to make that change.

I pushed the following patch to branch-2.5 and a similar one to master.

> > > +  /* We need a lookahead either to distinguish different reductions
> > > +     (i.e., there are two or more), or to distinguish a reduction from a
> > > +     shift.  Otherwise, it is straightforward, and the state is
> > > +     `consistent'.  However, for states that have any rules, treat only
> > 
> > I don't understand "states that have any rules".
> 
> It's been a couple of years since I wrote that, but I believe I was trying 
> to be consistent with "default rules".  I agree it's ugly for many 
> reasons.  I will change it to "states that have any reductions".

I realize now that the sentence is clearer if the phrase is completely 
removed, so I removed it.  That's probably what you were telling me.  Let 
me know if it's still not clear.

>From 783b0f0a2d5e46696906fb6300695e5b384a7f78 Mon Sep 17 00:00:00 2001
From: Joel E. Denny <address@hidden>
Date: Thu, 23 Apr 2009 03:18:03 -0400
Subject: [PATCH] Rename "default rule" to "default reduction".

This includes changing variable names in code, changing
comments, and renaming %define lr.default_rules to %define
lr.default_reductions.
* NEWS (2.5): Update IELR documentation.
* data/glr.c, data/lalr1.cc, data/lalr1.java, data/yacc.c:
Adjust YYDEFACT and yydefact_ documentation.
* doc/bison.texinfo (Decl Summary): Adjust lr.default_reductions
and lr.type documentation.  Make some other wording
improvements.
(Glossary): Adjust cross-references and Default Reduction
definition.
* src/lalr.c (state_lookahead_tokens_count): Adjust code.
Remove a confusing comment pointed out by Akim Demaille.
(initialize_LA): Adjust code.
* src/print-xml.c (print_reductions): Adjust code.
* src/print.c (print_reductions): Adjust code.
* src/reader.c (reader): Adjust code.
* src/tables.c (action_row): Adjust code.
(token_actions): Adjust code.
* src/tables.h: Adjust YYDEFACT documentation.
* tests/input.at (%define lr.default_rules invalid values):
Rename test group to...
(%define lr.default_reductions invalid values): ... this, and
update grammar file and expected output.
* tests/reduce.at (AT_TEST_LR_DEFAULT_RULES): Rename to...
(AT_TEST_LR_DEFAULT_REDUCTIONS): ... this, and update.

diff --git a/NEWS b/NEWS
index 91bde87..92a935f 100644
--- a/NEWS
+++ b/NEWS
@@ -24,10 +24,11 @@ Bison News
     %define lr.type "IELR"
     %define lr.type "canonical LR"
 
-  The default rules optimization in the parser tables can also be
-  adjusted using `%define lr.default_rules'.  See the documentation for
-  `%define lr.type' and `%define lr.default_rules' in the section `Bison
-  Declaration Summary' in the Bison manual for the details.
+  The default reduction optimization in the parser tables can also be
+  adjusted using `%define lr.default_reductions'.  See the documentation
+  for `%define lr.type' and `%define lr.default_reductions' in the
+  section `Bison Declaration Summary' in the Bison manual for the
+  details.
 
   These features are experimental.  More user feedback will help to
   stabilize them.
diff --git a/data/glr.c b/data/glr.c
index 0b4ad52..661db95 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -1,8 +1,8 @@
                                                                     -*- C -*-
 
 # GLR skeleton for Bison
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software
-# Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 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
@@ -150,7 +150,7 @@ m4_changecom()
 m4_divert_push(0)dnl
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison GLR parsers in C],
-             [2002, 2003, 2004, 2005, 2006, 2007, 2008])
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009])
 [
 /* C GLR parser skeleton written by Paul Hilfinger.  */
 
@@ -412,9 +412,9 @@ static const ]b4_int_type_for([b4_merger])[ yymerger[] =
   ]b4_merger[
 };
 
-/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
-   doesn't specify something else to do.  Zero means the default is an
-   error.  */
+/* YYDEFACT[S] -- default reduction number in state S.  Performed when
+   YYTABLE doesn't specify something else to do.  Zero means the default
+   is an error.  */
 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
 {
   ]b4_defact[
@@ -2639,7 +2639,7 @@ m4_if(b4_skeleton, ["glr.c"],
 [b4_defines_if(
 address@hidden(b4_spec_defines_file@)@
 b4_copyright([Skeleton interface for Bison GLR parsers in C],
-             [2002, 2003, 2004, 2005, 2006, 2007, 2008])
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009])
 
 b4_shared_declarations
 
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 603786e..342d87c 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -1,6 +1,6 @@
 # C++ skeleton for Bison
 
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 # Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
@@ -35,7 +35,7 @@ m4_divert_push(0)dnl
 b4_defines_if(
 address@hidden(b4_spec_defines_file@)@
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
-             [2002, 2003, 2004, 2005, 2006, 2007, 2008])
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009])
 dnl FIXME: This is wrong, we want computed header guards.
 [
 /* C++ LALR(1) parser skeleton written by Akim Demaille.  */
@@ -197,7 +197,7 @@ b4_error_verbose_if([, int tok])[);
     static const ]b4_int_type_for([b4_pact])[ yypact_[];
     static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
 
-    /// For a state, default rule to reduce.
+    /// For a state, default reduction number.
     /// Unless\a  yytable_ specifies something else to do.
     /// Zero means the default is an error.
     static const ]b4_int_type_for([b4_defact])[ yydefact_[];
@@ -300,7 +300,7 @@ b4_percent_code_get([[provides]])[]dnl
 ])dnl
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
-             [2002, 2003, 2004, 2005, 2006, 2007, 2008])
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009])
 b4_percent_code_get([[top]])[]dnl
 m4_if(b4_prefix, [yy], [],
 [
@@ -889,9 +889,9 @@ b4_error_verbose_if([, int tok])[)
     ]b4_pact[
   };
 
-  /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
-     doesn't specify something else to do.  Zero means the default is an
-     error.  */
+  /* YYDEFACT[S] -- default reduction number in state S.  Performed when
+     YYTABLE doesn't specify something else to do.  Zero means the
+     default is an error.  */
   const ]b4_int_type_for([b4_defact])[
   ]b4_parser_class_name[::yydefact_[] =
   {
@@ -1057,7 +1057,7 @@ b4_error_verbose_if([, int tok])[)
 dnl
 @output(b4_dir_prefix[]stack.hh@)@
 b4_copyright([Stack handling for Bison parsers in C++],
-             [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009])[
 
 #ifndef BISON_STACK_HH
 # define BISON_STACK_HH
diff --git a/data/lalr1.java b/data/lalr1.java
index c855a75..5fbce2b 100644
--- a/data/lalr1.java
+++ b/data/lalr1.java
@@ -1,6 +1,6 @@
 # Java skeleton for Bison -*- autoconf -*-
 
-# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+# Copyright (C) 2007, 2008, 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
@@ -25,7 +25,7 @@ m4_ifval(m4_defn([b4_symbol_destructors]),
 m4_divert_push(0)dnl
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
-  [2007, 2008])
+  [2007, 2008, 2009])
 
 b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
 ])[/* First part of user declarations.  */
@@ -732,9 +732,9 @@ m4_popdef([b4_at_dollar])])dnl
     ]b4_pact[
   };
 
-  /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
-     doesn't specify something else to do.  Zero means the default is an
-     error.  */
+  /* YYDEFACT[S] -- default reduction number in state S.  Performed when
+     YYTABLE doesn't specify something else to do.  Zero means the
+     default is an error.  */
   private static final ]b4_int_type_for([b4_defact])[ yydefact_[] =
   {
     ]b4_defact[
diff --git a/data/yacc.c b/data/yacc.c
index 940b4a7..3c7c602 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -3,7 +3,7 @@
 # Yacc compatible skeleton for Bison
 
 # Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-# 2007, 2008 Free Software Foundation, Inc.
+# 2007, 2008, 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
@@ -155,7 +155,8 @@ m4_changecom()
 m4_divert_push(0)dnl
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
-  [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])[
+  [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+   2009])[
 
 /* C LALR(1) parser skeleton written by Richard Stallman, by
    simplifying the original so-called "semantic" parser.  */
@@ -547,8 +548,8 @@ static const ]b4_int_type_for([b4_r2])[ yyr2[] =
   ]b4_r2[
 };
 
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
-   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
+   Performed when YYTABLE doesn't specify something else to do.  Zero
    means the default is an error.  */
 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
 {
@@ -1676,7 +1677,8 @@ yypushreturn:
 b4_defines_if(
 address@hidden(b4_spec_defines_file@)@
 b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
-  [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
+  [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+   2009])
 
 b4_percent_code_get([[requires]])[]dnl
 
diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index ed092e2..8e3ca22 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -4899,9 +4899,9 @@ More user feedback will help to stabilize it.)
 @item Default Value: @code{"pull"}
 @end itemize
 
address@hidden lr.default_rules
address@hidden default rules
address@hidden %define lr.default_rules
address@hidden lr.default_reductions
address@hidden default reductions
address@hidden %define lr.default_reductions
 @cindex delayed syntax errors
 @cindex syntax errors delayed
 
@@ -4909,15 +4909,14 @@ More user feedback will help to stabilize it.)
 @item Language(s): all
 
 @item Purpose: Specifies the kind of states that are permitted to
-contain default rules.
-That is, in such a state, Bison declares the rule with the largest
-lookahead set to be the default rule by which to reduce and then removes
-that lookahead set.
-The advantages of default rules are discussed below.
+contain default reductions.
+That is, in such a state, Bison declares the reduction with the largest
+lookahead set to be the default reduction and then removes that
+lookahead set.
+The advantages of default reductions are discussed below.
 The disadvantage is that, when the generated parser encounters a
 syntactically unacceptable token, the parser might then perform
-unnecessary reductions by default rules before it can detect the syntax
-error.
+unnecessary default reductions before it can detect the syntax error.
 
 (This feature is experimental.
 More user feedback will help to stabilize it.)
@@ -4927,14 +4926,14 @@ More user feedback will help to stabilize it.)
 @item @code{"all"}.
 For @acronym{LALR} and @acronym{IELR} parsers (@pxref{Decl
 Summary,,lr.type}) by default, all states are permitted to contain
-default rules.
+default reductions.
 The advantage is that parser table sizes can be significantly reduced.
 The reason Bison does not by default attempt to address the disadvantage
 of delayed syntax error detection is that this disadvantage is already
 inherent in @acronym{LALR} and @acronym{IELR} parser tables.
-That is, unlike a canonical @acronym{LR} state, an @acronym{LALR} or
address@hidden state can contain syntactically incorrect tokens in the
-lookahead sets of its rules.
+That is, unlike in a canonical @acronym{LR} state, the lookahead sets of
+reductions in an @acronym{LALR} or @acronym{IELR} state can contain
+tokens that are syntactically incorrect for some left contexts.
 
 @item @code{"consistent"}.
 @cindex consistent states
@@ -4942,16 +4941,17 @@ A consistent state is a state that has only one 
possible action.
 If that action is a reduction, then the parser does not need to request
 a lookahead token from the scanner before performing that action.
 However, the parser only recognizes the ability to ignore the lookahead
-token when such a reduction is encoded as a default rule.
-Thus, if default rules are permitted in and only in consistent states,
-then a canonical @acronym{LR} parser reports a syntax error as soon as
-it @emph{needs} the syntactically unacceptable token from the scanner.
+token when such a reduction is encoded as a default reduction.
+Thus, if default reductions are permitted in and only in consistent
+states, then a canonical @acronym{LR} parser reports a syntax error as
+soon as it @emph{needs} the syntactically unacceptable token from the
+scanner.
 
 @item @code{"accepting"}.
 @cindex accepting state
-By default, the only default rule permitted in a canonical @acronym{LR}
-parser is the accept rule in the accepting state, which the parser
-reaches only after reading all tokens from the input.
+By default, the only default reduction permitted in a canonical
address@hidden parser is the accept action in the accepting state, which
+the parser reaches only after reading all tokens from the input.
 Thus, the default canonical @acronym{LR} parser reports a syntax error
 as soon as it @emph{reaches} the syntactically unacceptable token
 without performing any extra reductions.
@@ -5028,8 +5028,8 @@ While Bison generates @acronym{LALR} parser tables by 
default for
 historical reasons, @acronym{IELR} or canonical @acronym{LR} is almost
 always preferable for deterministic parsers.
 The trouble is that @acronym{LALR} parser tables can suffer from
-mysterious conflicts and may not accept the full set of sentences that
address@hidden and canonical @acronym{LR} accept.
+mysterious conflicts and thus may not accept the full set of sentences
+that @acronym{IELR} and canonical @acronym{LR} accept.
 @xref{Mystery Conflicts}, for details.
 However, there are at least two scenarios where @acronym{LALR} may be
 worthwhile:
@@ -5039,8 +5039,8 @@ worthwhile:
 do not resolve any conflicts statically (for example, with @code{%left}
 or @code{%prec}), then the parser explores all potential parses of any
 given input.
-Thus, the use of @acronym{LALR} parser tables is guaranteed not to alter
-the language accepted by the parser.
+In this case, the use of @acronym{LALR} parser tables is guaranteed not
+to alter the language accepted by the parser.
 @acronym{LALR} parser tables are the smallest parser tables Bison can
 currently generate, so they may be preferable.
 
@@ -5069,13 +5069,14 @@ This can significantly reduce the complexity of 
developing of a grammar.
 @item @code{"canonical LR"}.
 @cindex delayed syntax errors
 @cindex syntax errors delayed
-The only advantage of canonical @acronym{LR} over @acronym{IELR} is that
-every canonical @acronym{LR} state encodes that state's exact set of
-syntactically acceptable tokens.
-The only difference in parsing behavior is then that the canonical
+The only advantage of canonical @acronym{LR} over @acronym{IELR} is
+that, for every left context of every canonical @acronym{LR} state, the
+set of tokens accepted by that state is the exact set of tokens that is
+syntactically acceptable in that left context.
+Thus, the only difference in parsing behavior is that the canonical
 @acronym{LR} parser can report a syntax error as soon as possible
 without performing any unnecessary reductions.
address@hidden Summary,,lr.default_rules}, for further details.
address@hidden Summary,,lr.default_reductions}, for further details.
 Even when canonical @acronym{LR} behavior is ultimately desired,
 @acronym{IELR}'s elimination of duplicate conflicts should still
 facilitate the development of a grammar.
@@ -10341,7 +10342,7 @@ committee document contributing to what became the 
Algol 60 report.
 
 @item Consistent State
 A state containing only one possible action.
address@hidden Summary,,lr.default_rules}.
address@hidden Summary,,lr.default_reductions}.
 
 @item Context-free grammars
 Grammars specified as rules that can be applied regardless of context.
@@ -10350,12 +10351,13 @@ expression, integers are allowed @emph{anywhere} an 
expression is
 permitted.  @xref{Language and Grammar, ,Languages and Context-Free
 Grammars}.
 
address@hidden Default Rule
-The rule by which a parser should reduce if the current parser state
address@hidden Default Reduction
+The reduction that a parser should perform if the current parser state
 contains no other action for the lookahead token.
-In permitted parser states, Bison declares the rule with the largest
-lookahead set to be the default rule and removes that lookahead set.
address@hidden Summary,,lr.default_rules}.
+In permitted parser states, Bison declares the reduction with the
+largest lookahead set to be the default reduction and removes that
+lookahead set.
address@hidden Summary,,lr.default_reductions}.
 
 @item Dynamic allocation
 Allocation of memory that occurs during execution, rather than at
diff --git a/src/lalr.c b/src/lalr.c
index 0101149..a3a31b2 100644
--- a/src/lalr.c
+++ b/src/lalr.c
@@ -328,7 +328,7 @@ compute_lookahead_tokens (void)
 `----------------------------------------------------*/
 
 static int
-state_lookahead_tokens_count (state *s, bool default_rule_only_for_accept)
+state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
 {
   int n_lookahead_tokens = 0;
   reductions *rp = s->reductions;
@@ -344,14 +344,14 @@ state_lookahead_tokens_count (state *s, bool 
default_rule_only_for_accept)
   /* We need a lookahead either to distinguish different reductions
      (i.e., there are two or more), or to distinguish a reduction from a
      shift.  Otherwise, it is straightforward, and the state is
-     `consistent'.  However, for states that have any rules, treat only
-     the accepting state as consistent (since there is never a lookahead
-     token that makes sense there, and so no lookahead token should be
-     read) if the user has otherwise disabled default rules.  */
+     `consistent'.  However, treat only the accepting state as
+     consistent (because there is never a lookahead token that makes
+     sense there, and so no lookahead token should be read) if the user
+     has otherwise disabled default reductions.  */
   if (rp->num > 1
       || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0))
       || (rp->num == 1 && rp->rules[0]->number != 0
-          && default_rule_only_for_accept))
+          && default_reduction_only_for_accept))
     n_lookahead_tokens += rp->num;
   else
     s->consistent = 1;
@@ -369,18 +369,21 @@ initialize_LA (void)
 {
   state_number i;
   bitsetv pLA;
-  bool default_rule_only_for_accept;
+  bool default_reduction_only_for_accept;
   {
-    char *default_rules = muscle_percent_define_get ("lr.default_rules");
-    default_rule_only_for_accept = 0 == strcmp (default_rules, "accepting");
-    free (default_rules);
+    char *default_reductions =
+      muscle_percent_define_get ("lr.default_reductions");
+    default_reduction_only_for_accept =
+      0 == strcmp (default_reductions, "accepting");
+    free (default_reductions);
   }
 
   /* Compute the total number of reductions requiring a lookahead.  */
   nLA = 0;
   for (i = 0; i < nstates; i++)
     nLA +=
-      state_lookahead_tokens_count (states[i], default_rule_only_for_accept);
+      state_lookahead_tokens_count (states[i],
+                                    default_reduction_only_for_accept);
   /* Avoid having to special case 0.  */
   if (!nLA)
     nLA = 1;
@@ -392,7 +395,8 @@ initialize_LA (void)
   for (i = 0; i < nstates; i++)
     {
       int count =
-        state_lookahead_tokens_count (states[i], default_rule_only_for_accept);
+        state_lookahead_tokens_count (states[i],
+                                      default_reduction_only_for_accept);
       if (count)
        {
          states[i]->reductions->lookahead_tokens = pLA;
diff --git a/src/print-xml.c b/src/print-xml.c
index cb6707d..72e61a8 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -1,6 +1,6 @@
 /* Print an xml on generated parser, for Bison,
 
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -244,7 +244,7 @@ print_reductions (FILE *out, int level, state *s)
 {
   transitions *trans = s->transitions;
   reductions *reds = s->reductions;
-  rule *default_rule = NULL;
+  rule *default_reduction = NULL;
   int report = false;
   int i, j;
 
@@ -254,7 +254,7 @@ print_reductions (FILE *out, int level, state *s)
   }
 
   if (yydefact[s->number] != 0)
-    default_rule = &rules[yydefact[s->number] - 1];
+    default_reduction = &rules[yydefact[s->number] - 1];
 
   bitset_zero (no_reduce_set);
   FOR_EACH_SHIFT (trans, i)
@@ -263,7 +263,7 @@ print_reductions (FILE *out, int level, state *s)
     if (s->errs->symbols[i])
       bitset_set (no_reduce_set, s->errs->symbols[i]->number);
 
-  if (default_rule)
+  if (default_reduction)
     report = true;
 
   if (reds->lookahead_tokens)
@@ -276,7 +276,7 @@ print_reductions (FILE *out, int level, state *s)
            {
              if (! count)
                {
-                 if (reds->rules[j] != default_rule)
+                 if (reds->rules[j] != default_reduction)
                    report = true;
                  count = true;
                }
@@ -307,7 +307,7 @@ print_reductions (FILE *out, int level, state *s)
            {
              if (! count)
                {
-                 if (reds->rules[j] != default_rule)
+                 if (reds->rules[j] != default_reduction)
                    print_reduction (out, level + 1, symbols[i]->tag,
                                     reds->rules[j], true);
                  else
@@ -318,7 +318,7 @@ print_reductions (FILE *out, int level, state *s)
                {
                  if (defaulted)
                    print_reduction (out, level + 1, symbols[i]->tag,
-                                    default_rule, true);
+                                    default_reduction, true);
                  defaulted = false;
                  print_reduction (out, level + 1, symbols[i]->tag,
                                   reds->rules[j], false);
@@ -326,9 +326,9 @@ print_reductions (FILE *out, int level, state *s)
            }
       }
 
-  if (default_rule)
+  if (default_reduction)
     print_reduction (out, level + 1,
-                    "$default", default_rule, true);
+                    "$default", default_reduction, true);
 
   xml_puts (out, level, "</reductions>");
 }
diff --git a/src/print.c b/src/print.c
index 413896c..7fc577c 100644
--- a/src/print.c
+++ b/src/print.c
@@ -242,7 +242,7 @@ print_reductions (FILE *out, state *s)
 {
   transitions *trans = s->transitions;
   reductions *reds = s->reductions;
-  rule *default_rule = NULL;
+  rule *default_reduction = NULL;
   size_t width = 0;
   int i, j;
   bool non_default_action = false;
@@ -251,7 +251,7 @@ print_reductions (FILE *out, state *s)
     return;
 
   if (yydefact[s->number] != 0)
-    default_rule = &rules[yydefact[s->number] - 1];
+    default_reduction = &rules[yydefact[s->number] - 1];
 
   bitset_zero (no_reduce_set);
   FOR_EACH_SHIFT (trans, i)
@@ -261,7 +261,7 @@ print_reductions (FILE *out, state *s)
       bitset_set (no_reduce_set, s->errs->symbols[i]->number);
 
   /* Compute the width of the lookahead token column.  */
-  if (default_rule)
+  if (default_reduction)
     width = strlen (_("$default"));
 
   if (reds->lookahead_tokens)
@@ -274,7 +274,7 @@ print_reductions (FILE *out, state *s)
            {
              if (! count)
                {
-                 if (reds->rules[j] != default_rule)
+                 if (reds->rules[j] != default_reduction)
                    max_length (&width, symbols[i]->tag);
                  count = true;
                }
@@ -306,7 +306,7 @@ print_reductions (FILE *out, state *s)
            {
              if (! count)
                {
-                 if (reds->rules[j] != default_rule)
+                 if (reds->rules[j] != default_reduction)
                     {
                       non_default_action = true;
                       print_reduction (out, width,
@@ -323,7 +323,7 @@ print_reductions (FILE *out, state *s)
                  if (defaulted)
                    print_reduction (out, width,
                                     symbols[i]->tag,
-                                    default_rule, true);
+                                    default_reduction, true);
                  defaulted = false;
                  print_reduction (out, width,
                                   symbols[i]->tag,
@@ -332,15 +332,16 @@ print_reductions (FILE *out, state *s)
            }
       }
 
-  if (default_rule)
+  if (default_reduction)
     {
-      char *default_rules = muscle_percent_define_get ("lr.default_rules");
-      print_reduction (out, width, _("$default"), default_rule, true);
-      aver (0 == strcmp (default_rules, "all")
-            || (0 == strcmp (default_rules, "consistent")
+      char *default_reductions =
+        muscle_percent_define_get ("lr.default_reductions");
+      print_reduction (out, width, _("$default"), default_reduction, true);
+      aver (0 == strcmp (default_reductions, "all")
+            || (0 == strcmp (default_reductions, "consistent")
                 && !non_default_action)
             || (reds->num == 1 && reds->rules[0]->number == 0));
-      free (default_rules);
+      free (default_reductions);
     }
 }
 
diff --git a/src/reader.c b/src/reader.c
index b2fdc3b..17ff0f7 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -561,9 +561,9 @@ reader (void)
     muscle_percent_define_default ("lr.type", "LALR");
     lr_type = muscle_percent_define_get ("lr.type");
     if (0 != strcmp (lr_type, "canonical LR"))
-      muscle_percent_define_default ("lr.default_rules", "all");
+      muscle_percent_define_default ("lr.default_reductions", "all");
     else
-      muscle_percent_define_default ("lr.default_rules", "accepting");
+      muscle_percent_define_default ("lr.default_reductions", "accepting");
     free (lr_type);
   }
 
@@ -571,7 +571,7 @@ reader (void)
   {
     static char const * const values[] = {
       "lr.type", "LALR", "IELR", "canonical LR", NULL,
-      "lr.default_rules", "all", "consistent", "accepting", NULL,
+      "lr.default_reductions", "all", "consistent", "accepting", NULL,
       NULL
     };
     muscle_percent_define_check_values (values);
diff --git a/src/tables.c b/src/tables.c
index 958e77b..186c1fe 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -240,7 +240,7 @@ static rule *
 action_row (state *s)
 {
   int i;
-  rule *default_rule = NULL;
+  rule *default_reduction = NULL;
   reductions *reds = s->reductions;
   transitions *trans = s->transitions;
   errs *errp = s->errs;
@@ -304,14 +304,15 @@ action_row (state *s)
       actrow[sym->number] = ACTION_NUMBER_MINIMUM;
     }
 
-  /* Turn off default rules where requested by the user.  See
+  /* Turn off default reductions where requested by the user.  See
      state_lookahead_tokens_count in lalr.c to understand when states are
      labeled as consistent.  */
   {
-    char *default_rules = muscle_percent_define_get ("lr.default_rules");
-    if (0 != strcmp (default_rules, "all") && !s->consistent)
+    char *default_reductions =
+      muscle_percent_define_get ("lr.default_reductions");
+    if (0 != strcmp (default_reductions, "all") && !s->consistent)
       nodefault = true;
-    free (default_rules);
+    free (default_reductions);
   }
 
   /* Now find the most common reduction and make it the default action
@@ -320,7 +321,7 @@ action_row (state *s)
   if (reds->num >= 1 && !nodefault)
     {
       if (s->consistent)
-       default_rule = reds->rules[0];
+       default_reduction = reds->rules[0];
       else
        {
          int max = 0;
@@ -337,7 +338,7 @@ action_row (state *s)
              if (count > max)
                {
                  max = count;
-                 default_rule = r;
+                 default_reduction = r;
                }
            }
 
@@ -351,17 +352,18 @@ action_row (state *s)
            {
              int j;
              for (j = 0; j < ntokens; j++)
-               if (actrow[j] == rule_number_as_item_number 
(default_rule->number)
+               if (actrow[j]
+                    == rule_number_as_item_number (default_reduction->number)
                    && ! (nondeterministic_parser && conflrow[j]))
                  actrow[j] = 0;
            }
        }
     }
 
-  /* If have no default rule, the default is an error.
+  /* If have no default reduction, the default is an error.
      So replace any action which says "error" with "use default".  */
 
-  if (!default_rule)
+  if (!default_reduction)
     for (i = 0; i < ntokens; i++)
       if (actrow[i] == ACTION_NUMBER_MINIMUM)
        actrow[i] = 0;
@@ -369,7 +371,7 @@ action_row (state *s)
   if (conflicted)
     conflict_row (s);
 
-  return default_rule;
+  return default_reduction;
 }
 
 
@@ -450,8 +452,8 @@ token_actions (void)
 
   for (i = 0; i < nstates; ++i)
     {
-      rule *default_rule = action_row (states[i]);
-      yydefact[i] = default_rule ? default_rule->number + 1 : 0;
+      rule *default_reduction = action_row (states[i]);
+      yydefact[i] = default_reduction ? default_reduction->number + 1 : 0;
       save_row (i);
 
       /* Now that the parser was computed, we can find which rules are
diff --git a/src/tables.h b/src/tables.h
index b0fbe9a..a44cdb8 100644
--- a/src/tables.h
+++ b/src/tables.h
@@ -1,5 +1,5 @@
 /* Prepare the LALR and GLR parser tables.
-   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -45,9 +45,9 @@
 
    YYSTOS[S] = the symbol number of the symbol that leads to state S.
 
-   YYDEFACT[S] = default rule to reduce with in state s, when YYTABLE
-   doesn't specify something else to do.  Zero means the default is an
-   error.
+   YYDEFACT[S] = default reduction number in state s.  Performed when
+   YYTABLE doesn't specify something else to do.  Zero means the default
+   is an error.
 
    YYDEFGOTO[I] = default state to go to after a reduction of a rule
    that generates variable NTOKENS + I, except when YYTABLE specifies
diff --git a/tests/input.at b/tests/input.at
index 9edf613..9fa8af7 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -867,20 +867,20 @@ AT_BISON_CHECK([[Input.y]], [1], [],
 
 AT_CLEANUP
 
-## ----------------------------------------- ##
-## %define lr.default_rules invalid values.  ##
-## ----------------------------------------- ##
+## ---------------------------------------------- ##
+## %define lr.default_reductions invalid values.  ##
+## ---------------------------------------------- ##
 
-AT_SETUP([[%define lr.default_rules invalid values]])
+AT_SETUP([[%define lr.default_reductions invalid values]])
 
 AT_DATA([[input.y]],
-[[%define lr.default_rules "bogus"
+[[%define lr.default_reductions "bogus"
 %%
 start: ;
 ]])
 
 AT_BISON_CHECK([[input.y]], [[1]], [[]],
-[[input.y:1.9-24: invalid value for %define variable `lr.default_rules': 
`bogus'
+[[input.y:1.9-29: invalid value for %define variable `lr.default_reductions': 
`bogus'
 ]])
 
 AT_CLEANUP
diff --git a/tests/reduce.at b/tests/reduce.at
index 6642f65..a3d1e27 100644
--- a/tests/reduce.at
+++ b/tests/reduce.at
@@ -1442,33 +1442,33 @@ dnl PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR
 
 
 
-## -------------------------- ##
-## %define lr.default_rules.  ##
-## -------------------------- ##
+## ------------------------------- ##
+## %define lr.default_reductions.  ##
+## ------------------------------- ##
 
-# AT_TEST_LR_DEFAULT_RULES(GRAMMAR, INPUT, TABLES)
-# ------------------------------------------------
-m4_define([AT_TEST_LR_DEFAULT_RULES],
+# AT_TEST_LR_DEFAULT_REDUCTIONS(GRAMMAR, INPUT, TABLES)
+# -----------------------------------------------------
+m4_define([AT_TEST_LR_DEFAULT_REDUCTIONS],
 [
-AT_TEST_TABLES_AND_PARSE([[no %define lr.default_rules]],
+AT_TEST_TABLES_AND_PARSE([[no %define lr.default_reductions]],
                          [[all]], [[]],
                          [[]],
                          [$1], [$2], [[]], [$3])
-AT_TEST_TABLES_AND_PARSE([[%define lr.default_rules "all"]],
+AT_TEST_TABLES_AND_PARSE([[%define lr.default_reductions "all"]],
                          [[all]], [[]],
-                         [[%define lr.default_rules "all"]],
+                         [[%define lr.default_reductions "all"]],
                          [$1], [$2], [[]], [$3])
-AT_TEST_TABLES_AND_PARSE([[%define lr.default_rules "consistent"]],
+AT_TEST_TABLES_AND_PARSE([[%define lr.default_reductions "consistent"]],
                          [[consistent]], [[]],
-                         [[%define lr.default_rules "consistent"]],
+                         [[%define lr.default_reductions "consistent"]],
                          [$1], [$2], [[]], [$3])
-AT_TEST_TABLES_AND_PARSE([[%define lr.default_rules "accepting"]],
+AT_TEST_TABLES_AND_PARSE([[%define lr.default_reductions "accepting"]],
                          [[accepting]], [[]],
-                         [[%define lr.default_rules "accepting"]],
+                         [[%define lr.default_reductions "accepting"]],
                          [$1], [$2], [[]], [$3])
 ])
 
-AT_TEST_LR_DEFAULT_RULES([[
+AT_TEST_LR_DEFAULT_REDUCTIONS([[
 /* The start state is consistent and has a shift on 'a' and no reductions.
    After pushing the b below, enter an inconsistent state that has a shift and
    one reduction with one lookahead.  */
@@ -1484,7 +1484,7 @@ a: 'a' ;
 
 /* After the previous reduction, enter an inconsistent state that has no shift
    and multiple reductions.  The first reduction has more lookaheads than the
-   second, so the first should always be preferred as the default rule if
+   second, so the first should always be preferred as the default reduction if
    enabled.  The second reduction has one lookahead.  */
 b: ;
 c: ;
-- 
1.5.4.3





reply via email to

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