mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
multistart: turn start symbols into rules on $accept
Now that the parser can read several start symbols, let's process them, and create the corresponding rules. * src/parse-gram.y (grammar_declaration): Accept a list of start symbols. * src/reader.h, src/reader.c (grammar_start_symbol_set): Rename as... (grammar_start_symbols_set): this. * src/reader.h, src/reader.c (start_flag): Replace with... (start_symbols): this. * src/reader.c (grammar_start_symbols_set): Build a list of start symbols. (switching_token, create_start_rules): New. (check_and_convert_grammar): Use them to turn the list of start symbols into a set of rules. * src/reduce.c (nonterminals_reduce): Don't complain about $accept, it's an internal detail. (reduce_grammar): Complain about all the start symbols that don't derive sentences. * src/symtab.c (startsymbol, startsymbol_loc): Remove, replaced by start_symbols. symbols_pack): Move the check about the start symbols to... * src/symlist.c (check_start_symbols): here. Adjust to multiple start symbols. * tests/reduce.at (Empty Language): Generalize into... (Bad start symbols): this.
This commit is contained in:
@@ -445,23 +445,69 @@ AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## ---------------- ##
|
||||
## Empty Language. ##
|
||||
## ---------------- ##
|
||||
## ------------------- ##
|
||||
## Bad start symbols. ##
|
||||
## ------------------- ##
|
||||
|
||||
AT_SETUP([Empty Language])
|
||||
AT_SETUP([Bad start symbols])
|
||||
|
||||
m4_pushdef([AT_TEST],
|
||||
[
|
||||
AT_DATA([[input.y]],
|
||||
[[%output "input.c"
|
||||
%%
|
||||
exp: exp;
|
||||
]])
|
||||
[%%
|
||||
$1
|
||||
])
|
||||
|
||||
AT_BISON_CHECK([[input.y]], 1, [],
|
||||
[$2
|
||||
])
|
||||
])
|
||||
|
||||
AT_TEST(
|
||||
[[exp: exp;]],
|
||||
[[input.y: warning: 2 nonterminals useless in grammar [-Wother]
|
||||
input.y: warning: 2 rules useless in grammar [-Wother]
|
||||
input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
|
||||
]])
|
||||
input.y:2.1-3: error: start symbol exp does not derive any sentence]])
|
||||
|
||||
AT_TEST(
|
||||
[[%start exp;
|
||||
exp: exp;]],
|
||||
[[input.y: warning: 2 nonterminals useless in grammar [-Wother]
|
||||
input.y: warning: 2 rules useless in grammar [-Wother]
|
||||
input.y:2.8-10: error: start symbol exp does not derive any sentence]])
|
||||
|
||||
AT_TEST(
|
||||
[[%start exp stmt;
|
||||
exp: exp;
|
||||
stmt: "stmt"]],
|
||||
[[input.y: warning: 1 nonterminal useless in grammar [-Wother]
|
||||
input.y: warning: 2 rules useless in grammar [-Wother]
|
||||
input.y:2.8-10: error: start symbol exp does not derive any sentence]])
|
||||
|
||||
AT_TEST(
|
||||
[[%start exp stmt;
|
||||
exp: exp;
|
||||
stmt: stmt]],
|
||||
[[input.y: warning: 3 nonterminals useless in grammar [-Wother]
|
||||
input.y: warning: 4 rules useless in grammar [-Wother]
|
||||
input.y:2.8-10: error: start symbol exp does not derive any sentence
|
||||
input.y:2.12-15: error: start symbol stmt does not derive any sentence]])
|
||||
|
||||
AT_TEST(
|
||||
[[%start exp;
|
||||
stmt: stmt]],
|
||||
[[input.y:2.8-10: warning: symbol 'exp' is used, but is not defined as a token and has no rules [-Wother]
|
||||
input.y: warning: 3 nonterminals useless in grammar [-Wother]
|
||||
input.y: warning: 2 rules useless in grammar [-Wother]
|
||||
input.y:2.8-10: error: start symbol exp does not derive any sentence]])
|
||||
|
||||
AT_TEST(
|
||||
[[%token FOO;
|
||||
%start FOO;
|
||||
stmt: FOO]],
|
||||
[[input.y:2.8-10: error: the start symbol FOO is a token]])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user