From 0e1d2ab5ca0f0fde5d2dd83b95230a8d93b58e7b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 23 Mar 2020 22:19:36 +0100 Subject: BNF match (WIP: return nodes) --- grammer.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'grammer.cpp') diff --git a/grammer.cpp b/grammer.cpp index cc285b9..4bcdd4d 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -38,7 +38,8 @@ void Compiler::Validate() const { // A program is non empty if (nodes.size() == 0) - throw std::runtime_error(""); + return; + //throw std::runtime_error("Program is empty"); // Consistency check for nodes if (root_node_id >= nodes.size()) @@ -539,12 +540,6 @@ bool Compiler::match(std::vector symbol_list, size_t begin, size_t { // TODO: isTerminal() necessary here? - std::cout << "DEBUG: Matching:"; - for (auto symbol: symbol_list) { - std::cout << " |" << symbol << "|"; - } - std::cout << std::endl; - // match terminal symbols at start while (begin < end && isTerminal(bnf, tokens[begin].type) && symbol_list.size() > 0 && symbol_list.front() == tokens[begin].type) { begin++; @@ -570,10 +565,8 @@ bool Compiler::match(std::vector symbol_list, size_t begin, size_t auto it{bnf.find(symbol_list.front())}; if (it != bnf.end()) { for (std::vector list: it->second) { // iterate over alternatives - std::cout << "ALTERNATIVE for " << symbol_list.front() << " with " << list.size() << std::endl; list.insert(list.end(), symbol_list.begin() + 1, symbol_list.end()); - std::cout << "Min: " << minimumSymbolsNeeded(list) << ", end-begin: " << (end-begin) << std::endl; - if (minimumSymbolsNeeded(list) > end - begin) // stop recursion + if (minimumSymbolsNeeded(list) > end - begin) // stop recursion continue; // TODO: recurse last? -- cgit v1.2.3