Skip to content

Commit

Permalink
realized parser is not actually lalr(?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raekye committed Jul 27, 2019
1 parent cc4f9d8 commit 1130d96
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
25 changes: 25 additions & 0 deletions midori/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,39 @@ int test_generator() {
return 0;
}

int test_lalr() {
ProductionHandler fn = [](MatchedNonterminal* m) -> std::unique_ptr<ParserAST> {
(void) m;
return nullptr;
};
Parser p;
p.add_token("EQUALS", std::unique_ptr<RegexAST>(new RegexASTLiteral('=')));
p.add_token("STAR", std::unique_ptr<RegexAST>(new RegexASTLiteral('*')));
p.add_token("ID", std::unique_ptr<RegexAST>(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;
}
2 changes: 1 addition & 1 deletion midori/src/midori/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
8 changes: 8 additions & 0 deletions midori/src/midori/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemSet> const& i : this->states) {
for (std::map<std::string, ItemSet*>::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<MatchedNonterminal> Parser::parse(IInputStream* in) {
Expand Down

0 comments on commit 1130d96

Please sign in to comment.