diff --git a/midori/src/main.cpp b/midori/src/main.cpp index 3ea4f8e..4c92c7c 100644 --- a/midori/src/main.cpp +++ b/midori/src/main.cpp @@ -123,14 +123,39 @@ int test_generator() { return 0; } +int test_lalr() { + ProductionHandler fn = [](MatchedNonterminal* m) -> std::unique_ptr { + (void) m; + return nullptr; + }; + Parser p; + p.add_token("EQUALS", std::unique_ptr(new RegexASTLiteral('='))); + p.add_token("STAR", std::unique_ptr(new RegexASTLiteral('*'))); + p.add_token("ID", std::unique_ptr(new RegexASTLiteral('i'))); + p.add_production("s", { "l", "EQUALS", "r" }, fn); + p.add_production("s", { "r" }, fn); + p.add_production("l", { "STAR", "r" }, fn); + p.add_production("l", { "ID" }, fn); + p.add_production("r", { "l" }, fn); + p.generate("s"); + std::stringstream ss; + ss << "*id=id"; + FileInputStream fis(&ss); + p.parse(&fis); + return 0; +} + int main() { ULong x = ~0; std::cout << "-1 is " << x << std::endl; + /* test_interval_tree(); test_parser0(); test_parser2(); test_parser1(); test_generator(); test_regex_engine(); + */ + test_lalr(); return 0; } diff --git a/midori/src/midori/CMakeLists.txt b/midori/src/midori/CMakeLists.txt index 311bf0c..3a241d9 100644 --- a/midori/src/midori/CMakeLists.txt +++ b/midori/src/midori/CMakeLists.txt @@ -7,7 +7,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/regex_engine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/glr.cpp + #${CMAKE_CURRENT_SOURCE_DIR}/glr.cpp ) add_library(midori SHARED ${SOURCES}) diff --git a/midori/src/midori/parser.cpp b/midori/src/midori/parser.cpp index d0c5bff..696eeba 100644 --- a/midori/src/midori/parser.cpp +++ b/midori/src/midori/parser.cpp @@ -59,6 +59,14 @@ void Parser::generate(std::string start) { this->generate_first_sets(); this->generate_follow_sets(); this->generate_itemsets(); + + for (std::unique_ptr const& i : this->states) { + for (std::map::value_type it : i->next) { + if (i->reductions.find(it.first) != i->reductions.end()) { + std::cout << "Shift reduce conflict at state " << i->index << " for " << it.first << std::endl; + } + } + } } std::unique_ptr Parser::parse(IInputStream* in) {