summaryrefslogtreecommitdiffhomepage
path: root/minicc.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-01-14 22:10:33 +0100
committerRoland Reichwein <mail@reichwein.it>2020-01-14 22:10:33 +0100
commit76363501a43fa1743b0685dc32d43b3c0f5f0bf1 (patch)
tree48062c4d5ec8237084ac6b569b3cd70b9f113101 /minicc.cpp
parenta30806c8b76b85da3c0577b7156f05cdc71c7a65 (diff)
Lex
Diffstat (limited to 'minicc.cpp')
-rw-r--r--minicc.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/minicc.cpp b/minicc.cpp
index 26a88d4..f283e1f 100644
--- a/minicc.cpp
+++ b/minicc.cpp
@@ -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);
}