CS 250 - Programming
Languages
Spring 2004
Assignment 2 -- Due 5:00pm February 13.
Finish reading Chapter 2 and Section 3-1 of your text, and then
answer the following questions. You may turn them in either in hardcopy
or by e-mail to me. As an aid to your Java programming in this
assignment, a tutorial for the Java Debugger jdb is available
on-line .
- Answer questions 2.9, 2.10, 2.12, 2.14, and 2.16 on
page 47 of your text.
- Develop a complete recursive descent parser for Jay,
using the guidelines introduced in section 2.3, the
TokenStream class you completed in the first assignment, and the
following additional on-line resources:
a. the skeleton recursive descent parser
ConcreteSyntax.java ,
b. the complete Jay abstract syntax
Program.java , as a collection of the Java
classes in Appendix B.
c. the driver program
parser.java , and
d. the Jay program
program.jay from Figure 2.19 as test input.
To test your program, copy these files to your cs250
directory, complete the coding of ConcreteSyntax.java,
and then run the driver program with the command:
$ java parser program.jay
That is, the file name "program.jay" is provided as a run-time
parameter. To see if the program is correct, compare its output
with the file
parser.output , which shows the complete abstract syntax tree for
this Jay program.
- The syntax of Jay does not currently
include String literals (only integers and booleans are present).
Suggest how these literals can be added to the lexical syntax of the
language
(defined in EBNF), and then how they could be recognized by the nextToken
method in the TokenStream class.
- Discuss the following assertion: "For loops
in Java are redundant. That is, any for loop can be
equivalently
expressed as an equivalent while loop." If this is true,
describe
an algorithm that would convert any for statement into an
equivalent while statement. If it is not true, give an
example of a for statement that has no equivalent while
statement
(i.e., a counterexample).
- Answer questions 3.1-3.4 on page
79 of your text.