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?

  • $\begingroup$ 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. $\endgroup$ Mar 10, 2019 at 11:03
  • $\begingroup$ 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. $\endgroup$
    – chi
    Mar 10, 2019 at 12:44
  • $\begingroup$ 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. $\endgroup$
    – MSalters
    Mar 11, 2019 at 14:20

1 Answer 1


There are computer languages with ambiguous grammars. They decide how to compile ambiguous code by applying rules outside the grammar (there’s no law saying that a language has to be defined by a grammar only). The problem is if your language is ambiguous - if you have code and cannot tell how it should be compiled, that’s quite useless.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.