{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw4_solution

# hw4_solution - CS150 Homework 4 Due 5/24 Problem 1(10...

This preview shows pages 1–4. Sign up to view the full content.

CS150 Homework 4 Due 5/24 Problem 1. (10 points) Construct a CFG for the set of all ternary strings of the form 0 i 1 j 2 k , where i + j = k . S 0 S 2 | X X 1 X 2 | ² 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem 2. (Exercise 5.2.1, 10 points) For the grammar and each of the strings in Exercise 5.1.2, give parse tree. Exercise 5.1.2: The following grammar generates the language of regular expression 0 * 1(0 + 1) * : S A 1 B A 0 A | ² B 0 B | 1 B | ² (a) 00101. (b) 1001. (c) 00011. (a) 00101 S A B 1 0 A B 0 1 B A 0 ² ² (b) 1001 S A B 1 B 0 B 0 B 1 ² ² (c) 00011 S A B 1 0 A B A 0 1 A 0 ² ² 2
Problem 3. (Exercise 5.4.7, 20 points) The following grammar generate prefix expressions with operands x and y and binary operators +, - , and * : E + EE | * EE | - EE | x | y (a) Find leftmost and rightmost derivations, and a derivations tree for the string +*-xyxy . (b) Prove that this grammar is unambiguous. ( Hint : show that the leftmost derivation is unique for any given input string. (a) Leftmost derivation: E lm + EE lm + * EEE lm + * - EEEE lm + * - xEEE lm + * - xyEE lm + * - xyxE lm + * - xyxy Rightmost derivation: E rm + EE rm + Ey rm + * EEy rm

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern