2nd production is
T → T * U (left recursive) so * is left associative.
Similarly
P → Q + P (Right recursion) so + is right associative.
Theory of Computation and Compilers MCQ - Syntax Analysis
12
Match the following:
Codes:
| List-I | List-II | ||
| A. | Lexical analysis | 1. | Graph coloring |
| B. | Parsing | 2. | DFA minimization |
| C. | Register allocation | 3. | Post-order traversal |
| D. | Expression evaluation | 4. | Production tree |
| A | B | C | D | |
| (a) | 2 | 3 | 1 | 4 |
| (b) | 2 | 1 | 4 | 3 |
| (c) | 2 | 4 | 1 | 3 |
| (d) | 2 | 3 | 4 | 1 |
The match are as follows
Lexical analysis – DFA minimization
Parsing – Production Tree
Register allocation – Graph coloring
expression evaluation – Post order traversal
left recursion: A → Aα/β
After removing left recursion it can be written as
A → βA’
A' → αA'/ε
So apply above rule for Variable E and T resultant
grammar is
E → TX
X → – TX|ε
T → FY
Y → +FY|ε
F → (E) → id
- A Equal precedence and left associativity; expression is evaluated to 7
- B Equal precedence and right associativity; expression is evaluated to 9
- C Precedence of 'x' is higher than that of '+', and both operators are left associative; expression is evaluated to 7
- D Precedence of '+' is higher than that of 'x', and both operators are left associative; expression is evaluated to 9
With look ahead, we would prefer to shift because the look ahead has higher precedence than X over + and both operation are left associative. So expression 3 x 2 + 1 = 6 + 1 = 7 will be evaluated.