summaryrefslogtreecommitdiffhomepage
path: root/grammer.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-03-23 22:19:36 +0100
committerRoland Reichwein <mail@reichwein.it>2020-03-23 22:19:36 +0100
commit0e1d2ab5ca0f0fde5d2dd83b95230a8d93b58e7b (patch)
tree13ca0dd1300f35d3bee94f0d7a1ff171cdcd26d7 /grammer.cpp
parentfce1c18103f208857af477ca47af9aa908bd69b6 (diff)
BNF match (WIP: return nodes)
Diffstat (limited to 'grammer.cpp')
-rw-r--r--grammer.cpp13
1 files changed, 3 insertions, 10 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?