Skip to content

[SUGGESTION] Disambiguate postfix unary and binary operators #152

Closed
@msadeqhe

Description

@msadeqhe

Currently in Cpp2:

  1. Expression x&&y is equivalent to (x&) & (y), because there is no whitespace before the first symbol &.
  2. Expression x && y is 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:

  1. 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&&&y will be logical && operator (because && is a valid binary operator and also it has more symbols than binary & operator).
  2. After Cpp2 has found the binary operator, it will treat the rest of symbols as postfix unary operators.

For example:

  1. Expression x&&y is equivalent to (x) && (y).
  2. Expression x && y is equivalent to (x) && (y).
  3. Expression x & & y is equivalent to (x&) & (y).
  4. Expression x& & y is equivalent to (x&) & (y).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions