Professional Documents
Culture Documents
Assignment #2
SECTION A (1*10=10 Marks)
1 LR Parser is a type of ____________ parser.
a) Top-Down b) Bottom-Up. c) Left-Right d) Right-Left
2 In LR parser, what does R stand for?
a) Rightmost Derivation. b) Rational Derivation
c) Roaming Derivation d) Real Time Derivation
3 Which of these is a component of LR Parser?
a) Stack b) Input Buffer c) Parsing Table d) All of these.
4 Which of these is not a component of the parsing table?
a) Goto b) Action c) Buffer. d) States
5 In the LALR parser, what does LA stand for?
a) Logic Acceptance b) Loop Ahead
c) Look Ahead. c) Loop Acceptance
6 Which parser is largest in size?
a) LALR b) SLR c) CLR. d) GLR
7 LR Parser is also called LR(k) parser.
a) True. b) False
8 ________ item consists of productions of grammar with dots at some point on the
right side.
a) LR(0). b) LL(0) c) LR(1) d) SLR(1)
9 Which parser provides immediate error detection?
a) LALR. b) SLR c) CLR d) GLR
10 __________ action is taken when parsing is complete.
a) forward b) parse c) accept. d) reduce
SECTION B (2*4=8)
1. What are the demerits of SLR parser?
Ans:
A. On single input, State may include a Final Item and a Non- Final Item. This may
result in a Shift-Reduce Conflict.
B. A State may include Two Different Final Items. This might result in a Reduce-Reduce
Conflict.
C. SLR(1) Parser reduces only when the next token is in Follow of the left-hand side of
the production.
D. SLR(1) can reduce shift-reduce conflicts but not reduce-reduce conflicts
2. Define parsing. What is the role of a parser?
Ans: Parsing is the process of identifying tokens within a data instance and looking for
recognizable patterns. The role of a parser is to segregate each word, attempt to determine the
relationship between the word and previously defined token sets, and then form patterns from
sequences of tokens.
3. What is a Simple LR parser or SLR parser?
Ans: A Simple LR or SLR parser is a type of LR parser with small parse tables and a
relatively simple parser generator algorithm. SLR parser is quite efficient at finding the single
correct bottom-up parse in a single left-to-right scan over the input stream, without
guesswork or backtracking.
FIRST(α)
If a is any string of grammar symbols, let FIRST(α) be the set of terminals that begin the
strings derived
from α. If α => ε then ε is also in FIRST(α).
FOLLOW(A)
Define FOLLOW(A), for nonterminal A, to be the set of terminals a that can appear
immediately to the right of A in some sentential form, that is, the set of terminals a such that
there exists a derivation of the form S=αAaꞵ for some α and ꞵ. Note that there may, at some
time during the derivation, have been symbols between A and a, but if so, they derived ε and
disappeared. If A can be the rightmost symbol in some sentential form, then $, representing
the input right endmarker, is in FOLLOW(A).
2. Define handle. Write a short note on handle pruning.
A Handle is a substring that matches the body of a production. Handle reduction is a step in
the reverse of rightmost derivation. A rightmost derivation in reverse can be obtained by
handle pruning.
a. E → E+T | T
T → T*F | F
F → (E) | id
b. E → TE′
E′ → +TE′ | ε
T′ → FT′
T → *FT′| ε
F → (E) | id
Ans:
E → TE’
E’ → +TE’ | ε
T → FT’
T’ → *FT’ | ε
F → (E) | id
First( ) :
FIRST(E) = { ( , id}
FIRST(E’) ={+ , ε }
FIRST(T) = { ( , id}
FIRST(T’) = {*, ε }
FIRST(F) = { ( , id }
Follow( ):
FOLLOW(E) = { $, ) }
FOLLOW(E’) = { $, ) }
FOLLOW(T) = { +, $, ) }
FOLLOW(T’) = { +, $, ) }
FOLLOW(F) = {+, * , $ , ) }
E → E+T | T
T → T*F | F
F → (E) | id
Ans: Page: 31
https://www.jntua.ac.in/gate-online-classes/registration/downloads/material/a1592805
08451.pdf