summaryrefslogtreecommitdiffhomepage
path: root/grammer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'grammer.cpp')
-rw-r--r--grammer.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/grammer.cpp b/grammer.cpp
index 4bdf8f4..8f2b42b 100644
--- a/grammer.cpp
+++ b/grammer.cpp
@@ -22,7 +22,8 @@ bool Compiler::IsRootNode(index_t node_id) const
return node.parent_node_id == node.node_id;
}
-void Compiler::Validate() const {
+void Compiler::Validate() const
+{
// A program is non empty
if (nodes.size() == 0)
throw std::runtime_error("");
@@ -50,11 +51,13 @@ void Compiler::DumpTree()
}
}
-bool RootIsStartSymbol()
+bool Compiler::RootIsStartSymbol() const
{
return GetTypeOfNode(root_node_id) == Top;
}
+namespace {
+
bool ChildIdIsToken(int32_t child_id)
{
return child_i < 0;
@@ -70,12 +73,14 @@ int32_t ChildIdFromTokenId(index_t token_id)
return -1 - int32_t(token_id);
}
-bool AllTokensUsed()
+} // namespace
+
+bool Compiler::AllTokensUsed() const
{
return tokens_used == tokens.size();
}
-bool Compiler::treeIsComplete()
+bool Compiler::treeIsComplete() const
{
return RootIsStartSymbol() && AllTokensUsed();
}
@@ -199,7 +204,7 @@ bool Compiler::AddRootNode()
return true;
}
-void RemoveLastNode()
+void Compiler::RemoveLastNode()
{
TreeNode& node {nodes.back()};
index_t node_id = node.node_id;
@@ -225,7 +230,7 @@ void RemoveLastNode()
}
// Change type of last node according to alternatives
-void ChangeNodeType()
+void Compiler::ChangeNodeType()
{
TreeNode& node {nodes.back()};
index_t node_id = node.node_id;
@@ -289,7 +294,8 @@ std::map<std::string, std::string> Compiler::traverse(lower, upper)
// returns list from lower (excluding) to upper (including)
// returns empty list on fail
-std::vector<std::string> Compiler::GetPath(std::string upper, std::string lower) {
+std::vector<std::string> Compiler::GetPath(std::string upper, std::string lower)
+{
std::vector<std::string> result;
// traverse bnf from lower to upper
@@ -327,7 +333,8 @@ index_t Compiler::AddNode(const std::string& name, const std::string& child_type
return index;
}
-void Compiler::AddPath(const std::vector<std::string>& path, index_t current_index) {
+void Compiler::AddPath(const std::vector<std::string>& path, index_t current_index)
+{
for (int i = path.size() - 1; i > 0; i--) {
std::string child_name = path[i - 1];
current_index = AddNode(path[i], child_name, current_index);