diff options
Diffstat (limited to 'grammer.cpp')
| -rw-r--r-- | grammer.cpp | 32 | 
1 files changed, 16 insertions, 16 deletions
| diff --git a/grammer.cpp b/grammer.cpp index 8f2b42b..8a4f6b7 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -58,20 +58,20 @@ bool Compiler::RootIsStartSymbol() const  namespace { -bool ChildIdIsToken(int32_t child_id) -{ - return child_i < 0; -} + bool ChildIdIsToken(int32_t child_id) + { +  return child_id < 0; + } -index_t TokenIdFromChildId(int32_t child_id) -{ - return index_t(-child_id) - 1; -} + index_t TokenIdFromChildId(int32_t child_id) + { +  return index_t(-child_id) - 1; + } -int32_t ChildIdFromTokenId(index_t token_id) -{ - return -1 - int32_t(token_id); -} + int32_t ChildIdFromTokenId(index_t token_id) + { +  return -1 - int32_t(token_id); + }  } // namespace @@ -123,7 +123,7 @@ void Compiler::AddFirstNode()   const std::string& child_type = tokens[0].type;   auto it = ReverseBNF.find(child_type);   if (it == ReverseBNF.end()) -  throw std::runtime_error("Type not found: "s + child_type + " ("s + tokens[0].value + ")"s); +  throw std::runtime_error("Illegal first token: "s + child_type + " ("s + tokens[0].value + ")"s);   std::set<std::string>& alternatives_set {it->second}; @@ -150,7 +150,7 @@ void Compiler::AddFirstNode()   }   if (node_type == "") // no matching type found -  throw std::runtime_error("No matching first node found."); +  throw std::runtime_error("Syntax error on first token: "s + child_type + " ("s + tokens[0].value + ")"s);   nodes.emplace_back({0, 0, node_type, node_variant, alternatives, child_ids}); @@ -169,14 +169,13 @@ bool Compiler::AddRootNode()    index_t old_root_node_id {root_node_id};    index_t new_root_node_id {nodes.size()}; -  nodes[root_node_id].parent_node_id = new_root_node_id;    std::set<std::string>& alternatives_set {it->second};    std::string node_type;    index_t node_variant;    std::deque<std::pair<std::string, index_t>> alternatives; // only for valid elements from alternatives_set -  std::vector<index_t> child_ids{1, old_root_node_id}; +  std::vector<index_t> child_ids{size_t(1), old_root_node_id};    for (const auto& type : alternatives_set) {     const auto& variants{bnf[type]}; @@ -196,6 +195,7 @@ bool Compiler::AddRootNode()     return false;    // now add!  +  nodes[old_root_node_id].parent_node_id = new_root_node_id;    root_node_id = new_root_node_id;    nodes.emplace_back({root_node_id, root_node_id, node_type, node_variant, alternatives, child_ids});    // keep tokens_used as is | 
