{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw4cs441f10-key

# hw4cs441f10-key - FOLLOW(A = \$ parse_S if id == match...

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

CS441 HW4 Fall 2010 Sample solution based on student's submission Two sentences: a{a}a {a}{a} a. We must first eliminate left recursion for S. If we designate {S}S as alpha, and (A) and a as betas, we can generate S' with S' -> alphaS'|eps and S becomes S-> beta1S'|beta2S' , leaving us with: S -> (A)S' | aS' S' -> {S}SS' | eps A -> {S}A | eps b. S' and A are both nullable so only S requires error handling. FIRST(S) = {'(' , 'a'} FOLLOW(S) = { '}', \$ } FIRST(S') = {'{' , eps } FOLLOW(S') = { '}', \$ } FIRST(A) = {'{', eps } FOLLOW(A) ={')', \$ }

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.

Unformatted text preview: FOLLOW(A) ={')', \$ } parse_S() if( id == '(' ) match( '(' ) parse_A() match( ')' ) parse_S'() elseif( id == 'a' ) match( 'a' ) parse_S'() else error() parse_S'() if( id == '{' ) match( '{' ) parse_S() match( '}' ) parse_S() parse_S'() parse_A() if( id == '{' ) match( '{' ) parse_S() match( '}' ) parse_A() c. (){a}() parse_S() match( '(' ) parse_A() match( ')' ) parse_S'() match( '{' ) parse_S() match( 'a' ) parse_S'() match( '}' ) parse_S() match( '(' ) parse_A() match( ')' ) parse_S'() parse_S'()...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

hw4cs441f10-key - FOLLOW(A = \$ parse_S if id == match...

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

View Full Document
Ask a homework question - tutors are online