CS200 Fall 2008 Homework 1: Constructing Grammars and Parsing Expressions - Prof. Adele E., Assignments of Computer Science

Instructions for completing homework assignments in a cs200 course during the fall 2008 semester. The assignments involve constructing grammars for java switch statements and bit strings, determining the legality of sentences and expressions, and analyzing the execution of a recursive descent parser. Essential for university students enrolled in the cs200 course during the fall 2008 semester.

Typology: Assignments

Pre 2010

Uploaded on 03/10/2009

koofers-user-sgy-1
koofers-user-sgy-1 ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS200 Fall 2008 HW 1 due 9/9/08 at 9:30AM
Hand-in before start of lecture
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.]
2. Construct a grammar for any length bit strings (alphabet is {0,1}) that start with
00 and end with one or more 1s.
3. Given the following grammar:
<S> = ab<S> | bc<S>| bb<S> | a | cb
1. Is โ€œbcbbaโ€ a legal sentence?
2. List all legal sentences of 5 characters or less.
4. Is โ€œ+ * 5 โ€“ 3 / 2 + + 6 1 โ€“ 8 7โ€ a legal prefix expression? If yes, to what does it
evaluate? If no, fix it, with as little change as possible, so that it is.
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?
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. [Note: The execution stack keeps track during program execution of
what methods have been invoked from where in the code so that the
program can return to the calling method when the called method returns.]

Partial preview of the text

Download CS200 Fall 2008 Homework 1: Constructing Grammars and Parsing Expressions - Prof. Adele E. and more Assignments Computer Science in PDF only on Docsity!

CS200 Fall 2008 HW 1 due 9/9/08 at 9:30AM

Hand-in before start of lecture

  1. Construct a grammar for the Java switch statement. Use (which denotes arbitrary Java expressions) as the starting non-terminal. You may also assume that some non-terminals have already been defined (i.e., for variables, , and non-terminals for legal values of all basic types). [Note: your grammar is not responsible for checking type consistency.]
  2. Construct a grammar for any length bit strings (alphabet is {0,1}) that start with 00 and end with one or more 1s.
  3. Given the following grammar: = ab | bc| bb | a | cb 1. Is โ€œbcbbaโ€ a legal sentence? 2. List all legal sentences of 5 characters or less.
  4. Is โ€œ+ * 5 โ€“ 3 / 2 + + 6 1 โ€“ 8 7โ€ a legal prefix expression? If yes, to what does it evaluate? If no, fix it, with as little change as possible, so that it is.
  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? 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. [Note: The execution stack keeps track during program execution of what methods have been invoked from where in the code so that the program can return to the calling method when the called method returns.]