Chapter 4: Syntax Analysis

Precedence

. String a+5*2 has two possible interpretations because of two different parse trees corresponding to

(a+5)*2 and a+(5*2)

. Precedence determines the correct interpretation.

Precedence is a simple ordering, based on either importance or sequence. One thing is said to "take precedence" over another if it is either regarded as more important or is to be performed first. For example, consider the string a+5*2. It has two possible interpretations because of two different parse trees corresponding to (a+5)*2 and a+(5*2). But the * operator has precedence over the + operator. So, the second interpretation is correct. Hence, the precedence determines the correct interpretation.