Small cleanup for existing test

This commit is contained in:
Robin Jadoul 2017-01-11 17:24:36 +01:00
parent 2e95d671bf
commit aa1ff29307
1 changed files with 23 additions and 15 deletions

View File

@ -15,42 +15,50 @@ TEST(lr0, test0) {
pds::Grammar grammar;
grammar.start = "S'";
grammar.variables = {"S'","S","A","E"};
grammar.terminals = {"$",";", "id", ":=", "+"};
grammar.start = "S";
grammar.variables = {"S","A","E"};
grammar.terminals = {";", "id", ":=", "+"};
std::shared_ptr<pds::Rule> rule(new pds::Rule());
rule->head = "S'";
rule->tail = {"S","$"};
grammar.rules.push_back(rule);
rule->head = "S";
rule->tail = {"S",";","A"};
grammar.rules.push_back(rule);
grammar.rules.push_back(std::make_shared<pds::Rule>(*rule));
rule->head = "S";
rule->tail = {"A"};
grammar.rules.push_back(rule);
grammar.rules.push_back(std::make_shared<pds::Rule>(*rule));
rule->head = "A";
rule->tail = {"E"};
grammar.rules.push_back(rule);
grammar.rules.push_back(std::make_shared<pds::Rule>(*rule));
rule->head = "A";
rule->tail = {"id",":=","E"};
grammar.rules.push_back(rule);
grammar.rules.push_back(std::make_shared<pds::Rule>(*rule));
rule->head = "E";
rule->tail = {"E","+","id"};
grammar.rules.push_back(rule);
grammar.rules.push_back(std::make_shared<pds::Rule>(*rule));
rule->head = "E";
rule->tail = {"id"};
grammar.rules.push_back(rule);
grammar.rules.push_back(std::make_shared<pds::Rule>(*rule));
pds::lr::Generator<pds::lr::SLR1Itemset> g(grammar);
auto tbl = g.generate(); // LRTable
{
pds::lr::Generator<pds::lr::LR0Itemset> g(grammar);
ASSERT_THROW(g.generate(), std::runtime_error);
try {
g.generate();
} catch (std::runtime_error& e) {
ASSERT_EQ(std::string("shift-reduce"), e.what());
}
}
{
pds::lr::Generator<pds::lr::SLR1Itemset> g(grammar);
ASSERT_NO_THROW(g.generate());
}
// auto tbl = g.generate(); // LRTable
// EXPECT_THROW(throw "shift-reduce", std::exception);
/*