quiz4-example-soln-fall11

# quiz4-example-soln-fall11 - &-expressions as much as...

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

CMSC330 Fall 2011 Example Quiz #4 Solution 1. (14 pts) Parsing Consider the following grammar: S aA | A A bS | ca a. (6 pts) Compute First sets for S and A First(A) = First(bS) ± First(ca) = {b, c} First(S) = First(aA) ± First(A) = {a, b, c} b. (12 pts) Write a predictive, recursive descent parser for the grammar parse_S( ) { if (lookahead == “a”) { // S aA match(“a”); parse_A( ); } else if ((lookahead == “b”) || (lookahead == “c”)) { // S A parse_A( ); } else error( ); } parse_A( ) { if (lookahead == “b”) { // A bS match(“b”); parse_S( ); } else if (lookahead == “c”) { // S aA match(“c”); match(“a”); } else error( ); }

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

View Full Document
2. (16 pts) Lambda calculus Circle all free (unbound) variables in the following & -expression a. (2 pts) ( a. a ( b. b a ) a b ) a ( a. a ( b. b a ) a b ) a Evaluate the following
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &-expressions as much as possible. Show each beta-reduction b. (3 pts) ( & x. & y.y x) a ( & z.z) b ( & x . & y.y x) a ( & z.z) b ± ( & y .y a) ( & z.z) b ± (( & z .z) a) b ± a b c. (3 pts) ( & y. & x. x y) x a b ( & y. & x . x y) x a b ± ( & y . & z. z y) x a b ± ( & z . z x) a b ± a x b d. (8 pts) Using encodings, show 3*1 =>* 3. Show each beta-reduction. =>* indicates 0 or more steps of beta-reduction 3*1 => & x.(3 (1 x)) => & x.(3 (( & f . & y.f y) x)) => & x.(3 ( & y.x y)) => & x.( & f. & y.f (f (f y)) ( & y.x y)) => & x.( & y.( & y.x y) (( & y.x y) (( & y .x y) y))) => & x.( & y.( & y.x y) (( & y .x y) (x y))) => & x.( & y.( & y .x y) (x (x y))) => & x.( & y.x (x (x y))) => 3 M * N = & x.(M (N x)) 1 = & f. & y.f y 2 = & f. & y.f (f y) 3 = & f. & y.f (f (f y)) 4 = & f. & y.f (f (f (f y)))...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

quiz4-example-soln-fall11 - &-expressions as much as...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online