

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 2
This page cannot be seen from the preview
Don't miss anything!


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 | ฮต
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
Write pseudo-code to parse the following grammer by recursive-descent. S โ { S } S | A A โ [ A ] | B B โ ( B ) B | C C โ int | ฮต