diff options
1 files changed, 113 insertions, 0 deletions
| -rw-r--r-- | JSImpl/src/Lexer.h | 113 |
diff --git a/JSImpl/src/Lexer.h b/JSImpl/src/Lexer.h new file mode 100644 index 0000000..fd3d244 --- /dev/null +++ b/JSImpl/src/Lexer.h @@ -0,0 +1,113 @@ +#pragma once + +#include "CommonTypes.h" +#include <functional> + +enum TokenType +{ + // Single-character tokens. + LeftParen, + RightParen, + LeftBrace, + RightBrace, + Comma, + Dot, + Minus, + Plus, + Semicolon, + Star, + Division, + Modulo, + BitwiseNot, + BitwiseAnd, + BitwiseXor, + BitwiseOr, + QuestionMark, + Colon, + LeftSquareBracket, + RightSquareBracket, + + // One or two character tokens + Bang, + BangEqual, + Equal, + EqualEqual, + StrictEqual, + StrictNotEqual, + Greater, + GreaterEqual, + Less, + LessEqual, + MinusMinus, + PlusPlus, + LeftShift, + RightShift, + LogicalAnd, + LogicalOr, + StarEqual, + DivideEqual, + ModuloEqual, + PlusEqual, + MinusEqual, + LeftShiftEqual, + RightShiftEqual, + BitwiseAndEqual, + BitwiseXorEqual, + BitwiseOrEqual, + + Identifier, + String, + Number, + + // Keywords. ECMAScript 2015 + 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, + Null, + Undefined, + True, + False, + + + Eof, +}; + +struct Token +{ + TokenType Type; + unsigned Line; + IPLString Lexeme; + double Number; +}; + +IPLVector<Token> Tokenize(const char* code, const std::function<void()>& onError = {}); |
