From 6ba49b30cf1e33fb0dd6782a404ec34b7964cb59 Mon Sep 17 00:00:00 2001 From: Martin Dobrev Date: Tue, 24 Nov 2020 18:06:26 +0200 Subject: Feature/object getters (#101) * Add member access expression. * Implement property getters. * Add test for property getters. * Add test for property setter. * Implement while and do-while Signed-off-by: Martin Dobrev * Add implement byte code generation for break/continue in for/while. --- JSImpl/src/Parser.cpp | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'JSImpl/src/Parser.cpp') diff --git a/JSImpl/src/Parser.cpp b/JSImpl/src/Parser.cpp index bc4920f..4bc97ce 100644 --- a/JSImpl/src/Parser.cpp +++ b/JSImpl/src/Parser.cpp @@ -23,6 +23,7 @@ private: bool MatchOneOf(IPLVector types); bool Match(TokenType type); + bool Peek(TokenType type); ExpressionPtr RegularExpression(); ExpressionPtr ParenthesizedExpression(); ExpressionPtr PrimaryExpression(NormalType a); @@ -125,6 +126,11 @@ bool Parser::Match(TokenType type) return false; } +bool Parser::Peek(TokenType type) +{ + return type == m_Tokens[m_Current].Type; +} + ExpressionPtr Parser::RegularExpression() { return nullptr; @@ -383,23 +389,32 @@ ExpressionPtr Parser::LeftSideExpression(NormalType a) ExpressionPtr Parser::CallExpression(NormalType a) { ExpressionPtr result; + auto ss = Snapshot(); - if (result = PrimaryExpression(a)) + if (auto pe = PrimaryExpression(a)) { - return result; + result = IPLMakeSharePtr(pe); } - Restore(ss); - if (result = FullNewExpression()) + else { - return result; + Restore(ss); } - - if (result = CallExpressionHelper(a)) + if (auto fne = FullNewExpression()) { - return result; + result = IPLMakeSharePtr<::Call>(fne); } - // TODO error - return nullptr; + + ExpressionPtr right; + do + { + right = CallExpressionHelper(a); + if (right) + { + result = IPLMakeSharePtr<::Call>(result, right); + } + } while (right); + + return result; } ExpressionPtr Parser::CallExpressionHelper(NormalType a) @@ -420,9 +435,7 @@ ExpressionPtr Parser::CallExpressionHelper(NormalType a) { if (Match(TokenType::Identifier)) { - auto next = CallExpressionHelper(a); - // return meaningfull expr - return nullptr; + return IPLMakeSharePtr(Prev().Lexeme); } // TODO error return nullptr; @@ -991,10 +1004,8 @@ ExpressionPtr Parser::ContinueStatement() { if (Match(TokenType::Continue)) { - auto type = TokenType::Continue; ExpressionPtr expr = OptionalLabel(); - bool suffix = true; - return IPLMakeSharePtr(expr, type, suffix); + return IPLMakeSharePtr(); } return nullptr; } @@ -1003,10 +1014,8 @@ ExpressionPtr Parser::BreakStatement() { if (Match(TokenType::Break)) { - auto type = TokenType::Break; ExpressionPtr expr = OptionalLabel(); - bool suffix = true; - return IPLMakeSharePtr(expr, type, suffix); + return IPLMakeSharePtr(); } return nullptr; } -- cgit v1.3.1-23-gd82d