summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--bnf.cpp8
-rw-r--r--bnf.h8
-rw-r--r--dfa.cpp1
-rw-r--r--dfa.h10
-rw-r--r--grammer.cpp6
-rw-r--r--grammer.h6
-rw-r--r--lexer.h3
-rw-r--r--test-dfa.cpp17
9 files changed, 17 insertions, 44 deletions
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<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) {
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 <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"
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<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) {
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<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);
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<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) {
-}
-