0% found this document useful (0 votes)
240 views8 pages

Numerical Question Based On Shift Reduce Parser

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

Numerical Question Based on Shift Reduce parser

1. What do you understand by a handle? Explain the stack implementation of shift reduce
parser for string id1 + id2 * id3 $.
Productions are
E->E+T
E->E*E
E->(E)
E->id

2. Consider the grammar


S->aAcBe
AAb|b
Bd
Parse the string is “abbcde” using shift reduce parse.

3. Consider the following grammar


S0S0|1S1|2
Parse the input string “10201” using shift reduce parser.

4. Consider the grammar


E –> 2E2
E –> 3E3
E –> 4
Perform Shift Reduce parsing for input string “32423”.
5. Consider the grammar

A->A+B|B
B->B*C|C
C->(A)|id
a. Compute Leading and Trailing for each non-terminal of above grammar.
b. Construct a operator precedence table for above.
Numerical based on LL and Types of LR parser

1.

2. Do left factoring in the following grammar-


S → a / ab / abc / abcd
3. Consider the following grammar and eliminate left recursion-
X → XSb / Sa / b
S → Sb / Xa / a
4.

5.

6. Consider the given grammar with parsing table and parse (using
LL(1))the given string w=”bcba”.
SaAa|BAa|€
AcA|bA|€
B b

Parsing Table:
a b c $
S SaAa S BAa S€
A A € AbA AcA
B Bb

7. Consider the following grammar


S->iCtSS’|a
S’->es|E(epsilon)
C->b
a. Compute FIRST and FOLLOW for each non-terminal of above grammar.
b. Construct a LL(1) parsing table for above grammar.
c. Construct Predictive Parsing table for the following grammar:
d. (20)
S > (L)/ a
L > L, S/S
and check whether the following sentences belong to that grammar or not.
(i) (a,a)
(ii) (a, (a , a))
8.

9.
10. Show the following Grammar:

SAaAb|BbBa

A-> €

B-> €

Is LL(1)? and parse the input string “ba”.


11.

12.
13.

14.

15.

16. Construct the predictive parsing table for the following grammar:
SqABC
Aa|bbD
Ba|€
Cb|€
Dc|€

17. Consider the following grammar: S-> Aa|bAc|Bc|bBa

A-> d

B-> d

Compute closure and goto.

18. Construct the canonical LR parsing table for the following grammar.
E->E+T|T
T->T*F|F
F->(E)|id
a. Compute LR (0) items for the grammar
b. Show that the grammar is SLR (1)
c. Construct the SLR (1) parsing table for above grammar
d. Consider the following grammar

19. Consider the given grammar

S->L=R
S->R
L->*R
L->id
R->L
Show that the grammar is not SLR (1).

20. Consider the following grammar

S->CC
C->cC|d
(i) Compute LR (1) items for the grammar.

(ii)Construct the CLR parsing table for the grammar


21. Consider the following grammar

S->CC
C->cC|d
Find the collection of LALR(1) set of items.
(i) Draw the corresponding GOTO graph.

(iii)Construct the LALR parsing table for the grammar

22. show that the following grammar is LR(1) but not SLR(1).

S->AaAb/BbBa
A->e(epsilon)

B->e(epsilon)

23. Consider the following

grammar: E-> E+T|T

T-> TF|F

F-> F*|a|b

Construct the SLR parsing table and also parse the input “a*b+a”.

24.

25. Construct the SLR(1) parsing table for the following grammar: 8
SxAy|xBy|xAz
AqS|q
Bq

You might also like