From 08997620fd617b580c1adbcb03c90cf621aa7069 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 19 Jan 2020 20:18:11 +0100 Subject: Prepared compiler --- minicc.cpp | 35 ++++++++++++++++++++++++++--------- 1 file 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 Tokens, std::string Top, BNF bnf, Terminals terminals) +class Compiler { - std::map> ReverseBNF{ Reverse(bnf)}; - if (Tokens.size()){ - } else - throw std::runtime_error("No tokens!"); +private: + const BNF &bnf; + const std::string& Top; - return {}; -} + std::map> ReverseBNF; + +public: + Compiler(const BNF& bnf, const std::string& Top): bnf(bnf), Top(Top), ReverseBNF{Reverse(bnf)} + { + } + + ProgramNode compile(std::vector 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 Terminals{"identifier", "=", ";"}; + // implicit? + //std::set Terminals{"identifier", "=", ";"}; std::string Code{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ"}; std::vector 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[]) { -- cgit v1.2.3