

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: COMPILER CONSTRUCTION; Subject: Computer Science; University: Rice University; Term: Fall 2008;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


COMP 412 Fall 2008 Homework 2 Due: Monday, Oct 6th
Problem 1 (20 points) Consider the grammar S โ ( L ) | a L โ L , S | S (a) What are the terminals, nonterminals and start symbol? (b) Find parse trees for the following sentences: i) (a, a) ii) (a, (a, a)) (c) Construct the leftmost derivation for each of the sentences in (b) (d) Construct the rightmost derivation for each of the sentences in (b)
Problem 2 (20 points) Consider the grammar S โ aSbS | bSaS | (a) Show the grammar is ambiguous by constructing two different leftmost derivations for the sentence abab. (b) Construct the corresponding rightmost derivations for abab. (c) Construct the corresponding parse trees from parts (a) and (b) for abab. (d) What can you conclude from the parse trees in part (d)?
Problem 3 (20 points) A grammar symbol X is defunct if there is no derivation of the form S โโ^ wXy โโ^ wxy, where X โ V and w, x, y โ ฮฃโ. That is, X can never appear in the derivation of some sentence. (a) Write an algorithm to eliminate all productions containing defunct symbols from the grammar. (b) Apply your algorithm to the grammar below. Describe the steps your algorithm takes. S โ 0 | A A โ AB B โ 1 1
Problem 4 (20 points) Section 3.3, question 2 (page 730 in EAC)
Problem 5 (20 points) Section 3.5, question 1 (pages 731 & 732 in EAC)