Docsity

Compiler Design - Assignment 3 Problems | CS 5300, Assignments of Computer Science

Toggle sidebar
bg1
CS 5300
Compiler Construction
Due October 5, 2005 – 40 points
Homework 3
You are allowed to work in groups, one or two people, for this assignment. When it is turned in,
submit only one copy for the group and include all names on it. The assignment is turned in on
the eagle system and you need to use .doc or .txt format.
1. Consider the grammar G1 that follows:
1. S→A 5. B→CC
2. S→B 6. B→a
3. A→aCbA 7. C→ba
4. A→ab
a. Show the left-most derivation for the string ababababab.
b. Show the right-most derivation for the string ababababab.
2. Construct the First and Follow sets for grammar G2 that follows.
First Follow
A
B
C
D
E
1. A→BCe 6. C→ea
2. A→gDB 7. D→ε
3. B→ε 8. D→dD
4. B→bCDE 9. E→gAf
5. C→DaB 10. E→e
3. For grammar G3 given below, show the LR parse for the string acddb$.
a b c D $ S A B C
0 S5 R5 S6 R7 R5 1 2 3 4
1 acc
2 R1
3 S7
4 S8
5 S5 R5 S6 R7 9 3 4
6 S5 R5 S6 R7 10 3 4
7 R2 R2 R2
8 R3 R3 R3
9 R4
10 R6
0. S'→S$
1. S→A
2. A→Bb
3. A→Cd
4. B→aA
5. B→ε
6. C→cA
7. C→ε
Homework 3 Page 1
pf2

Partial preview of the text

Download Compiler Design - Assignment 3 Problems | CS 5300 and more Assignments Computer Science in PDF only on Docsity!

CS 5300

Compiler Construction

Due October 5, 2005 – 40 points Homework 3

You are allowed to work in groups, one or two people, for this assignment. When it is turned in, submit only one copy for the group and include all names on it. The assignment is turned in on the eagle system and you need to use .doc or .txt format.

  1. Consider the grammar G 1 that follows:
    1. (^) S→A 5. (^) B→CC
    2. (^) S→B 6. (^) B→a
    3. (^) A→aCbA 7. (^) C→ba
    4. (^) A→ab

a. Show the left-most derivation for the string ababababab. b. Show the right-most derivation for the string ababababab.

  1. Construct the First and Follow sets for grammar G 2 that follows.

First Follow A B C D E

  1. (^) A→BCe 6. (^) C→ea
  2. (^) A→gDB 7. (^) D→ε
  3. (^) B→ε 8. (^) D→dD
  4. (^) B→bCDE 9. (^) E→gAf
  5. (^) C→DaB 10. (^) E→e
  6. For grammar G 3 given below, show the LR parse for the string acddb$. a b c D $ S A B C 0 S5 R5 S6 R7 R5 1 2 3 4 1 acc 2 R 3 S 4 S 5 S5 R5 S6 R7 9 3 4 6 S5 R5 S6 R7 10 3 4 7 R2 R2 R 8 R3 R3 R 9 R 10 R

0. S'→S$

1. S→A

  1. (^) A→Bb
  2. (^) A→Cd
  3. (^) B→aA
  4. (^) B→ε
  5. (^) C→cA
  6. (^) C→ε

Homework 3 Page 1

  1. Given grammar G 4 shown below:
    1. (^) S→Aa 4. (^) S→bBa
    2. S→bAc 5. A→d
    3. (^) S→Bc 6. (^) B→d a. Construct the set of LR(0) items. b. Construct the SLR(1) parse table c. Construct the set of LR(1) items. d. Construct the LR(1) parse table. e. Construct the LALR(1) parse table. f. Given the above answers, what can be said about the grammar G 4?

Homework 3 Page 2