aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/lexer/lexer.h27
-rw-r--r--include/lexer/token.h17
-rw-r--r--include/lexer/token_type.h25
3 files changed, 69 insertions, 0 deletions
diff --git a/include/lexer/lexer.h b/include/lexer/lexer.h
new file mode 100644
index 0000000..f24e92e
--- /dev/null
+++ b/include/lexer/lexer.h
@@ -0,0 +1,27 @@
+#ifndef LEXER_H
+#define LEXER_H
+
+#include "token.h"
+
+#include <vector>
+#include <string>
+
+class Lexer {
+public:
+ explicit Lexer (const std::string& src);
+
+ std::vector<Token> tokenise();
+
+private:
+ int line;
+ int column;
+ int position;
+ std::string src;
+ std::vector<Token> tokens;
+
+ char advance();
+ void skipWhitespace();
+ void skipComment();
+};
+
+#endif
diff --git a/include/lexer/token.h b/include/lexer/token.h
new file mode 100644
index 0000000..54ac116
--- /dev/null
+++ b/include/lexer/token.h
@@ -0,0 +1,17 @@
+#ifndef TOKEN_H
+#define TOKEN_H
+
+#include "token_type.h"
+
+#include <string>
+
+struct Token {
+ TokenType type;
+ std::string value;
+ int line;
+ int column;
+
+ Token(TokenType t, const std::string& val, int line, int col) : type{t}, value{val}, line{line}, column{col} {};
+};
+
+#endif
diff --git a/include/lexer/token_type.h b/include/lexer/token_type.h
new file mode 100644
index 0000000..f83c6d6
--- /dev/null
+++ b/include/lexer/token_type.h
@@ -0,0 +1,25 @@
+#ifndef TOKEN_TYPE_H
+#define TOKEN_TYPE_H
+
+enum class TokenType {
+ INT,
+ STRING,
+
+ NUMBER,
+ IDENTIFIER,
+
+ PLUS,
+ MINUS,
+ MULTIPLY,
+ DIVIDE,
+
+ ASSIGN,
+
+ SEMICOLON,
+
+ END_OF_FILE,
+ INVALID
+
+};
+
+#endif