diff --git a/poincare/src/parsing/parser.cpp b/poincare/src/parsing/parser.cpp index 2225a194f..26115d313 100644 --- a/poincare/src/parsing/parser.cpp +++ b/poincare/src/parsing/parser.cpp @@ -15,8 +15,8 @@ Expression Parser::parseUntil(Token::Type stoppingType) { typedef void (Parser::*TokenParser)(Expression & leftHandSide); static constexpr TokenParser tokenParsers[] = { &Parser::parseUnexpected, // Token::EndOfStream - &Parser::parseEqual, // Token::Equal &Parser::parseStore, // Token::Store + &Parser::parseEqual, // Token::Equal &Parser::parseUnexpected, // Token::RightBracket &Parser::parseUnexpected, // Token::RightParenthesis &Parser::parseUnexpected, // Token::RightBrace @@ -170,10 +170,8 @@ void Parser::parseEqual(Expression & leftHandSide) { } Expression rightHandSide; if (parseBinaryOperator(leftHandSide, rightHandSide, Token::Equal)) { - if (rightHandSide.type() == ExpressionNode::Type::Store) { - m_status = Status::Error; // Equal cannot have a Store on the right - return; - } + /* We parse until finding a token of lesser precedence than Equal. The next + * token is thus either EndOfStream or Store. */ leftHandSide = Equal(leftHandSide, rightHandSide); } if (!m_nextToken.is(Token::EndOfStream)) { diff --git a/poincare/src/parsing/token.h b/poincare/src/parsing/token.h index 87b8766d5..e10740685 100644 --- a/poincare/src/parsing/token.h +++ b/poincare/src/parsing/token.h @@ -17,8 +17,13 @@ public: enum Type { // Ordered from lower to higher precedence to make Parser's job easier EndOfStream = 0, // Must be the first - Equal, Store, + Equal, + /* Equal should have a higher precedence than Store, because + * Tokenizer::parseEqual looks for a right hand side until it finds a + * token of lesser precedence than Equal, and this prevents expressions + * such as "3=4>a". Tokenizer::parseStore uses a special algorithm that + * prevents (3>4=a). */ RightBracket, RightParenthesis, RightBrace,