summaryrefslogtreecommitdiffhomepage
path: root/lexer.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-03-15 18:19:49 +0100
committerRoland Reichwein <mail@reichwein.it>2020-03-15 18:19:49 +0100
commit9f69b006dde3c3fbe19ed3e0275d3b7348f2aa87 (patch)
tree6ac42793568339463f913cf39474794c8613d0b6 /lexer.h
parent3a7006fcf5f8ecffd852fbba6d8ee03ce8a35dce (diff)
New lexer
Diffstat (limited to 'lexer.h')
-rw-r--r--lexer.h32
1 files changed, 29 insertions, 3 deletions
diff --git a/lexer.h b/lexer.h
index f9363ef..eb41e3d 100644
--- a/lexer.h
+++ b/lexer.h
@@ -3,16 +3,42 @@
#include "minicc.h"
#include "bnf.h"
+#include <string>
+#include <unordered_map>
+#include <vector>
+
namespace Lex {
class Lexer
{
+ // constructor input
+ const BNF& m_bnf;
+ const std::string& m_top;
+
+ // Graph
+
+ size_t states{}; // start, ...
+ std::unordered_map<size_t, std::vector<std::pair<size_t, char>>> transitions; //transitions: state -> {state,character}, ...; empty transition is marked by \0
+ std::vector<std::string> m_state_types;
+ size_t m_startState;
+ size_t m_endState;
+
+ // Graph manipulation
+
+ size_t newState(std::string state_type = "");
+ void addTransition(size_t state0, size_t state1, char c);
+ std::vector<std::pair<size_t, char>> getSuccessors(size_t state);
+
+ // Build up automaton, recursively
+ void addPath(size_t state0, size_t state1, std::string s, std::string type);
+ void addPathOrTransition(size_t state0, size_t state1, std::string symbol, std::string type);
+ void addRule(const std::vector<std::string>& list, size_t list_index_from, size_t list_index_to, size_t state0, size_t state1, const std::string& rule_symbol, std::string type);
- //states; // start, ...
- //transitions; // state, state, character
+ Token getToken(const std::string& s, Location& location);
+ void skipWhitespace(const std::string& s, Location& location);
public:
- Lexer(const BNF& bnf, const std::string& Top);
+ Lexer(const BNF& bnf, const std::string& top);
std::vector<Token> Lex(const std::string& s);
};