CSE307
Spring 2007
Stony Brook
Principles of Programming Languages
Annie Liu
Assignment 5
Handout A5
Mar. 29, 2007
Due Apr. 17

Object Abstraction --- Organizing Everything

This assignment has two goals: (1) organizing everything we have programmed, and (2) practicing programming with object abstraction.

We have written programs for reading tables, checking syntax against separate declarations, inferring information about data in the table, analyzing static semantics based on a state machine semantics, and implementing a hierarchical state machine semantics. We have used high-level data types, such as lists and dictionaries, and control abstraction, such as iterators, comprehension, and recursion, but we have not defined classes and created object abstraction; we will do this now.

Programming with object abstraction

At least two kinds of uses of object abstraction are possible in what we have programmed.

  1. The data we processed could be represented as objects. For example, we could represent each row as an object whose fields are the column names; this means that, for tables that represent state machines, each state is an object whose fields are the possible input labels.
  2. Different kinds of processing could be captured as objects. For example, an object could do syntax checking, another one could do static semantic analysis, and yet another one could implement the hierarchical state machine semantics; perhaps some objects could inherit from other objects.
Of course, to do these, we would need to define classes and create objects. We would also need to reorganize everything and modify the code for accessing the data and applying the functions.

The most important question, though, is: why would we do these? We should not use objects only for the sake of using objects. Our goal is to make our program better, i.e., clearer and more modular so that it is easier to understand, use, and extend. We would use objects only when they help us achieve our goal. So, would the two kinds of uses of objects help? Would other kinds of uses help? We would not easily know unless we try them out.

Your main task for this assignment is to (1) organize everything you have programmed so that one can easily use all the functionalities, as described below, and that your program is better, i.e., clearer and more modular as you can possibly do in the given time frame, and (2) try the two kinds of uses of objects suggested above, and any other use of objects that you think is better, and compare the result with the best you can improve your program without using objects---which one, or which parts or aspects of which one, you think is clearer or more modular, why, and how much effort it took to achieve that? In particular, when you make your program clearer and more modular, with or without using objects, you should describe what were the problems before, how you improved it, and how much effort it took you to achieve that.

Organizing everything

It is almost never trivial to put everything together, even if you had designed every piece with integration in mind, let alone if you have the goal of making your program clearer and more modular. So, you are asked to document your effort when doing this assignment. Among the many possible things to make your program better, let me emphasize a most important one: don't duplicate code---remember the story I told in class today.

When run, your program should take (1) an input data file name, (2) a few possible kinds of optional arguments, and (3) an output data file name. The optional arguments are one or more of the following forms:

  1. -sort column_name
  2. -check input_declaration_file_name
  3. -infer output_declaration_file_name
  4. -analyze
  5. -implement input_lable_sequence_file_name output_state_sequence_file_name
Your program should read table or tables from the input data file and, for each of the options numbered above, do the following respective processing:
  1. sorting as specified in Assignment 1.
  2. syntax checking as specified in Assignment 2.
  3. inferring types as specified in the first half of Assignment 3.
  4. analyzing static semantics as specified in the second half of Assignment 3.
  5. implementing the hierarchical state machine semantics as specified in Assignment 4.
For options 1-3, the input should be one table. For options 4-5, the input may be one or more tables representing a hierarchical state machine; when there are more than one table, option 4 applies to every table. Finally, your program should write the cleaned-up data, as specified in the respective previous assignment, and with columns aligned, to the output data file; when none of the optional arguments is present, your program should just write the data to the output data file with columns aligned. When there are errors in processing the data, try to give the best error messages possible and finish all the processing possible.

Extra credit suggestions

Here are some ideas. (1) Organize also the extra credit work you did for the previous assignments, trying the uses of objects, and adding additional optional arguments. (2) Think of other interesting and/or useful things to check and/or to do, and do them; feel free to discuss with me.


Handins

Hand in everything electronically, using Blackboard, by 5pm on the due date. Your handin should include your README file, code, test data, and anything else you have to show your work.

Grading

This assignment will be graded based on 100 points, allocated in proportion to the estimated amount of work for each part. You may do this assignment in a team of two people; the two people will receive the same points. Exceptionally well thought-out and well written work will receive appropriate extra credit. Extra credit work will be graded based on the estimated amount of extra work.

Note that the README file for this assignment will be given 40% of the points, instead of the usual 30%, because of the required documentation of effort and comparisons.