mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 01:03:04 +00:00
Implement %define lr.default_rules.
Its value describes the states that are permitted to contain default rules: "all", "consistent", or "accepting". * src/reader.c (reader): Default lr.default_rules to "all". Check for a valid lr.default_rules value. * src/lalr.c (state_lookahead_tokens_count): If lr.default_rules is "accepting", then only mark the accepting state as consistent. (initialize_LA): Tell state_lookahead_tokens_count whether lr.default_rules is "accepting". * src/tables.c (action_row): If lr.default_rules is not "all", then disable default rules in inconsistent states. * src/print.c (print_reductions): Use this opportunity to perform some assertions about whether lr.default_rules was obeyed correctly. * tests/local.at (AT_TEST_TABLES_AND_PARSE): New macro that helps with checking the parser tables for a grammar. * tests/input.at (%define lr.default_rules invalid values): New test group. * tests/reduce.at (AT_TEST_LR_DEFAULT_RULES): New macro using AT_TEST_TABLES_AND_PARSE. (`no %define lr.default_rules'): New test group generated by AT_TEST_LR_DEFAULT_RULES. (`%define lr.default_rules "all"'): Likewise. (`%define lr.default_rules "consistent"'): Likewise. (`%define lr.default_rules "accepting"'): Likewise.
This commit is contained in:
29
src/print.c
29
src/print.c
@@ -1,7 +1,7 @@
|
||||
/* Print information on generated parser, for bison,
|
||||
|
||||
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009
|
||||
Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "getargs.h"
|
||||
#include "gram.h"
|
||||
#include "lalr.h"
|
||||
#include "muscle-tab.h"
|
||||
#include "print.h"
|
||||
#include "reader.h"
|
||||
#include "reduce.h"
|
||||
@@ -244,6 +245,7 @@ print_reductions (FILE *out, state *s)
|
||||
rule *default_rule = NULL;
|
||||
size_t width = 0;
|
||||
int i, j;
|
||||
bool non_default_action = false;
|
||||
|
||||
if (reds->num == 0)
|
||||
return;
|
||||
@@ -296,6 +298,8 @@ print_reductions (FILE *out, state *s)
|
||||
{
|
||||
bool defaulted = false;
|
||||
bool count = bitset_test (no_reduce_set, i);
|
||||
if (count)
|
||||
non_default_action = true;
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
@@ -303,15 +307,19 @@ print_reductions (FILE *out, state *s)
|
||||
if (! count)
|
||||
{
|
||||
if (reds->rules[j] != default_rule)
|
||||
print_reduction (out, width,
|
||||
symbols[i]->tag,
|
||||
reds->rules[j], true);
|
||||
{
|
||||
non_default_action = true;
|
||||
print_reduction (out, width,
|
||||
symbols[i]->tag,
|
||||
reds->rules[j], true);
|
||||
}
|
||||
else
|
||||
defaulted = true;
|
||||
count = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
non_default_action = true;
|
||||
if (defaulted)
|
||||
print_reduction (out, width,
|
||||
symbols[i]->tag,
|
||||
@@ -325,8 +333,15 @@ print_reductions (FILE *out, state *s)
|
||||
}
|
||||
|
||||
if (default_rule)
|
||||
print_reduction (out, width,
|
||||
_("$default"), default_rule, true);
|
||||
{
|
||||
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")
|
||||
&& !non_default_action)
|
||||
|| (reds->num == 1 && reds->rules[0]->number == 0));
|
||||
free (default_rules);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user