summaryrefslogtreecommitdiffhomepage
path: root/cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp.cpp')
-rw-r--r--cpp.cpp47
1 files changed, 7 insertions, 40 deletions
diff --git a/cpp.cpp b/cpp.cpp
index bbb6e27..d877564 100644
--- a/cpp.cpp
+++ b/cpp.cpp
@@ -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