quiz4-soln-fall11

# quiz4-soln-fall11 - a. (1 pt) ( & x.y) z ( & x .y)...

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

CMSC330 Fall 2011 Quiz #4 Solution 1. (6 pts) First Sets Calculate the FIRST set for S, A, and B in the following grammar: S Adg | Bh FIRST(S) = FIRST(Adg) ± FIRST(Bh) = { a, d, f, g } A aBc | epsilon FIRST(A) = FIRST(aBc) ± FIRST(epsilon) = { a, epsilon } B f | g FIRST(B) = FIRST(f) ± FIRST(g) = { f, g } 2. (10 pts) Parsing Write a predictive, recursive descent parser for the following grammar. You may assume the existence of a match ( ) function for terminals that will update the value for the lookahead token. S bAb | c A ad | epsilon parse_S( ) { if (lookahead == “b”) { // S bAb match(“b”); parse_A( ); match(“b”); } else if (lookahead == “c”) { // S c match(“c”); } else error( ); } parse_A( ) { if (lookahead == “a”) { // A ad match(“a”); match(“d”); } else ; // A epsilon }

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

View Full Document
3. (6 pts) Lambda calculus Evaluate the following & -expressions as much as possible. Show each beta-reduction
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a. (1 pt) ( & x.y) z ( & x .y) z ± y b. (1 pt) ( & x. & y.x y) a b ( & x . & y.x y) a b ± ( & y .a y) b ± a b c. (2 pts) ( & x.x x) ( & z.z) a b ( & x .x x)( & z.z)a b ± ( & z .z)( & z.z)a b ± ( & z .z)a b ± a b d. (2 pts) ( & x. & y.x) y a b ( & x. & y .x) y a b ± ( & x . & z.x) y a b ± ( & z .y) a b ± y b 4. (8 pts) Lambda calculus encodings a. Using encodings, show 1*1 =>* 1. Show each beta-reduction. =>* indicates 0 or more steps of beta-reduction 1*1 => & x.(1 (1 x)) => & x.(1 (( & f . & y.f y) x)) => & x.(1 ( & y.x y)) => & x.( ( & f. & y.f y) ( & y.x y)) => & x.( & y.( & y .x y) y) => & x.( & y.x y) => 1 OR 1*1 => & x.(1 (1 x)) => & x.(( & f . & y.f y) (1 x)) => & x.( & y.(1 x) y) => & x.( & y.(( & f. & y.f y) x) y) => & x.( & y.( & y .x y) y) => & x.( & y.x y) => 1 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

## This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

### Page1 / 2

quiz4-soln-fall11 - a. (1 pt) ( & x.y) z ( & x .y)...

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

View Full Document
Ask a homework question - tutors are online