diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | bnf.cpp | 8 | ||||
| -rw-r--r-- | bnf.h | 8 | ||||
| -rw-r--r-- | dfa.cpp | 1 | ||||
| -rw-r--r-- | dfa.h | 10 | ||||
| -rw-r--r-- | grammer.cpp | 6 | ||||
| -rw-r--r-- | grammer.h | 6 | ||||
| -rw-r--r-- | lexer.h | 3 | ||||
| -rw-r--r-- | test-dfa.cpp | 17 | 
9 files changed, 17 insertions, 44 deletions
| @@ -51,8 +51,6 @@ SRC=\      minicc.cpp \      test-minicc.cpp \      cppbnf.cpp \ -    dfa.cpp \ -    test-dfa.cpp \      googletest/src/gtest-all.cpp \      googlemock/src/gmock-all.cpp @@ -1,8 +1,8 @@  #include "bnf.h" -std::map<std::string, std::set<std::string>> Reverse(BNF bnf) +std::unordered_map<std::string, std::set<std::string>> Reverse(BNF bnf)  { - std::map<std::string, std::set<std::string>> result; + std::unordered_map<std::string, std::set<std::string>> result;   for (const auto& [from, to] : bnf) {    for (const auto& list : to) { @@ -19,9 +19,9 @@ std::map<std::string, std::set<std::string>> Reverse(BNF bnf)   return result;  } -std::map<std::string, std::set<std::string>> reverseFirst(BNF bnf) +std::unordered_map<std::string, std::set<std::string>> reverseFirst(BNF bnf)  { - std::map<std::string, std::set<std::string>> result; + std::unordered_map<std::string, std::set<std::string>> result;   for (const auto& [from, to] : bnf) {    for (const auto& list : to) { @@ -1,7 +1,7 @@  #pragma once  #include <deque> -#include <map> +#include <unordered_map>  #include <set>  #include <string>  #include <utility> @@ -9,9 +9,9 @@  using namespace std::string_literals; -using BNF = std::map<std::string, std::vector<std::vector<std::string>>>; +using BNF = std::unordered_map<std::string, std::vector<std::vector<std::string>>>; -std::map<std::string, std::set<std::string>> Reverse(BNF bnf); // unused now, remove? -std::map<std::string, std::set<std::string>> reverseFirst(BNF bnf); +std::unordered_map<std::string, std::set<std::string>> Reverse(BNF bnf); // unused now, remove? +std::unordered_map<std::string, std::set<std::string>> reverseFirst(BNF bnf);  BNF SubBNF(const BNF& bnf, const std::string& top); diff --git a/dfa.cpp b/dfa.cpp deleted file mode 100644 index a33db3f..0000000 --- a/dfa.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "dfa.h" @@ -1,10 +0,0 @@ -#pragma once - -namespace { -}; - -// deterministic finite automaton -class DFA { -public: - DFA(){} -}; diff --git a/grammer.cpp b/grammer.cpp index be01adc..2379e9a 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -365,9 +365,9 @@ void Compiler::TrackBack()  // breadth-first search  // return: node, child -std::map<std::string, std::string> Compiler::traverse(const std::string& lower, const std::string& upper) +std::unordered_map<std::string, std::string> Compiler::traverse(const std::string& lower, const std::string& upper)  { - std::map<std::string, std::string> visited; // node, child + std::unordered_map<std::string, std::string> visited; // node, child   std::deque<std::pair<std::string, std::string>> todo{{lower, ""}}; // node, child   while (!todo.empty()) { @@ -401,7 +401,7 @@ std::vector<std::string> Compiler::GetPath(std::string upper, std::string lower)   std::vector<std::string> result;   // traverse bnf from lower to upper - std::map<std::string, std::string> visited {traverse(lower, upper)}; + std::unordered_map<std::string, std::string> visited {traverse(lower, upper)};   auto current {upper};   while (current != lower) { @@ -38,8 +38,8 @@ private:   BNF &bnf; // not const for access via operator[]   const std::string& Top; - std::map<std::string, std::set<std::string>> ReverseBNF; // possible parent types of a given type; unused now: remove? - std::map<std::string, std::set<std::string>> reversedFirst; // possible parent types of first childs of a given type + std::unordered_map<std::string, std::set<std::string>> ReverseBNF; // possible parent types of a given type; unused now: remove? + std::unordered_map<std::string, std::set<std::string>> reversedFirst; // possible parent types of first childs of a given type   // Tree specific   void clear(); @@ -61,7 +61,7 @@ private:   void ChangeNodeType();   void TrackBack();   void Validate() const; - std::map<std::string, std::string> traverse(const std::string& lower, const std::string& upper); + std::unordered_map<std::string, std::string> traverse(const std::string& lower, const std::string& upper);   std::vector<std::string> GetPath(std::string upper, std::string lower);   index_t AddNode(const std::string& child_type, index_t parent_index);   void AddPath(const std::vector<std::string>& path, index_t current_index); @@ -8,6 +8,9 @@ namespace Lex {  class Lexer  { + //states; // start, ... + //transitions; // state, state, character +  public:   Lexer(const BNF& bnf, const std::string& Top);   std::vector<Token> Lex(const std::string& s); diff --git a/test-dfa.cpp b/test-dfa.cpp deleted file mode 100644 index 07166f0..0000000 --- a/test-dfa.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "debug.h" -#include "dfa.h" - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -class DFATest: public ::testing::Test { -protected: - DFATest(){ -  debug = false; - } - ~DFATest() override {} -}; - -TEST_F(DFATest, BNF) { -} - | 
