diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-16 16:51:51 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-17 07:03:30 +0800 |
commit | 90e39c04d6e476491503573719c487744f529514 (patch) | |
tree | 0e307e5f4b3c5a85e4319b6167429bebed0ccbe4 /Parser.cpp | |
parent | 3f2600bb31a5a71ce4ebb4c2fa95762d68eb516b (diff) | |
download | dexon-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.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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, |