Most languages use +
/-
for addition and subtraction, in addition to using +
/-
as unary prefix positive/negative operators (the former typically being a no-op). However, this can easily lead to ambiguity.
For example, many languages include a ++
or --
operator. Sometimes these are prefix/postfix increment or decrement operators, typically in C-like languages, and sometimes they're binary operators, such as concatenation in Haskell. When ++
is an operator, 1++2
becomes ambiguous; is it 1 ++ 2
, or 1 + (+2)
?
Another example is languages where function application doesn't require parentheses (for example, add 1 2
). In this case, even 2 - 1
could be ambiguous; is it the subtraction 2 - 1
, or is it a 2
followed by a -1
? This case could maybe be solved by tracking the number of arguments to any functions before those tokens, but this falls apart with cases like a three-argument function followed by 1 - 2 3 - 4
.
How can this ambiguity be resolved, whether by changing the syntax (such as APL's separate "high minus" for negative number literals), the parsing (such as signficant whitespace), or some other aspect of the language?
*
for multiplication, pointer dereferencing, and/or exponentiation (**
). $\endgroup$