summaryrefslogtreecommitdiffhomepage
path: root/minicc.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-01-19 20:18:11 +0100
committerRoland Reichwein <mail@reichwein.it>2020-01-19 20:18:11 +0100
commit08997620fd617b580c1adbcb03c90cf621aa7069 (patch)
treeefa96e1a04001c0fbdbc2e99286218aad8e136f4 /minicc.cpp
parentc6fe8cccc49a70af8b8367fcfe19ff8a05f16d7a (diff)
Prepared compiler
Diffstat (limited to 'minicc.cpp')
-rw-r--r--minicc.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/minicc.cpp b/minicc.cpp
index f548181..0562491 100644
--- a/minicc.cpp
+++ b/minicc.cpp
@@ -395,16 +395,29 @@ public:
};
-ProgramNode Compile(std::vector<Token> Tokens, std::string Top, BNF bnf, Terminals terminals)
+class Compiler
{
- std::map<std::string, std::set<std::string>> ReverseBNF{ Reverse(bnf)};
- if (Tokens.size()){
- } else
- throw std::runtime_error("No tokens!");
+private:
+ const BNF &bnf;
+ const std::string& Top;
- return {};
-}
+ std::map<std::string, std::set<std::string>> ReverseBNF;
+
+public:
+ Compiler(const BNF& bnf, const std::string& Top): bnf(bnf), Top(Top), ReverseBNF{Reverse(bnf)}
+ {
+ }
+
+ ProgramNode compile(std::vector<Token> Tokens)
+ {
+ if (Tokens.size()){
+ } else
+ throw std::runtime_error("No tokens!");
+
+ return {};
+ }
+};
class Test: public ::testing::Test {
protected:
@@ -443,7 +456,8 @@ TEST_F(Test, BNF) {
{"assignment", {{"identifier", "=", "identifier"}}}
};
- std::set<std::string> Terminals{"identifier", "=", ";"};
+ // implicit?
+ //std::set<std::string> Terminals{"identifier", "=", ";"};
std::string Code{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ"};
std::vector<Token> tokens_reference{
@@ -473,7 +487,10 @@ TEST_F(Test, BNF) {
std::cout << i.value << std::endl;
}
#endif
- auto Program = Compile(tokens, Top, bnf, Terminals);
+ Compiler compiler(bnf, Top);
+ auto Program = compiler.compile(tokens);
+
+ //ASSERT_EQ(Program, Program_reference);
}
int main(int argc, char* argv[]) {