diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-03-23 22:19:36 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-03-23 22:19:36 +0100 | 
| commit | 0e1d2ab5ca0f0fde5d2dd83b95230a8d93b58e7b (patch) | |
| tree | 13ca0dd1300f35d3bee94f0d7a1ff171cdcd26d7 | |
| parent | fce1c18103f208857af477ca47af9aa908bd69b6 (diff) | |
BNF match (WIP: return nodes)
| -rw-r--r-- | grammer.cpp | 13 | ||||
| -rw-r--r-- | test-cpp.cpp | 4 | 
2 files changed, 5 insertions, 12 deletions
| 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<std::string> 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<std::string> symbol_list, size_t begin, size_t   auto it{bnf.find(symbol_list.front())};   if (it != bnf.end()) {    for (std::vector<std::string> 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? diff --git a/test-cpp.cpp b/test-cpp.cpp index 6727966..2a67b38 100644 --- a/test-cpp.cpp +++ b/test-cpp.cpp @@ -30,7 +30,7 @@ protected:   }  }; -#if 0 +#if 1  TEST_F(CppTest, preprocessing_tokenize) {   CPP cpp;   auto pp_tokens = cpp.preprocessing_tokenize("int main() { return 1; }"); @@ -40,7 +40,7 @@ TEST_F(CppTest, preprocessing_tokenize) {   auto tokens = cpp.tokens_from_pptokens(pp_tokens);   ASSERT_EQ(tokens.size(), 9); -#if 1 +#if 0   for (auto &i: tokens) {    std::cout << i.type << ": " << i.value << std::endl;   } | 
