22FA CSC321-PRINCIPLES OF PROGRAMMING LANG 98312 Modify the following ambiguous grammar to unambiguous grammar that takes precedence of operator * over + ->= ->+|*| ->a|b|c For example, using the above grammar we can create two parse trees (different meanings) for: c=a+b*c Test cases for your new grammar: c=a+b*c, c=a*b+c, c=a, c=a+b
I need help with the following
Unambiguous Grammar
A grammar can be unambiguous if the grammar does not contain ambiguity that means if it does not contain more than one leftmost derivation or more than one rightmost derivation or more than one parse tree for the given input string.
To convert ambiguous grammar to unambiguous grammar, we will apply the following rules:
1. If the left associative operators (+, -, *, /) are used in the production rule, then apply left recursion in the production rule. Left recursion means that the leftmost symbol on the right side is the same as the non-terminal on the left side. For example,
- X → Xa
2. If the right associative operates(^) is used in the production rule then apply right recursion in the production rule. Right recursion means that the rightmost symbol on the left side is the same as the non-terminal on the right side. For example,
- X → aX
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images