|
CSE305 Spring 2008 - Navigation Menus
|
Homework 1
Assigned: Friday February 1, 2008.
Due: on or before 11:59 PM on Friday February 15, 2008.
When doing this homework, first create a directory named HW1
somewhere in your home directory (e.g. as a subdirectory of a
cse305 directory). Place your solution to each question in a
file or set of files, as indicated, in the HW1 directory.
When you're ready to submit, zip up the HW1 directory and its
contents, and use the submit_cse305 command to submit your
HW1.zip file.
It is very important that you pay close attention to the naming
conventions for files and directories for you homework submissions in
this course. Having uniform names for all student submissions makes
grading submissions much easier. If you do not adhere to the naming
conventions, grading of your work will be delayed, or it may simply be
returned to you ungraded for you to correct the names.
For information on how to run the various programming language
compilers/interpreters, click here. You
will find resources for these languages on the course web site, under
the "Resources" page. You might the following page, listing available
CSE systems, helpful too: http://www-local.cse.buffalo.edu/Services/Data/Student/
Question 1: Derivations (10 points)
The purpose of this question is to ensure that you can
read a programming language grammar and reason about it.
For this question you need to make use of the Pascal grammar at http://pascal-central.com/docs/iso7185.pdf.
The grammar is found in Annex A of this document, starting on page 69
of the document (page 75 of the PDF file).
This grammar accepts programs of various lengths (as measured by
the number of characters contained in the program listing). There is
a minimal length to programs accepted by this grammar.
- Give an example of one such minimal length program.
- Give a leftmost derivation of your minimal length program.
- Justify, informally, that your example program is a minimal length
program.
Put your answer in a file named HW1Q1.txt.
Question 2: IO variety (72 points - 18 points each)
The purpose of this question is to ensure that you can
use available language documentation to write a simple program in each
of four languages.
Write a program, in each of the following four languages: C# (use
Mono), Lisp (use Allegro CL), ML (use SML/NJ), and Prolog
(use Sicstus).
The programs you are to write must accept two filenames, the name of
an input file and the name of an output file. My suggestion is that
your programs accept the filenames in the following ways:
- C#: accept the filenames as command-line arguments.
- Lisp: define a function named hw1 which takes two
arguments, the name of the input file and the name of the output file,
both as strings (names enclosed in double quotes).
- ML: define a function named hw1 which takes two
arguments, the name of the input file and the name of the output file,
both as strings (names enclosed in double quotes).
- Prolog: define a predicate named hw1 which takes two
arguments, the name of the input file and the name of the output file,
both as atoms (names enclosed in single quotes).
The program you are to write must read in the input file, a plain text
file, line by line, and write to the output file only those lines
which begin with the '+' character.
For example, if the file foo.txt contains
program abc;
+var x: integer;
begin
+ x := 10;
+end.
the running your program with foo.txt as the name of the
input file, and bar.txt as the name of the output
file, must
produce write to bar.txt the following:
+var x: integer;
+ x := 10;
+end.
For the purposes of this assignment you do not need to do any specific
error checking on the files. Your program can assume that the files
exist (for the input file) or can be created or overwritten (for the
output file).
Put your answers for C#, Lisp, ML and Prolog in files named, respectively,
hw1.cs
hw1.lsp
hw1.ml
hw1.pl
Question 3: Scaling Fortress (18 points)
The purpose of this question is to ensure that you can
use available language documentation to write a simple program in the
language Fortress. Because Fortress is only partially implemented at
this time, what I am asking you to do in Fortress is a little
different from what I asked you to do in the other four languages.
Write a program in Fortress which takes in a sequence of strings as
command-line arguments, and prints out the ones whose first character
is "+".
Put your answer in a file named
hw1.fss
This page written an maintained by Carl Alphonce.
|