From 9f69b006dde3c3fbe19ed3e0275d3b7348f2aa87 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 15 Mar 2020 18:19:49 +0100 Subject: New lexer --- cppbnf.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'cppbnf.cpp') diff --git a/cppbnf.cpp b/cppbnf.cpp index 0b6e58f..4818fc3 100755 --- a/cppbnf.cpp +++ b/cppbnf.cpp @@ -39,11 +39,6 @@ namespace { return result; } - bool isTerminal(const std::string& symbol, const BNF& bnf) - { - return bnf.find(symbol) == bnf.end(); - } - size_t numberOfStartSymbols(const BNF& bnf) { // exactly 1 start symbol @@ -75,7 +70,7 @@ namespace { for (const auto& list : lists) { for (const auto& i : list) { - if (!isTerminal(i, bnf)) { + if (!isTerminal(bnf, i)) { // every non-terminal symbol must be longer that 1 char if (i.size() == 1) { std::cerr << "Warning: Non-Terminal symbol " << i << " in " << symbol << " is too short." << std::endl; @@ -107,7 +102,7 @@ namespace { for (const auto& [symbol, lists] : bnf) { for (const auto& list : lists) { for (const auto& i : list) { - if (i.size() != 1 && isTerminal(i, bnf)) { + if (i.size() != 1 && isTerminal(bnf, i)) { std::cerr << "Warning: Terminal symbol in " << symbol << " is too long: "s << i << std::endl; return false; } @@ -197,7 +192,7 @@ namespace { for (auto& [symbol, lists] : bnf) { for (auto& list : lists) { for (int i = 0; i < list.size(); i++) { - if (list[i].size() > 1 && isTerminal(list[i], bnf)) { + if (list[i].size() > 1 && isTerminal(bnf, list[i])) { auto newList = vectorize(list[i]); list.erase(list.begin() + i); list.insert(list.begin() + i, newList.begin(), newList.end()); -- cgit v1.2.3