Assignment 1

CS 152
due September 25, 2000
100 points

Do the assignment described in the handout entitled "The programming assigment, CS 152, Spring 2000", in C++. The test cases and the grammar to be used are given in the file a1test.cpp, available from the class web site. Note that traversal is performed even if the parse fails, so you can't have the parser return an empty pointer if parsing fails.

You are responsible for constructing the appropriate header file(s) so that the test file may be compiled. Ideally you will have access to a version of C++ that supports the <iostream> argument to #include (and the underlying library) rather than just the <iostream.h> argument. If not, then you will need to modify this directive.

If you cannot get the parse function to read text from a file, you may pass the text itself, as a string, to this function. Expect a deduction if you do this. You should not have to qualify the given file names with path information.

All of your output should be directed to cout, not to cerr or to a file.

You should reclaim storage. Note that the test code only explicitly calls delete for parse trees -- deletions for objects of other types should take place inside other methods. You needn't use exceptions.

You may use C instead of C++ for this assignment. If you use C, you will need to modify the test program so that the tree t is an argument to the traverse and display_yield functions. You will also need to replace the calls to new parse_tree -- ideally to an explicit function with the same effect. Some C++ compilers have a switch to enable rejection of any code that is not C code. Consider using this feature if you are writing C code and have a C++ compiler. I will be using such a feature in grading the C versions of this assignment, and I may deduct for C++ features used in C. In particular, do not use the // notation for comments, or use a .cpp extension, if you are doing the assignment in C. Expect deductions if you do either of these.