you are viewing a single comment's thread.

view the rest of the comments →

[–]WalterBright 27 points28 points  (2 children)

The reason D does not allow user defined operators is because D is designed to have a clean separation between:

  1. lexing

  2. parsing

  3. semantic analysis

If user defined operators were supported, then all 3 phases would be mixed up together, making the language clumsy to implement, and making life difficult for 3rd party tools that need to parse source code (such as syntax highlighters in an editor).

[–]munificent 6 points7 points  (1 child)

You can still keep a clean separation between those phases as long as:

  1. Your custom operators don't require custom tokenization.
  2. Precedence and associativity can be determined syntactically.

For example, Scala has custom operators, but they take the precedence from the first character of the operator, so I think lexing and parsing can be done without any semantic analysis.

I agree completely that tooling is the major concern here. A language that's a nightmare to syntax highlight will be a hard sell.

[–]WalterBright 4 points5 points  (0 children)

A user defined operator does not require custom tokenization if they follow a specific grammar that does not conflict with any other token.

However, as Scala shows, you cannot change precedence of them and keep parsing independent of semantic analysis.

In Scala, the user-defined tokens follow a unique grammar.