0% found this document useful (0 votes)
21 views3 pages

CD Unit-II Questions - MSWEC

The document consists of a series of questions related to parsing and grammars, covering topics such as the role of parsers, types of grammars, predictive parsing, left recursion, and ambiguity in grammars. It includes algorithms for constructing predictive parsing tables, eliminating ambiguities, and various parsing techniques. Additionally, it provides examples and exercises for constructing parse trees and analyzing different grammars used in programming languages.

Uploaded by

vkrao1984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

CD Unit-II Questions - MSWEC

The document consists of a series of questions related to parsing and grammars, covering topics such as the role of parsers, types of grammars, predictive parsing, left recursion, and ambiguity in grammars. It includes algorithms for constructing predictive parsing tables, eliminating ambiguities, and various parsing techniques. Additionally, it provides examples and exercises for constructing parse trees and analyzing different grammars used in programming languages.

Uploaded by

vkrao1984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CD Unit-2 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))).

3. a) Compute FIRST and FOLLOW for the grammar:


S → S S + \ S S * \ a.
b) Write about various types of top down parsing. Discuss about the error recover
in predictive parsing.
4. a) Give an algorithm to eliminate productions containing useless symbols and
ambiguous productions from a grammar.

b) Construct predictive parse table for the following grammar.


E → E + T/T
T → T *F/F
F → F /a/b
5. a) Define Context Free Grammar. Explain how it is suitable for parsing? Explain
the recursive descent parser with example.
b) Design a non-recursive predictive parser for the following grammar:
S → AaAb | BbBb
A→ e
B → e where a, b, e are terminals.

6. a) Given the following grammar: E -> E + E | E - E | E * E | E / E | - E | int Show


two different left-most derivations with the help of parse trees for the string
int + int * int / int.
What does this tell you?
b) Explain left recursion and left factoring with examples.
7. a) What are the preprocessing steps required for constructing Predictive parsing
table. Explain with example.
b) Define a Parser. What is the role of grammars in Parser construction? Construct
the Predictive parsing table for the grammar
G: E → E+T |T, E →T*F |F, F →(E) |id.
8. a) What is an LL(1) grammar? Can you convert every context free grammar into
LL(1). How to check the grammar is LL(1) or not? Explain the rules,
b) Consider the following grammar
E → T + E|T
T→V*T|V
V → id
Write down the procedures for the non-terminals of the grammar to make a
recursive descent parser.
December -2023
9. a) What is an ambiguous grammar? Write a procedure to eliminate the same with
an example.
b) Given the following grammar:
E → E + E | E - E | E * E | E / E | - E | int
Show two different left-most derivations with the help of parse trees for the
string
int + int * int / int.
What does this infer?
10. a) Write an algorithm for constructing Predictive parsing table.
b) Explain left recursion and left factoring with examples.

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.

b) Explain left recursion and left factoring with examples.

20 a) Eliminate ambiguities from the following grammar


S →iEtSeS|iEtS|a
E →b|c|d
b) Explain in detail about the Non Recursive Predictive Parsing.

You might also like