Basic LR(1) but not LALR(1) test
This commit is contained in:
parent
e1208101b9
commit
ed9c1cd0c9
|
@ -1,5 +1,6 @@
|
|||
add_executable(Parsodus-test
|
||||
lr0_shift-red.cpp
|
||||
lr1_only.cpp
|
||||
)
|
||||
target_link_libraries(Parsodus-test
|
||||
# Parsodus-backends
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include "Parsodus/lrtables/generator.h"
|
||||
#include "Parsodus/lrtables/LR1Itemset.h"
|
||||
#include "Parsodus/lrtables/LALR1Itemset.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
TEST(lr1, only) {
|
||||
using namespace pds;
|
||||
|
||||
Grammar grammar;
|
||||
grammar.start = "s";
|
||||
grammar.variables = {"s","a","b"};
|
||||
grammar.terminals = {"A", "B"};
|
||||
|
||||
for (const std::pair<std::string, std::vector<std::string>>& p : std::initializer_list<std::pair<std::string, std::vector<std::string>>>({
|
||||
{"s", {"B", "a", "A"}},
|
||||
{"s", {"b", "A"}},
|
||||
{"s", {"a"}},
|
||||
{"s", {"B", "b"}},
|
||||
{"a", {"A"}},
|
||||
{"b", {"A"}}
|
||||
})) {
|
||||
auto r = std::make_shared<Rule>();
|
||||
r->head = p.first;
|
||||
r->tail = p.second;
|
||||
grammar.rules.emplace_back(std::move(r));
|
||||
}
|
||||
|
||||
{
|
||||
pds::lr::Generator<lr::LR1Itemset> g(grammar);
|
||||
ASSERT_NO_THROW(g.generate());
|
||||
}
|
||||
|
||||
{
|
||||
pds::lr::Generator<pds::lr::LALR1Itemset> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue