summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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[]) {