mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
Allow %start after the first rule.
* src/reader.c (grammar_current_rule_begin): Don't set the start symbol when parsing the first rule. (check_and_convert_grammar): Search for it here after all grammar declarations have been parsed. Skip midrules, which have dummy LHS nonterminals. * src/symtab.c (symbol_is_dummy): New function. * src/symtab.h (symbol_is_dummy): Declare it. * tests/input.at (%start after first rule): New test.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
2006-08-19 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
|
Allow %start after the first rule.
|
||||||
|
* src/reader.c (grammar_current_rule_begin): Don't set the start symbol
|
||||||
|
when parsing the first rule.
|
||||||
|
(check_and_convert_grammar): Search for it here after all grammar
|
||||||
|
declarations have been parsed. Skip midrules, which have dummy LHS
|
||||||
|
nonterminals.
|
||||||
|
* src/symtab.c (symbol_is_dummy): New function.
|
||||||
|
* src/symtab.h (symbol_is_dummy): Declare it.
|
||||||
|
* tests/input.at (%start after first rule): New test.
|
||||||
|
|
||||||
2006-08-18 Joel E. Denny <jdenny@ces.clemson.edu>
|
2006-08-18 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
Redo some of the previous commit: add back the ability to use
|
Redo some of the previous commit: add back the ability to use
|
||||||
|
|||||||
24
src/reader.c
24
src/reader.c
@@ -225,13 +225,6 @@ static symbol_list *previous_rule_end = NULL;
|
|||||||
void
|
void
|
||||||
grammar_current_rule_begin (symbol *lhs, location loc)
|
grammar_current_rule_begin (symbol *lhs, location loc)
|
||||||
{
|
{
|
||||||
if (!start_flag)
|
|
||||||
{
|
|
||||||
startsymbol = lhs;
|
|
||||||
startsymbol_location = loc;
|
|
||||||
start_flag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start a new rule and record its lhs. */
|
/* Start a new rule and record its lhs. */
|
||||||
++nrules;
|
++nrules;
|
||||||
previous_rule_end = grammar_end;
|
previous_rule_end = grammar_end;
|
||||||
@@ -607,6 +600,23 @@ check_and_convert_grammar (void)
|
|||||||
endtoken->user_token_number = 0;
|
endtoken->user_token_number = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Find the start symbol if no %start. */
|
||||||
|
if (!start_flag)
|
||||||
|
{
|
||||||
|
symbol_list *node;
|
||||||
|
for (node = grammar;
|
||||||
|
node != NULL && symbol_is_dummy (node->sym);
|
||||||
|
node = node->next)
|
||||||
|
{
|
||||||
|
for (node = node->next;
|
||||||
|
node != NULL && node->sym != NULL;
|
||||||
|
node = node->next)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
assert (node != NULL);
|
||||||
|
grammar_start_symbol_set (node->sym, node->sym->location);
|
||||||
|
}
|
||||||
|
|
||||||
/* Insert the initial rule, whose line is that of the first rule
|
/* Insert the initial rule, whose line is that of the first rule
|
||||||
(not that of the start symbol):
|
(not that of the start symbol):
|
||||||
|
|
||||||
|
|||||||
@@ -615,6 +615,11 @@ dummy_symbol_get (location loc)
|
|||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
symbol_is_dummy (const symbol *sym)
|
||||||
|
{
|
||||||
|
return sym->tag[0] == '@';
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------.
|
/*-------------------.
|
||||||
| Free the symbols. |
|
| Free the symbols. |
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ symbol *symbol_get (const char *key, location loc);
|
|||||||
Its name cannot conflict with the user's names. */
|
Its name cannot conflict with the user's names. */
|
||||||
symbol *dummy_symbol_get (location loc);
|
symbol *dummy_symbol_get (location loc);
|
||||||
|
|
||||||
|
/** Is this a dummy nonterminal? */
|
||||||
|
bool symbol_is_dummy (const symbol *sym);
|
||||||
|
|
||||||
/** Declare the new symbol \c sym. Make it an alias of \c symval. */
|
/** Declare the new symbol \c sym. Make it an alias of \c symval. */
|
||||||
void symbol_make_alias (symbol *sym, symbol *symval, location loc);
|
void symbol_make_alias (symbol *sym, symbol *symval, location loc);
|
||||||
|
|
||||||
|
|||||||
@@ -537,3 +537,24 @@ input.y:20.1: syntax error, unexpected end of file, expecting ;
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
## ------------------------- ##
|
||||||
|
## %start after first rule. ##
|
||||||
|
## ------------------------- ##
|
||||||
|
|
||||||
|
AT_SETUP([%start after first rule])
|
||||||
|
|
||||||
|
# Bison once complained that a %start after the first rule was a redeclaration
|
||||||
|
# of the start symbol.
|
||||||
|
|
||||||
|
AT_DATA([input.y],
|
||||||
|
[[%%
|
||||||
|
false_start: ;
|
||||||
|
start: false_start ;
|
||||||
|
%start start;
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_CHECK([bison -o input.c input.y])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user