diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-01-19 20:18:11 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-01-19 20:18:11 +0100 | 
| commit | 08997620fd617b580c1adbcb03c90cf621aa7069 (patch) | |
| tree | efa96e1a04001c0fbdbc2e99286218aad8e136f4 | |
| parent | c6fe8cccc49a70af8b8367fcfe19ff8a05f16d7a (diff) | |
Prepared compiler
| -rw-r--r-- | minicc.cpp | 35 | 
1 files changed, 26 insertions, 9 deletions
| @@ -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[]) { | 
