Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS200 Fall 2008 Homework 1: Grammar and Parsing - Prof. Adele E. Howe, Assignments of Computer Science

Instructions and exercises for cs200 students in the fall 2008 semester. The tasks include constructing grammars for java switch statements and bit strings, determining the legality of certain strings and expressions, and analyzing the execution stack of a recursive descent parser. Students are expected to earn a total of 100 points.

Typology: Assignments

Pre 2010

Uploaded on 03/11/2009

koofers-user-49q-1
koofers-user-49q-1 ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download CS200 Fall 2008 Homework 1: Grammar and Parsing - Prof. Adele E. Howe and more Assignments Computer Science in PDF only on Docsity! CS200 Fall 2008 HW 1 due 9/9/08 at 9:30AM Name: 1. Construct a grammar for the Java switch statement. Use <expr> (which denotes arbitrary Java expressions) as the starting non-terminal. You may also assume that some non-terminals have already been defined (i.e., <var> for variables, <expr>, and non-terminals for legal values of all basic types). [Note: your grammar is not responsible for checking type consistency.] [20 points] <expr> -> switch (<expr>) { <case> } <case> -> case <value> : <casedo> <case> | case <value> : <casedo> | default : <casedo> | case <value> : <case> <casedo> -> <expr> | <expr> break; <value> -> <byte> | <short> | <char> | <int> | <enum> |<expr> 2. Construct a grammar for any length bit strings of that start with 00 and end with one or more 1s. [20 points] <S> -> 00<A> <A> -> 0<A> | 1<A> | 1 3. Given the following grammar: <S> = ab<S> | bc<S>| bb<S> | a | cb 1. Is โ€œbcbbaโ€ a legal sentence? [5 points] yes 2. List all legal sentences of 5 characters or less. [15 points] a, cb, aba, bca, bba, abcb, bccb, bbcb, ababa, abbca, abbba, bcbca, bcbba, bcaba, bbaba, bbbca, bbbba 4. Is โ€œ+*5-3/2++61-87โ€ a legal prefix expression (assume all operators are binary)? If yes, to what does it evaluate? If no, fix it, with as little change as possible, so that it is. [10 points] Not legal. +*5-3/2++61-879 5. For the recursive descent parser provided in class (and on the website), a. will the code conclude that โ€œ* + a b โ€“ c / a bโ€ is a legal expression? [10 points] Yes. b. show how the execution stack will change as the code runs for the expression โ€œ* a + b cโ€. Every time a method is invoked, show a stack snapshot that includes the name of that method and its argument(s) at the top. [20 points] 0. main. 1. Parse(โ€* a + b cโ€); main. 2. main. 3. start(); main. 4. expression(โ€œ โ€œ);start();main. 5. ID(โ€œ โ€œ);expression(โ€œ โ€œ);start();main. 6. expression(โ€œ โ€œ);start();main. 7. operator(โ€œ โ€œ);expression(โ€œ โ€œ);start();main. 8. expression(โ€œ โ€œ);start();main. 9. expression(โ€œ โ€œ); expression(โ€œ โ€œ);start();main. 10. ID(โ€œ โ€œ);expression(โ€œ โ€œ); expression(โ€œ โ€œ);start();main.
Docsity logo



Copyright ยฉ 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved