#include "Parsodus/lrtables/generator.h" #include "Parsodus/lrtables/LR1Itemset.h" #include "Parsodus/lrtables/LALR1Itemset.h" #include "gtest/gtest.h" #include TEST(lr1, only) { using namespace pds; Grammar grammar; grammar.start = "s"; grammar.variables = {"s","a","b"}; grammar.terminals = {"A", "B"}; for (const std::pair>& p : std::initializer_list>>({ {"s", {"B", "a", "A"}}, {"s", {"b", "A"}}, {"s", {"a"}}, {"s", {"B", "b"}}, {"a", {"A"}}, {"b", {"A"}} })) { auto r = std::make_shared(); r->head = p.first; r->tail = p.second; grammar.rules.emplace_back(std::move(r)); } { pds::lr::Generator g(grammar); ASSERT_NO_THROW(g.generate()); } { pds::lr::Generator g(grammar); ASSERT_THROW(g.generate(), std::runtime_error); try { g.generate(); } catch (std::runtime_error& e) { ASSERT_EQ(std::string("reduce-reduce"), e.what()); } } }