Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / Lexer.h
diff options
context:
space:
mode:
Commit00fedcbc8839be26b6738613d88b9d6883eaa7a0 (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-05 09:30:12 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-05 09:30:12 +0300
Files51c0df374475edbc620be2a60fc7f16951cf9432 /JSImpl/src/Lexer.h
IPL-00fedcbc8839be26b6738613d88b9d6883eaa7a0.tar
IPL-00fedcbc8839be26b6738613d88b9d6883eaa7a0.tar.gz
IPL-00fedcbc8839be26b6738613d88b9d6883eaa7a0.zip
Parent4e9b86ab9b8d2f780e2e966d5f99b0dd8ba16fa1 (diff)
Create solution for sample vm implementation.
Implement basic Lexer.
1 files changed, 81 insertions, 0 deletions
-rw-r--r--JSImpl/src/Lexer.h81
diff --git a/JSImpl/src/Lexer.h b/JSImpl/src/Lexer.h
new file mode 100644
index 0000000..6090759
--- /dev/null
+++ b/JSImpl/src/Lexer.h
@@ -0,0 +1,81 @@
+#pragma once
+
+#include "CommonTypes.h"
+#include <functional>
+
+enum TokenType
+{
+ // Single-character tokens.
+ LeftParen,
+ RightParen,
+ LeftBrace,
+ RightBrace,
+ Comma,
+ Dot,
+ Minums,
+ Plus,
+ Semicolon,
+ Slash,
+ Star,
+
+ // One or two character tokens
+ Bang,
+ BangEqual,
+ Equal,
+ EqualEqual,
+ Greater,
+ GreaterEqual,
+ Less,
+ LessEqual,
+
+ Identifier,
+ String,
+ Number,
+
+ // Keywords.
+ Break,
+ Case,
+ Catch,
+ Class,
+ Const,
+ Continue,
+ Debugger,
+ Default,
+ Delete,
+ Do,
+ Else,
+ Export,
+ Extends,
+ Finally,
+ For,
+ Function,
+ If,
+ Import,
+ In,
+ Instanceof,
+ New,
+ Return,
+ Super,
+ Switch,
+ This,
+ Throw,
+ Try,
+ Typeof,
+ Var,
+ Void,
+ While,
+ With,
+ Yield,
+
+ Eof,
+};
+
+struct Token
+{
+ TokenType Type;
+ unsigned Line;
+ IPLString Lexeme;
+ double Number;
+};
+
+IPLVector<Token> Tokenize(const char* code, const std::function<void()>& onError = {});