4 ms·
> (5 + 1) * 2 That’s six expressions, not five. Josh conflates the the addition expression and the parenthesised expression, but they’re distinct (even if you
by chrismorgan 4y ago
> (5 + 1) * 2
That’s six expressions, not five. Josh conflates the the addition expression and the parenthesised expression, but they’re distinct (even if you couldn’t represent the semantics without the parenthesis due to operator precedence).
Here’s an approximate representation of the parse tree, indicating which nodes are expressions:
MultiplicativeExpression { ←
ParenthesizedExpression { ←
AdditiveExpression { ←
DecimalIntegerLiteral("5") ←
"+"
DecimalIntegerLiteral("1") ←
}
}
"*"
DecimalIntegerLiteral("2") ←
}