4 ms·
> Problem statement: it’s hard to describe arithmetic expressions in a way that: > - declaratively captures the overall shape of expression, and > - has a
by thomastjeffery 2y ago
> Problem statement: it’s hard to describe arithmetic expressions in a way that:
> - declaratively captures the overall shape of expression, and
> - has a clear precedence semantics
I'm pretty distracted here. The answer to that question is either postfix or guaranteed parenthesis. Precedence is only ever used with mathematical operators anyway...
> ...it doesn’t tell whether * or + binds tighter, and their associativity.
Associativity isn't defined by grammar. It's defined by mathematical proof. You can write 2+4 or 4+2, and predict that they will evaluate to the same 6, but the grammar sees two entirely different expressions. Just because you know two syntax trees are equivalent doesn't mean they will ever be the same. Parsing is not arithmetic.
- anonymoushn 2y agoAssociativity in this context doesn't mean "The associative property," it means "left-associative or right-associative" https://en.wikipedia.org/wiki/Operator_associativity https://en.wikipedia.org/wiki/Operator_associativity