Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src
diff options
context:
space:
mode:
Commitb91b7d3820deb7e0aed536141cd79e7a8c4ca8c9 (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-08 12:23:28 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-08 12:23:28 +0300
Files78b5912f2ae289a7280e5cd8c3993a040eda54d9 /JSImpl/src
IPL-b91b7d3820deb7e0aed536141cd79e7a8c4ca8c9.tar
IPL-b91b7d3820deb7e0aed536141cd79e7a8c4ca8c9.tar.gz
IPL-b91b7d3820deb7e0aed536141cd79e7a8c4ca8c9.zip
Parentf5b37017965efbc73deddc8a8afaabc9274dd530 (diff)
Add more tokens to Lexer
2 files changed, 30 insertions, 4 deletions
-rw-r--r--JSImpl/src/Lexer.cpp15
-rw-r--r--JSImpl/src/Lexer.h19
diff --git a/JSImpl/src/Lexer.cpp b/JSImpl/src/Lexer.cpp
index 3e78275..49c7567 100644
--- a/JSImpl/src/Lexer.cpp
+++ b/JSImpl/src/Lexer.cpp
@@ -71,6 +71,10 @@ Tokenizer::Tokenizer(const char* code, const std::function<void()>& onError)
m_KeyWordsTable["while"] = TokenType::While;
m_KeyWordsTable["with"] = TokenType::With;
m_KeyWordsTable["yield"] = TokenType::Yield;
+ m_KeyWordsTable["null"] = TokenType::Null;
+ m_KeyWordsTable["undefined"] = TokenType::Undefined;
+ m_KeyWordsTable["true"] = TokenType::True;
+ m_KeyWordsTable["false"] = TokenType::False;
}
IPLVector<Token> Tokenizer::Tokenize()
@@ -167,10 +171,13 @@ Token Tokenizer::NextToken()
case '!': m_Current++; return Match('=') ? Match('=') ? ProduceToken(TokenType::StrictNotEqual) : ProduceToken(TokenType::BangEqual) : ProduceToken(TokenType::Bang);
case '>': m_Current++; return Match('=') ? ProduceToken(TokenType::GreaterEqual) : Match('>') ? ProduceToken(TokenType::RightShift) : ProduceToken(TokenType::Greater);
case '<': m_Current++; return Match('=') ? ProduceToken(TokenType::LessEqual) : Match('<') ? ProduceToken(TokenType::LeftShift) : ProduceToken(TokenType::Less);
- case '&': m_Current++; return Match('&') ? ProduceToken(LogicalAnd) : ProduceToken(BitwiseAnd);
- case '^': m_Current++; return ProduceToken(BitwiseXor);
- case '|': m_Current++; return Match('|') ? ProduceToken(LogicalOr) : ProduceToken(BitwiseOr);
-
+ case '&': m_Current++; return Match('&') ? ProduceToken(TokenType::LogicalAnd) : ProduceToken(TokenType::BitwiseAnd);
+ case '^': m_Current++; return ProduceToken(TokenType::BitwiseXor);
+ case '|': m_Current++; return Match('|') ? ProduceToken(TokenType::LogicalOr) : ProduceToken(TokenType::BitwiseOr);
+ case '?': m_Current++; return ProduceToken(TokenType::QuestionMark);
+ case ':': m_Current++; return ProduceToken(TokenType::Colon);
+ case '[': m_Current++; return ProduceToken(TokenType::LeftSquareBracket);
+ case ']': m_Current++; return ProduceToken(TokenType::RightSquareBracket);
default:
break;
}
diff --git a/JSImpl/src/Lexer.h b/JSImpl/src/Lexer.h
index 21c06cc..fd3d244 100644
--- a/JSImpl/src/Lexer.h
+++ b/JSImpl/src/Lexer.h
@@ -22,6 +22,10 @@ enum TokenType
BitwiseAnd,
BitwiseXor,
BitwiseOr,
+ QuestionMark,
+ Colon,
+ LeftSquareBracket,
+ RightSquareBracket,
// One or two character tokens
Bang,
@@ -40,6 +44,16 @@ enum TokenType
RightShift,
LogicalAnd,
LogicalOr,
+ StarEqual,
+ DivideEqual,
+ ModuloEqual,
+ PlusEqual,
+ MinusEqual,
+ LeftShiftEqual,
+ RightShiftEqual,
+ BitwiseAndEqual,
+ BitwiseXorEqual,
+ BitwiseOrEqual,
Identifier,
String,
@@ -79,6 +93,11 @@ enum TokenType
While,
With,
Yield,
+ Null,
+ Undefined,
+ True,
+ False,
+
Eof,
};