Programming Language Assignments

Dear Raphael, This is a general assignment for my programming languages course this fall. If you have a few extra days I wonder if you would write a reference implementation in Java.

In each language we study in depth (Ada, C++, Scheme) we are going to look at three kinds of functionality that are typical of programming tasks: simple parsing, simple numerical calculations, and simple data manipulation. By simple parsing we mean parsing some commands that are given to the program when it is running. By simple numerical calculations, we mean simple statistics. By simple data manipulation, we mean performing the queries of a simple relational database. I present some examples here but I expect you to be able to do these assignments on any data meeting these specifications.

General notes:

1. When parsing commands, any type of white space (one or more spaces, tabs or newlines) should be treated equally. The semicolon tells you when the command is done. Your programs should be sophisticated about parsing white space.

2. You will be working in groups of size one or two. Aside from your fellow group member, the only material you may use are the books, the class notes and the material you gather from the class or the recitation. If different groups' assignments are too similar we will consider this plagiarism. If you are found to have copied from the internet or have cheated in any other way, we will consider this to be plagiarism.

The penalty for plagiarism is an F in the course and a report to the director of graduate studies. In the case of copying from another student, both the receiver of information and the giver may receive an F. Plagiarism is one of the few things that makes us unfriendly.

Functionality Common to the Assignments:

1. Title: reading files.
Syntax:

readfile <filename> into <tablename> columns <columns separated by commas>;
Comments: The entries in the file will be delimited by vertical bars. Your program will look at the first line of the file to determine the types if necessary and when possible.
Example: readfile foo into sales columns sale, item, customer, store, price, quantity; File foo might look like this: sale3506|item405|customer138|store19|59|25 sale78345|item617|customer878|store36|6|21 sale79991|item433|customer251|store53|43|20 sale90466|item490|customer592|store7|84|32 sale22332|item646|customer956|store65|56|32 sale95047|item513|customer687|store24|6|18 sale48867|item578|customer669|store73|6|31 sale22220|item562|customer435|store91|46|27 sale53696|item310|customer956|store45|6|23 sale34328|item421|customer569|store73|57|27 sale61356|item588|customer762|store77|6|30 sale41673|item449|customer428|store89|87|26 sale48926|item571|customer582|store10|83|34 sale68040|item542|customer956|store19|87|25 sale14876|item476|customer956|store55|6|21 sale69406|item492|customer956|store63|6|27 sale46341|item507|customer161|store75|6|28 sale17846|item323|customer396|store39|56|23 sale67528|item407|customer956|store69|6|24 sale76012|item650|customer956|store39|6|18 sale86835|item583|customer245|store93|6|24 sale51047|item574|customer392|store76|22|21 sale96804|item415|customer956|store17|6|25 Each record consists of one line. No blank lines at the end.

2. Title: Simple inserts/selects.
Syntax:

[insert tablename] select <columnnames separated by commas> from <tablename> [ where <conditions> ] ;
Comments: The brackets denote optional parts. The conditions (if any) are separated by "and". There is always one table (no relational joins). There are no disjunctions or negations. At least not until the final project (where you will choose one language and implement joins as well as and/or conditions).

Example:

insert bigcustomer select customer, price, quantity from sales where quantity > 25 and price < 90 will produce a table bigcustomer having column names customer, price, quantity inherited from the query: customer592|84|32 customer956|56|32 customer669|6|31 customer435|46|27 customer569|57|27 customer762|6|30 customer428|87|26 customer582|83|34 customer956|6|27 customer161|6|28 customer956|6|25

3. Title: Aggregate inserts/selects.
Syntax:

[insert tablename] select <columnnames or aggregate expressions separated by commas> from <tablename> [group by columnname] [ where <conditions> ] ;
Comment: This is a generalization of the simple insert/selects. There may be at most one columnname (until you get to your final project where there will be many). An aggregate expression is going to come from your aggregate assignment. Aggregates will be sum, max, min, avg, var, std. All of these should be familiar except perhaps var which stands for variance and std which stands for standard deviation. To avoid making you look this up: the variance of list L = (average of square of the members of list) - (square of the average of the list). The standard deviation is simply the square root of the variance. If there is a grouping column, then that column must be the only non-aggregated column in the result. If there is no grouping column then the aggregates are over all values.

Example:

insert tots select avg(quantity), std(quantity) from sales where quantity > 25 and price < 90

will produce a table tots having fields avg_quantity and std_quantity and one row with values 29.0 and 2.796.

insert bigcustomer select customer, sum(price), std(quantity) from sales group by customer where quantity > 25 and price < 90 will produce a table bigcustomer having fields customer, sum_price, std_quantity with the following data: customer592|84|0.0 customer956|68|2.94 customer669|6|0.0 customer435|46|0.0 customer569|57|0.0 customer762|6|0.0 customer428|87|0.0 customer582|83|0.0 customer161|6|0.0

4. Title: Write table to file.
Syntax:

writefile <tablename> into <filename> Comment: output should be in the same format as the input file, that is, vertical bar delimited.
Example writefile bigcustomer into bigcustfile