Associativity
. If an operand has operator on both the sides, the side on which operator takes this operand is the associativity of that operator
. In a+b+c b is taken by left +
. +, -, *, / are left associative
. ^, = are right associative
. Grammar to generate strings with right associative operators
right à letter = right | letter
letter a| b |.| z
A binary operation * on a set S that does not satisfy the associative law is called non-associative.
A left-associative operation is a non-associative operation that is conventionally evaluated from left to right i.e., operand is taken by the operator on the left side.
For example,
6*5*4 = (6*5)*4 and not 6*(5*4)
6/5/4 = (6/5)/4 and not 6/(5/4)
A right-associative operation is a non-associative operation that is conventionally evaluated from right to left i.e., operand is taken by the operator on the right side.
For example,
6^5^4 => 6^(5^4) and not (6^5)^4)
x=y=z=5 => x=(y=(z=5))
Following is the grammar to generate strings with left associative operators. (Note that this is left recursive and may go into infinite loop. But we will handle this problem later on by making it right recursive)
left left + letter | letter
letter a | b | .... | z
|