-
Notifications
You must be signed in to change notification settings - Fork 269
Closed
Labels
Description
Currently in Cpp2:
- Expression
x&&yis equivalent to(x&) & (y), because there is no whitespace before the first symbol&. - Expression
x && yis equivalent to(x) && (y), because there is a whitespace before the first symbol&.
Although x&&y and x && y are too much similar in the syntax, but they have completely different results. A typical programmer expects x&&y and x && y to be equivalent to (x) && (y).
Cpp2 can be simpler with less surprising results, less programmer responsibility to care about the syntax, if Cpp2 uses the following rule to disambiguate postfix unary and binary operators:
- If there is a combination of operators between two identifiers or literals or parenthesis, Cpp2 should check whether the last symbols are a valid binary operator, in a way that Cpp2 will try to find the biggest possible match for the binary operator. e.g. the binary operator for
x&&&ywill be logical&&operator (because&&is a valid binary operator and also it has more symbols than binary&operator). - After Cpp2 has found the binary operator, it will treat the rest of symbols as postfix unary operators.
For example:
- Expression
x&&yis equivalent to(x) && (y). - Expression
x && yis equivalent to(x) && (y). - Expression
x & & yis equivalent to(x&) & (y). - Expression
x& & yis equivalent to(x&) & (y).
Reactions are currently unavailable