Parsing & Syntax Analysis

Answer & solution
Official answer: 9.0 : 9.0
Our answer: 9
Addition has highest precedence, giving 5+1=6. The remaining subtraction is right-associative, so 2−6−7 groups as 2−(6−7)=3. Multiplication has lowest precedence, producing 3*3=9.
Insert parentheses in precedence order before calculating: the expression becomes (2−(5+1)−7)*3, then right associativity changes the subtraction part to 2−((5+1)−7). The inner result 6−7 is−1, so the outer result is 3 and multiplying by 3 gives 9. Ordinary arithmetic precedence would put multiplication first and produce a different result; this question intentionally defines a different expression grammar.