CS 3240 Homework 6 - Fall 2005, Assignments of Computer Science

Homework assignments for cs 3240, a university course in computer science, focusing on first and follow sets, cfsm, eliminating left-recursion and common prefixes in grammars, and writing recursive-descent parsers. Assigned on october 27th, 2005, and due on november 3rd, 2005.

Typology: Assignments

Pre 2010

Uploaded on 08/05/2009

koofers-user-cst
koofers-user-cst ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 6
CS 3240 - Fall 2005
Assigned: October 27th, 2005
Due: November 3rd, 2005
1. First and Follow Sets and CFSM
A. Construct the first and follow sets for the following grammar.
lexp โ†’atom |list
atom โ†’number |identifier
list โ†’(lexpseq )
lexpseq โ†’lexp lexpseq |ฮต
where the terminals are: number,identi fiers,(,)and the starting symbol is
lexp.
B. Construct the CFSM for the following grammar.
Sโ†’(L)|a
Lโ†’S L |ฮต
2. Grammars for LL Parsing
A. Eliminating left-recursion. LL parsers cannot deal with left-recursion, they
go into an infinite loop. For each of the following grammars, remove its
left-recursion so that itโ€™s LL parsable.
i. Sโ†’S+S|S-S|T
Tโ†’T*T|T/T|I
Iโ†’I0|I1|0|1
ii. Sโ†’Sa|Tb|c
Tโ†’Tx|Sy|z
B. Eliminating common prefixes (left factoring). LL parsers also cannot han-
dle common prefixes. Use left factoring to remove the common prefixes in
the following grammer and make it LL parsable.
Sโ†’xyA|ByB|v
1
pf2

Partial preview of the text

Download CS 3240 Homework 6 - Fall 2005 and more Assignments Computer Science in PDF only on Docsity!

Homework 6

CS 3240 - Fall 2005

Assigned: October 27th, 2005

Due: November 3rd, 2005

  1. First and Follow Sets and CFSM

A. Construct the first and follow sets for the following grammar. lexp โ†’ atom | list atom โ†’ number | identifier list โ†’ ( lexpseq ) lexpseq โ†’ lexp lexpseq | ฮต where the terminals are: number, identi f iers, (, ) and the starting symbol is lexp. B. Construct the CFSM for the following grammar. S โ†’ ( L ) | a L โ†’ S L | ฮต

  1. Grammars for LL Parsing

A. Eliminating left-recursion. LL parsers cannot deal with left-recursion, they go into an infinite loop. For each of the following grammars, remove its left-recursion so that itโ€™s LL parsable. i. S โ†’ S + S | S - S | T T โ†’ T * T | T / T | I I โ†’ I 0 | I 1 | 0 | 1 ii. S โ†’ S a | T b | c T โ†’ T x | S y | z B. Eliminating common prefixes (left factoring). LL parsers also cannot han- dle common prefixes. Use left factoring to remove the common prefixes in the following grammer and make it LL parsable. S โ†’ xyA | ByB | v

A โ†’ zB | zx | w C โ†’ y|x C. For each of the following grammars, indicate whether it is LL. If it is not LL, fix it so that it is. i. S โ†’ Sxy S โ†’ SxB S โ†’ q B โ†’ Ez ii. S โ†’ Aw S โ†’ Bx A โ†’ yB B โ†’ zA iii. S โ†’ Ax S โ†’ By A โ†’ zB B โ†’ z

  1. Writing Recursive-Descent Parsers

Write pseudo-code to parse the following grammer by recursive-descent. S โ†’ { S } S | A A โ†’ [ A ] | B B โ†’ ( B ) B | C C โ†’ int | ฮต