diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-02-16 18:41:49 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-02-16 18:41:49 +0100 | 
| commit | d10f91dce5ecc2643496b7ef78149c0cdf37aaae (patch) | |
| tree | 9d1e96964ea9539a7637382c9a2235ff4714f644 | |
| parent | 142194b90d444d988890f9578a24b5d6094ddab0 (diff) | |
Try to match lex grammar (WIP)
| -rw-r--r-- | cpp.cpp | 37 | ||||
| -rw-r--r-- | debug.h | 3 | ||||
| -rw-r--r-- | grammer.cpp | 2 | ||||
| -rw-r--r-- | test-lexer.cpp | 5 | 
4 files changed, 43 insertions, 4 deletions
| @@ -4,6 +4,7 @@  #include "cppbnf.h"  #include "grammer.h"  #include "minicc.h" +#include "debug.h"  #include <gtest/gtest.h>  #include <gmock/gmock.h> @@ -49,7 +50,29 @@ void CPP::preprocessing_tokenize(const std::string& s)   auto charTokens {sourceToCharTokens(s)};   auto bnf{SubBNF(GetCppBNFLex(), "preprocessing-token")}; - Gram::Compiler compiler(bnf, "preprocessing-token"); + + // add to bnf to match whole file + bnf["file"] = { +  {"preprocessing-token-list"}, +  {"whitespace-list", "preprocessing-token-list"} + }; + bnf["preprocessing-token-list"] = { +  {"preprocessing-token-padded"}, +  {"preprocessing-token-list", "preprocessing-token-padded"} + }; + bnf["preprocessing-token-padded"] = { +  {"preprocessing-token"}, +  {"preprocessing-token", "whitespace-list"} + }; + bnf["whitespace-list"] = { +  {"whitespace-char"}, +  {"whitespace-list", "whitespace-char" } + }; + bnf["whitespace-char"] = { +  {" "}, {"\t"}, {"\n"}, {"\r"} + }; + Gram::Compiler compiler(bnf, "file"); + debug = true;   auto Tree = compiler.compile(charTokens);  } @@ -111,7 +134,17 @@ void CPP::translate(const std::string& code)   link();  } -TEST(Cpp, preprocessing_tokenize) { +class CppTest: public ::testing::Test +{ +protected: + CppTest() { +  debug = false; + } + ~CppTest() { + } +}; + +TEST_F(CppTest, preprocessing_tokenize) {   CPP::preprocessing_tokenize("int main() { return 1; }");  } @@ -0,0 +1,3 @@ +#pragma once + +extern bool debug; diff --git a/grammer.cpp b/grammer.cpp index 808c49e..9df4703 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -4,7 +4,7 @@  using namespace Gram; -static bool debug{false}; +bool debug{false};  void Debug(std::string s)  { diff --git a/test-lexer.cpp b/test-lexer.cpp index 651dfae..b0706df 100644 --- a/test-lexer.cpp +++ b/test-lexer.cpp @@ -3,6 +3,7 @@  #include "lexer.h"  #include "grammer.h"  #include "minicc.h" +#include "debug.h"  #include <boost/algorithm/string.hpp> @@ -20,7 +21,9 @@  class Test: public ::testing::Test {  protected: - Test(){} + Test(){ +  debug = false; + }   ~Test() override {}  }; | 
