10
votes
How can ambiguity with unary and binary operators be resolved?
Who says you have to?
Never mind that APL has a separate "high minus" for negative literal numbers, the APL unary/binary operators (called monadic/dyadic functions in APL lingo) scheme is ...
9
votes
How can ambiguity with unary and binary operators be resolved?
This is called maximal munch, and is usually handled during lexing. It means that the lexer will make the tokens as large as possible. This is obvious with identifiers, ...
9
votes
How can ambiguity with unary and binary operators be resolved?
Require parentheses whenever different operators are mixed
Whenever different operators appear in the same expression, whether infix, prefix, or postfix, they must be fully parenthesised. No ...
7
votes
How can ambiguity with unary and binary operators be resolved?
In Haskell and ML, which don't use parenthesis for function calls, their solution to the problem is that they require parenthesis around unary operators:
f x (-1)
7
votes
How can ambiguity with unary and binary operators be resolved?
Spacing
Swift allows a * b and a*b for infix operators, but a *b is interpreted as a prefix ...
7
votes
How can single-item tuples be disambiguated from the grouping operator?
Rust-style: Trailing comma
Since Rust allows and even encourages trailing commas in arrays, structs, and so on, it also allows them in tuples, giving you a simple, unambiguous single-item tuple syntax:...
4
votes
Prior art on precedence rules on template instantiation for inner entity clashes
In C#, it's not an error. If E is Exception, then the first catch gets executed:
...
3
votes
How can ambiguity with unary and binary operators be resolved?
If you do come across any conflicts that may arise from a clash between unary and binary operators, I'd recommend checking out a language with a similar set of operators to see how they handle them. ...
3
votes
How can single-item tuples be disambiguated from the grouping operator?
Labels
Some languages, such as Swift and C#, let you label the items in tuple types:
...
1
vote
How can single-item tuples be disambiguated from the grouping operator?
Compiler inference
Another, more complex option would be compiler inference. In a statically and strongly typed language, and one where few operators can be used on a tuple, it may be relatively ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ambiguity × 4syntax × 2
language-design × 1
parsing × 1
operators × 1
language-comparison × 1
semantics × 1
grammar × 1
generics × 1
tuple × 1
compiler-inference × 1