diff options
| Commit | 6ba49b30cf1e33fb0dd6782a404ec34b7964cb59 (patch) | |
|---|---|---|
| Author | 2020-11-24 18:06:26 +0200 | |
| Committer | 2020-11-24 18:06:26 +0200 | |
| Files | a89b314c4d0b942d2350b9adbd741d6fa3375bfb /JSImpl/src/Parser.cpp | |
| IPL-6ba49b30cf1e33fb0dd6782a404ec34b7964cb59.tar IPL-6ba49b30cf1e33fb0dd6782a404ec34b7964cb59.tar.gz IPL-6ba49b30cf1e33fb0dd6782a404ec34b7964cb59.zip | ||
| Parent | 4e883334a14ff22f12765204d6bf223d07c0298f (diff) | |
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 <martindobrev0@gmail.com>
* Add implement byte code generation for break/continue in for/while.
1 files changed, 28 insertions, 19 deletions
| -rw-r--r-- | JSImpl/src/Parser.cpp | 47 |
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<TokenType> 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<Call>(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<MemberAccess>(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<UnaryExpression>(expr, type, suffix); + return IPLMakeSharePtr<Continue>(); } 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<UnaryExpression>(expr, type, suffix); + return IPLMakeSharePtr<Break>(); } return nullptr; } |
