aboutsummaryrefslogtreecommitdiffstats
path: root/Parser.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-12-16 16:51:51 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-12-17 07:03:30 +0800
commit90e39c04d6e476491503573719c487744f529514 (patch)
tree0e307e5f4b3c5a85e4319b6167429bebed0ccbe4 /Parser.cpp
parent3f2600bb31a5a71ce4ebb4c2fa95762d68eb516b (diff)
downloaddexon-solidity-90e39c04d6e476491503573719c487744f529514.tar
dexon-solidity-90e39c04d6e476491503573719c487744f529514.tar.gz
dexon-solidity-90e39c04d6e476491503573719c487744f529514.tar.bz2
dexon-solidity-90e39c04d6e476491503573719c487744f529514.tar.lz
dexon-solidity-90e39c04d6e476491503573719c487744f529514.tar.xz
dexon-solidity-90e39c04d6e476491503573719c487744f529514.tar.zst
dexon-solidity-90e39c04d6e476491503573719c487744f529514.zip
Solidity ForStatements expressions are now optional
Diffstat (limited to 'Parser.cpp')
-rw-r--r--Parser.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/Parser.cpp b/Parser.cpp
index d936cfc7..598f5ad4 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -374,14 +374,25 @@ ASTPointer<WhileStatement> Parser::parseWhileStatement()
ASTPointer<ForStatement> Parser::parseForStatement()
{
ASTNodeFactory nodeFactory(*this);
+ ASTPointer<ASTNode> initExpression;
+ ASTPointer<Expression> conditionExpression;
+ ASTPointer<ExpressionStatement> loopExpression;
expectToken(Token::FOR);
expectToken(Token::LPAREN);
- ASTPointer<ASTNode> initExpression = parseVardefOrExprstatement();
+
+ // LTODO: Maybe here have some predicate like peekExpression() instead of checking for semicolon and RPAREN?
+ if (m_scanner->getCurrentToken() != Token::SEMICOLON)
+ initExpression = parseVardefOrExprstatement();
expectToken(Token::SEMICOLON);
- ASTPointer<Expression> conditionExpression = parseExpression();
+
+ if (m_scanner->getCurrentToken() != Token::SEMICOLON)
+ conditionExpression = parseExpression();
expectToken(Token::SEMICOLON);
- ASTPointer<ExpressionStatement> loopExpression = parseExpressionStatement();
+
+ if (m_scanner->getCurrentToken() != Token::RPAREN)
+ loopExpression = parseExpressionStatement();
expectToken(Token::RPAREN);
+
ASTPointer<Statement> body = parseStatement();
nodeFactory.setEndPositionFromNode(body);
return nodeFactory.createNode<ForStatement>(initExpression,