From 76363501a43fa1743b0685dc32d43b3c0f5f0bf1 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 14 Jan 2020 22:10:33 +0100 Subject: Lex --- minicc.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'minicc.cpp') diff --git a/minicc.cpp b/minicc.cpp index 26a88d4..f283e1f 100644 --- a/minicc.cpp +++ b/minicc.cpp @@ -25,19 +25,29 @@ std::vector split(std::string s) return result; } -std::vector Lex(std::string s) +std::vector GetPath(std::string Token, BNF ReverseBNF, std::string Top, Terminals terminals = {}, std::vector PreviousPath = {}) { - return split(s); + throw std::runtime_error("Compile error"); + return {}; // TODO } BNF Reverse(BNF bnf){ return {}; // TODO } -std::vector GetPath(std::string Token, BNF ReverseBNF, std::string Top, Terminals terminals, std::vector PreviousPath = {}) +std::vector 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 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); } -- cgit v1.2.3