Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src
diff options
context:
space:
mode:
Commitb37ef48f0dc109ef99089a99eb917d027799e5ea (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-07 18:58:29 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-07 18:58:29 +0300
Filesd8f2bf7fa71a513abb65b3e04c439bbdbdaa4ac6 /JSImpl/src
IPL-b37ef48f0dc109ef99089a99eb917d027799e5ea.tar
IPL-b37ef48f0dc109ef99089a99eb917d027799e5ea.tar.gz
IPL-b37ef48f0dc109ef99089a99eb917d027799e5ea.zip
Parent4fb889400b4f4e478bea030d1484becc89a1025c (diff)
Add more lexemes to Lexer
2 files changed, 13 insertions, 6 deletions
-rw-r--r--JSImpl/src/Lexer.cpp10
-rw-r--r--JSImpl/src/Lexer.h9
diff --git a/JSImpl/src/Lexer.cpp b/JSImpl/src/Lexer.cpp
index d17f593..2115a2b 100644
--- a/JSImpl/src/Lexer.cpp
+++ b/JSImpl/src/Lexer.cpp
@@ -156,12 +156,13 @@ Token Tokenizer::NextToken()
case '}': m_Current++; return ProduceToken(TokenType::RightBrace);
case ',': m_Current++; return ProduceToken(TokenType::Comma);
case '.': m_Current++; return ProduceToken(TokenType::Dot);
- case '-': m_Current++; return ProduceToken(TokenType::Minums);
- case '+': m_Current++; return ProduceToken(TokenType::Plus);
+ case '-': m_Current++; return Match('-') ? ProduceToken(TokenType::MinusMinus) : ProduceToken(TokenType::Minus);
+ case '+': m_Current++; return Match('+') ? ProduceToken(TokenType::PlusPlus) : ProduceToken(TokenType::Plus);
case ';': m_Current++; return ProduceToken(TokenType::Semicolon);
case '*': m_Current++; return ProduceToken(TokenType::Star);
- case '=': m_Current++; return Match('=') ? ProduceToken(TokenType::EqualEqual) : ProduceToken(TokenType::Equal);
- case '!': m_Current++; return Match('=') ? ProduceToken(TokenType::BangEqual) : ProduceToken(TokenType::Bang);
+ case '~': m_Current++; return ProduceToken(TokenType::BitwiseNot);
+ case '=': m_Current++; return Match('=') ? Match('=') ? ProduceToken(TokenType::StrictEqual) : ProduceToken(TokenType::EqualEqual) : ProduceToken(TokenType::Equal);
+ case '!': m_Current++; return Match('=') ? Match('=') ? ProduceToken(TokenType::StrictNotEqual) : ProduceToken(TokenType::BangEqual) : ProduceToken(TokenType::Bang);
case '>': m_Current++; return Match('=') ? ProduceToken(TokenType::GreaterEqual) : ProduceToken(TokenType::Greater);
case '<': m_Current++; return Match('=') ? ProduceToken(TokenType::LessEqual) : ProduceToken(TokenType::Less);
default:
@@ -220,5 +221,6 @@ Token Tokenizer::NextToken()
}
return Token{ TokenType::Identifier, m_Line, IPLString(m_Code + start, m_Code + m_Current) };
}
+ // TODO: Error reporting
return Token{ TokenType::Eof, m_Line, "" };
} \ No newline at end of file
diff --git a/JSImpl/src/Lexer.h b/JSImpl/src/Lexer.h
index 6090759..eb33e77 100644
--- a/JSImpl/src/Lexer.h
+++ b/JSImpl/src/Lexer.h
@@ -12,27 +12,32 @@ enum TokenType
RightBrace,
Comma,
Dot,
- Minums,
+ Minus,
Plus,
Semicolon,
Slash,
Star,
+ BitwiseNot,
// One or two character tokens
Bang,
BangEqual,
Equal,
EqualEqual,
+ StrictEqual,
+ StrictNotEqual,
Greater,
GreaterEqual,
Less,
LessEqual,
+ MinusMinus,
+ PlusPlus,
Identifier,
String,
Number,
- // Keywords.
+ // Keywords. ECMAScript 2015
Break,
Case,
Catch,