CD Unit-II Questions - MSWEC
CD Unit-II Questions - MSWEC
June 2023
1 a) Explain the role of parser. Explain types of grammars used for parsing.
b) Write an algorithm for constructing a predictive parsing table. Give Example
2. a) What is an ambiguous grammar? Write a procedure to eliminate the same with
an example.
b) Consider the following grammar
S → (L) |a L → L, S |S
Construct leftmost and Right most derivations and parse trees for the following
sentences:
i) (a,(a,a))
ii) (a,((a,a),(a,a))).
May/June – 2024
11. a) Consider the following grammar which is used for specifying subset of arithmetic
expressions in C
A -> A - id | -A | id
i) Construct a parse tree for the string id-id-id
ii) Prove that the above grammar ambiguous
b) Explain with an example “why left recursion is an issue in top down parsing”
and write steps for left recursion elimination
12. Construct a LL(1) parsing table for the following grammar and show the working
of parser on input -id-id-id
A -> A -id | B
B -> -A | id
13. a) Consider the following grammar which is used for specifying logical
expressions in python
L ->L and L | L or L |not L | TRUE | FALSE
i) Construct parse tree(s) for the string
not TRUE and FALSE
ii) Prove that the above grammar ambiguous
b) Explain with an example “why common left factors is an issue in top down
parsing” and write steps for left factoring
14. Construct a LL(1) parsing table for the following grammar and show the
working of parser on inputnot TRUE and FALSE
L -> L orB | B
B ->BandC | C
C ->not L | TRUE | FALSE
15. a) Consider the following grammar which is used for specifying subset of
arithmetic expressions in C, where num is an integer constant
E ->num –E | num + E | num
i) Construct a parse tree for the string
num – num - num + num
ii) As per the grammar given above , what is the result of the
expression 9-5-2+4
b) Explain dangling else problem and what is the solution for it as per the C
language specification.
16. Construct a LL(1) parsing table for the following grammar and show the
working of parser on input aa+a*
S-> SS + | SS * | a
17. a) Consider the following grammar which is used for specifying subset of
arithmetic expressions in C, where num is an integer constant
E -> num * E| num/E | num
i) Construct a parse tree for the string
num / num / num * num
ii) As per the grammar given above, what is the result of the
expression 12 / 12 / 2 * 3
b) Explain with an example “why ambiguity is an issue in parsing” and write an
intuitive argument why it is difficult to solve.
18. Construct a LL(1) parsing table for the following grammar and show the
working of parser on input ((a,a),a,(a))
S-> (L) | a
L-> L, S | S
November -2024
19 . a) Verify whether the following grammar is LL(1) or not?
E →E + T | T
T →T * F / F
F →(F) | a| b.