Parser: Exponentiation is right associative

This commit is contained in:
hrkrshnn
2020-10-13 16:38:37 +02:00
parent 0ea4bdafcd
commit 13e7012e1e
7 changed files with 101 additions and 40 deletions
+7 -1
View File
@@ -1606,7 +1606,13 @@ ASTPointer<Expression> Parser::parseBinaryExpression(
{
Token op = m_scanner->currentToken();
m_scanner->next();
ASTPointer<Expression> right = parseBinaryExpression(precedence + 1);
static_assert(TokenTraits::hasExpHighestPrecedence(), "Exp does not have the highest precedence");
// Parse a**b**c as a**(b**c)
ASTPointer<Expression> right = (op == Token::Exp) ?
parseBinaryExpression(precedence) :
parseBinaryExpression(precedence + 1);
nodeFactory.setEndPositionFromNode(right);
expression = nodeFactory.createNode<BinaryOperation>(expression, op, right);
}