Compiler design miscellaneous
- Consider the grammar S → (S) | a
Let the number of states in SLR (1), LR(1) and LALR (1) parsers for the grammar be n1, n2 and n3 respectively. Which of the following relationships holds good?
-
View Hint View Answer Discuss in Forum
The no. of states for SLR(1) &LALR(1) are equal so n 1 = n3, but CLR(1) or LR(1) will have no. of states greater than LALR &LR(0) both.
Correct Option: B
The no. of states for SLR(1) &LALR(1) are equal so n 1 = n3, but CLR(1) or LR(1) will have no. of states greater than LALR &LR(0) both.
Direction: Consider the following expression grammar. The semantic rules for expression evaluation are stated next to each grammar production.
E → number | E.val = number.val |
| E ‘+’ E | E(1).val = E(2).val + E(3).val |
| E ‘×’ E | E (1).val = E(2).val × E(3).val |
- Assume the conflicts in Part (a) of this question are resolved and an LALR(1) parser is generated for parsing arithmetic expressions as per the given associativity properties does the generated parser realize?
-
View Hint View Answer Discuss in Forum
The grammar has equal precedence and it is also ambiguous. Since LALR(1) parser prefer shift over reduce so + operation will be executed here before). 2 + 1 = 3 & 3 #3 = 9 also the operators are right associative. Hence (b) is correct option.
Correct Option: B
The grammar has equal precedence and it is also ambiguous. Since LALR(1) parser prefer shift over reduce so + operation will be executed here before). 2 + 1 = 3 & 3 #3 = 9 also the operators are right associative. Hence (b) is correct option.
- The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?
-
View Hint View Answer Discuss in Forum
Yacc tool is used to create a LALR(1) parser. This parser can detect the conflicts but to resolve the conflicts it actually prefers shift over reduce action.
Correct Option: C
Yacc tool is used to create a LALR(1) parser. This parser can detect the conflicts but to resolve the conflicts it actually prefers shift over reduce action.