|
|
|
|
|
by tsimionescu
24 days ago
|
|
Contradicting highly ingrained precedence rules for the common operations (+, -, ×) is a huge flaw for strict left to right parsing. And for ?:, only the part between the ? and the : is implicitly paranthesized. In "a && b ? c : d || e", you need operator precedence to decide if this is "a && (b ? c : d) || e" or "(a && b)? c : (d || e)" or any other combination. So you have to define the precedence of ? and : in relation to other operators in order to define the syntax of your language, so I think it's normal to consider it an operator as well (and I'd say the same for Python's if/else conditional expression, "a if b else c", this is not about the characters used). |
|
> for ?:, only the part between the ? and the : is implicitly paranthesized.
That is a choice. If you treat it as an operator, yes. But you don't have to. It can be treated as a language construct. Given the grammar expr ? expr : expr the trailing portion is akin to a set of brackets or parenthesis, greedily consuming all until end of line.