From 7eefa838a3384d3a8a81d73d7e544afa7f3193fc Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Tue, 22 Dec 2015 16:47:55 +0000 Subject: [cond-expr] parse _ ? _ : _ into conditional AST node --- libsolidity/parsing/Parser.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 4ac3381c..cc06eb87 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -932,13 +932,26 @@ ASTPointer Parser::parseExpression( ) { ASTPointer expression = parseBinaryExpression(4, _lookAheadIndexAccessStructure); - if (!Token::isAssignmentOp(m_scanner->currentToken())) + if (Token::isAssignmentOp(m_scanner->currentToken())) + { + Token::Value assignmentOperator = expectAssignmentOperator(); + ASTPointer rightHandSide = parseExpression(); + ASTNodeFactory nodeFactory(*this, expression); + nodeFactory.setEndPositionFromNode(rightHandSide); + return nodeFactory.createNode(expression, assignmentOperator, rightHandSide); + } + else if (m_scanner->currentToken() == Token::Value::Conditional) + { + m_scanner->next(); + ASTPointer trueExpression = parseExpression(); + expectToken(Token::Colon); + ASTPointer falseExpression = parseExpression(); + ASTNodeFactory nodeFactory(*this, expression); + nodeFactory.setEndPositionFromNode(falseExpression); // TODO: + return nodeFactory.createNode(expression, trueExpression, falseExpression); + } + else return expression; - Token::Value assignmentOperator = expectAssignmentOperator(); - ASTPointer rightHandSide = parseExpression(); - ASTNodeFactory nodeFactory(*this, expression); - nodeFactory.setEndPositionFromNode(rightHandSide); - return nodeFactory.createNode(expression, assignmentOperator, rightHandSide); } ASTPointer Parser::parseBinaryExpression( -- cgit