diff options
| Commit | f8ccf5eedb60435b7fac66521554beab582c0b00 (patch) | |
|---|---|---|
| Author | 2020-10-24 17:58:54 +0300 | |
| Committer | 2020-10-24 17:58:54 +0300 | |
| Files | cbee6e087ffc49463c69553c9505f4b9a7baa5ce /JSImpl/src | |
| IPL-f8ccf5eedb60435b7fac66521554beab582c0b00.tar IPL-f8ccf5eedb60435b7fac66521554beab582c0b00.tar.gz IPL-f8ccf5eedb60435b7fac66521554beab582c0b00.zip | ||
| Parent | d5fd7629fc6b85df0f27f3069bffef407a94cef8 (diff) | |
JSImpl: Implemented ASTInterpreter::Visit for unary + and - (#87)
* JSImpl: Implemented ASTInterpreter::Visit for unary + and -
* JSImpl: Added tests for unary + and -
* JSImpl: fixed appveyor ubuntu build
Co-authored-by: Martin Dobrev <martindobrev0@gmail.com>
2 files changed, 33 insertions, 20 deletions
| -rw-r--r-- | JSImpl/src/ASTInterpreter.cpp | 50 | ||||
| -rw-r--r-- | JSImpl/src/Lexer.cpp | 3 |
diff --git a/JSImpl/src/ASTInterpreter.cpp b/JSImpl/src/ASTInterpreter.cpp index 25f5c02..9874a4d 100644 --- a/JSImpl/src/ASTInterpreter.cpp +++ b/JSImpl/src/ASTInterpreter.cpp @@ -216,27 +216,41 @@ void ASTInterpreter::Visit(BinaryExpression* e) { } void ASTInterpreter::Visit(UnaryExpression* e) { - LValueExtractor extractor(this); - auto lvalue = extractor.Run(e->GetExpr().get()); - if (e->GetSuffix()) - { - m_Evaluation.push_back(*lvalue); - } switch (e->GetOperator()) { - case TokenType::PlusPlus: - ++(*lvalue); - break; - case TokenType::MinusMinus: - --(*lvalue); - break; - default: - NOT_IMPLEMENTED; - } - if (!e->GetSuffix()) - { - m_Evaluation.push_back(*lvalue); + case TokenType::Minus: + { + e->GetExpr()->Accept(*this); + m_Evaluation.back() *= -1; + break; + } + case TokenType::Plus: + { + e->GetExpr()->Accept(*this); + break; + } + case TokenType::PlusPlus: // FALLTHROUGH + case TokenType::MinusMinus: + { + LValueExtractor extractor(this); + auto lvalue = extractor.Run(e->GetExpr().get()); + if (e->GetSuffix()) + { + m_Evaluation.push_back(*lvalue); + } + *lvalue += e->GetOperator() == TokenType::PlusPlus ? 1 : -1; + if (!e->GetSuffix()) + { + m_Evaluation.push_back(*lvalue); + } + break; + } + default: + { + NOT_IMPLEMENTED; + } } + } void ASTInterpreter::Visit(IdentifierExpression* e) { diff --git a/JSImpl/src/Lexer.cpp b/JSImpl/src/Lexer.cpp index 0f6f4a6..4a2deb8 100644 --- a/JSImpl/src/Lexer.cpp +++ b/JSImpl/src/Lexer.cpp @@ -179,8 +179,7 @@ Tokenizer::Tokenizer(const char* code, const LexerSettings& settings) LexerResult Tokenizer::Tokenize() { - LexerResult result; - result.IsSuccessful = true; + LexerResult result{ true, IPLError(), IPLVector<Token>() }; Token token; do { |
