diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-03-21 16:06:47 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-03-21 16:06:47 +0100 |
commit | cdf001920fde6652b344775589b0524ff6529809 (patch) | |
tree | 883ab6232a4c4ca4056b123bff7c7d1cd98c5cf4 /cpp.cpp | |
parent | 3cc139bce0283018473d4906ee2ea5f40f771255 (diff) |
Added Gram::Compiler to CPP (WIP)
Diffstat (limited to 'cpp.cpp')
-rw-r--r-- | cpp.cpp | 47 |
1 files changed, 7 insertions, 40 deletions
@@ -33,7 +33,7 @@ void CPP::backslash_escape() // Phase 3: Parse preprocessing tokens std::vector<Token> CPP::preprocessing_tokenize(const std::string& s) { - auto bnf{SubBNF(GetCppBNFLex(), "preprocessing-token")}; + auto bnf{SubBNF(CPPBNF::GetCppBNFLex(), "preprocessing-token")}; Lex::Lexer lexer(bnf, "preprocessing-token"); @@ -137,9 +137,13 @@ std::vector<Token> CPP::tokens_from_pptokens(std::vector<Token> pp_tokens) } // Phase 7.b: Grammar Analysis -std::pair<index_t, std::vector<Gram::TreeNode>> analysis(std::vector<Token>) +std::pair<index_t, std::vector<Gram::TreeNode>> CPP::analysis(std::vector<Token> tokens) { - return {0 , {}}; + auto bnf = SubBNF(CPPBNF::GetCppBNFGram(), "translation-unit"); + + Gram::Compiler compiler(bnf, "translation-unit"); + + return compiler.compile(tokens); } // Phase 7.c: Translate @@ -178,40 +182,3 @@ void CPP::translate(const std::string& code) #endif } -class CppTest: public ::testing::Test -{ -protected: - CppTest() { - //debug = true; - } - ~CppTest() { - } -}; - -#if 1 -TEST_F(CppTest, preprocessing_tokenize) { - CPP cpp; - auto pp_tokens = cpp.preprocessing_tokenize("int main() { return 1; }"); - - ASSERT_EQ(pp_tokens.size(), 9); - - auto tokens = cpp.tokens_from_pptokens(pp_tokens); - - ASSERT_EQ(tokens.size(), 9); -} -#endif - -#if 0 -TEST_F(CppTest, preprocessing_tokenize2) { - CPP cpp; - auto ppTree = cpp.preprocessing_tokenize("in ma"); - - cpp.tokens_from_pptokens(ppTree); -} -#endif - -#if 0 -TEST(Cpp, translate) { - CPP::translate(); -} -#endif |