hw4cs441f10-key

hw4cs441f10-key - FOLLOW(A) ={')', $ } parse_S() if( id ==...

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

View Full Document Right Arrow Icon
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 }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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

This document was uploaded on 12/14/2010.

Page1 / 2

hw4cs441f10-key - FOLLOW(A) ={')', $ } parse_S() if( id ==...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online