From 3a7006fcf5f8ecffd852fbba6d8ee03ce8a35dce Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 14 Mar 2020 17:10:23 +0100 Subject: Remove dfa again --- Makefile | 2 -- bnf.cpp | 8 ++++---- bnf.h | 8 ++++---- dfa.cpp | 1 - dfa.h | 10 ---------- grammer.cpp | 6 +++--- grammer.h | 6 +++--- lexer.h | 3 +++ test-dfa.cpp | 17 ----------------- 9 files changed, 17 insertions(+), 44 deletions(-) delete mode 100644 dfa.cpp delete mode 100644 dfa.h delete mode 100644 test-dfa.cpp diff --git a/Makefile b/Makefile index ec51fe1..5d6ee59 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/bnf.cpp b/bnf.cpp index 7290962..4dd896e 100644 --- a/bnf.cpp +++ b/bnf.cpp @@ -1,8 +1,8 @@ #include "bnf.h" -std::map> Reverse(BNF bnf) +std::unordered_map> Reverse(BNF bnf) { - std::map> result; + std::unordered_map> result; for (const auto& [from, to] : bnf) { for (const auto& list : to) { @@ -19,9 +19,9 @@ std::map> Reverse(BNF bnf) return result; } -std::map> reverseFirst(BNF bnf) +std::unordered_map> reverseFirst(BNF bnf) { - std::map> result; + std::unordered_map> result; for (const auto& [from, to] : bnf) { for (const auto& list : to) { diff --git a/bnf.h b/bnf.h index b14ca58..13337bf 100644 --- a/bnf.h +++ b/bnf.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -9,9 +9,9 @@ using namespace std::string_literals; -using BNF = std::map>>; +using BNF = std::unordered_map>>; -std::map> Reverse(BNF bnf); // unused now, remove? -std::map> reverseFirst(BNF bnf); +std::unordered_map> Reverse(BNF bnf); // unused now, remove? +std::unordered_map> 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" diff --git a/dfa.h b/dfa.h deleted file mode 100644 index 8917433..0000000 --- a/dfa.h +++ /dev/null @@ -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 Compiler::traverse(const std::string& lower, const std::string& upper) +std::unordered_map Compiler::traverse(const std::string& lower, const std::string& upper) { - std::map visited; // node, child + std::unordered_map visited; // node, child std::deque> todo{{lower, ""}}; // node, child while (!todo.empty()) { @@ -401,7 +401,7 @@ std::vector Compiler::GetPath(std::string upper, std::string lower) std::vector result; // traverse bnf from lower to upper - std::map visited {traverse(lower, upper)}; + std::unordered_map visited {traverse(lower, upper)}; auto current {upper}; while (current != lower) { diff --git a/grammer.h b/grammer.h index c2eb705..ee2897d 100644 --- a/grammer.h +++ b/grammer.h @@ -38,8 +38,8 @@ private: BNF &bnf; // not const for access via operator[] const std::string& Top; - std::map> ReverseBNF; // possible parent types of a given type; unused now: remove? - std::map> reversedFirst; // possible parent types of first childs of a given type + std::unordered_map> ReverseBNF; // possible parent types of a given type; unused now: remove? + std::unordered_map> 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 traverse(const std::string& lower, const std::string& upper); + std::unordered_map traverse(const std::string& lower, const std::string& upper); std::vector GetPath(std::string upper, std::string lower); index_t AddNode(const std::string& child_type, index_t parent_index); void AddPath(const std::vector& path, index_t current_index); diff --git a/lexer.h b/lexer.h index 7f1be2d..f9363ef 100644 --- a/lexer.h +++ b/lexer.h @@ -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 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) { -} - -- cgit v1.2.3