# Is ambiguity in Programming Language always bad?

Suppose we have a token and our language allows the compiler to build two different derivation trees. However, it can happen that there exists two semantic ways to interpret our token. So ambiguity is not a problem in this case. Am I correct?

• Are you talking about "tokens" as in "lexical analysis" and are the derivation trees supposed to be those of the parsing stage? If so, you should note that that's not "semantics", it's just a way of translating human-readable strings to a better representation of syntax (trees). But in general such ambuguity is problematic because it is confusing to humans. – Andrej Bauer Mar 10 '19 at 11:03
• If the same program can cause different behaviors, due to ambiguities in parsing or in the semantics, it can not easily used by programmers. Programmers need to either 1) avoid using that program (e.g. undefined behavior in C), or 2) use it very carefully, without assuming its behavior is completely determined. It might happen that the program is working just fine, and then it stops working as expected because the language implementation suddenly switched to another behavior. – chi Mar 10 '19 at 12:44
• I can probably craft an example where a+b+c=(a+b)+c=a=(b+c), i.e. where the ambiguity doesn't matter because the resulting evaluations are mathematically identical. But this breaks down when addition is not associative, as in IEEE754. – MSalters Mar 11 '19 at 14:20