diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-01-14 22:10:33 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-01-14 22:10:33 +0100 | 
| commit | 76363501a43fa1743b0685dc32d43b3c0f5f0bf1 (patch) | |
| tree | 48062c4d5ec8237084ac6b569b3cd70b9f113101 | |
| parent | a30806c8b76b85da3c0577b7156f05cdc71c7a65 (diff) | |
Lex
| -rw-r--r-- | minicc.cpp | 26 | 
1 files changed, 19 insertions, 7 deletions
| @@ -25,19 +25,29 @@ std::vector<std::string> split(std::string s)   return result;  } -std::vector<std::string> Lex(std::string s) +std::vector<PathElement> GetPath(std::string Token, BNF ReverseBNF, std::string Top, Terminals terminals = {}, std::vector<PathElement> PreviousPath = {})  { - return split(s); + throw std::runtime_error("Compile error"); + return {}; // TODO  }  BNF Reverse(BNF bnf){   return {}; // TODO  } -std::vector<PathElement> GetPath(std::string Token, BNF ReverseBNF, std::string Top, Terminals terminals, std::vector<PathElement> PreviousPath = {}) +std::vector<std::string> Lex(std::string s, std::string Top, BNF bnf)  { - throw std::runtime_error("Compile error"); - return {}; // TODO + BNF ReverseBNF{ Reverse(bnf)}; + + size_t pos{0}; + + while (pos < s.size()) { +  char c{s[pos]}; +  auto Path = GetPath(std::string{1, c}, ReverseBNF, Top); +  pos++; + } + + return {};  }  ProgramNode Compile(std::vector<std::string> Tokens, std::string Top, BNF bnf, Terminals terminals) @@ -68,6 +78,7 @@ protected:  };  TEST_F(Test, BNF) { + std::string LexTop{"preprocessing-token"};   BNF LexBNF{    {"preprocessing-token", {{"identifier"},                             {"preprocessing-op-or-punc"}, @@ -80,7 +91,8 @@ TEST_F(Test, BNF) {    {"identifier-nondigit", {{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",                              "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_"}}},    {"preprocessing-op-or-punc", {{";"}}}, -  {"pp-number", {{"digit"}, {"pp-number", "digit"}}} +  {"pp-number", {{"digit"}, +                 {"pp-number", "digit"}}}   };   std::string Top{"program"}; @@ -96,7 +108,7 @@ TEST_F(Test, BNF) {   std::string Code{"a = b ; c = d ; e = f ;"}; - auto tokens = Lex(Code); + auto tokens = Lex(Code, LexTop, LexBNF);   auto Program = Compile(tokens, Top, bnf, Terminals);  } | 
