summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-01-14 22:24:50 +0100
committerRoland Reichwein <mail@reichwein.it>2020-01-14 22:24:50 +0100
commit44b2cf820149eb751474d9ccd2746359da73a4e9 (patch)
tree1aefe20b72a7320cd7c0b8a94b4f13daf1a6e9f0
parent76363501a43fa1743b0685dc32d43b3c0f5f0bf1 (diff)
Lex (WIP)
-rw-r--r--minicc.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/minicc.cpp b/minicc.cpp
index f283e1f..07090a8 100644
--- a/minicc.cpp
+++ b/minicc.cpp
@@ -37,17 +37,22 @@ BNF Reverse(BNF bnf){
std::vector<std::string> Lex(std::string s, std::string Top, BNF bnf)
{
+ std::vector<std::string> result;
+ std::string token;
+
BNF ReverseBNF{ Reverse(bnf)};
- size_t pos{0};
+ std::string Whitespace{"\t \n\r"};
- while (pos < s.size()) {
+ for (size_t pos{0}; pos < s.size(); pos++) {
char c{s[pos]};
+ if (token.empty() and Whitespace.find(c) != std::string::npos)
+ continue; // skip whitespace between tokens
+
auto Path = GetPath(std::string{1, c}, ReverseBNF, Top);
- pos++;
}
- return {};
+ return result;
}
ProgramNode Compile(std::vector<std::string> Tokens, std::string Top, BNF bnf, Terminals terminals)