CSE 2320 Section 501 Fall 1998
Due: November 3, 1998, 5:30pm (November 4, 1998, 5:00pm for -10%)
For this program you will implement another very small subset of the LISP
programming language using binary trees; namely, arithmetic expressions.
You may write your code in C or C++. In addition to correctness,
programming style is also important, so please write modular,
For this program a LISP arithmetic expression is of the form (op expr1
expr2), where op is one of + (addition), - (subtraction)
or * (multiplication). The arguments expr1 and expr2 are
either integers in the range 1-999 or valid arithmetic expressions. Note
that unlike PGM2, the only spaces in an expression are one between op
and expr1 and one between expr1 and expr2. You may
assume that the final and all intermediate results fall within the range of
the int type.
Your program will read in and print each expression, parse the expression
into a binary parse tree, print out the indented tree, print out the infix
representation of the expression, and print the final result. Your
program cannot use global variables. Specifically:
- Implement data structures for the binary tree as shown in class.
Note that a tree object will need to store either an operator or an
- Implement procedures for creating a binary parse tree from the input
expression, printing the tree using indentation to note parent-child
relationships, printing the infix representation of the expression,
evaluating the tree, and freeing the tree.
- The main part of your program will read in data from a file whose
name is given as the first argument to your executable. The file will
consist of one or more lines, each containing a valid arithmetic
expression. Your main program should process each line one at a time and
for each line, output the expression, the indented binary parse tree, the
infix notation and the result. See files pgm3in and pgm3out in
the class directory on omega for examples. Your output should match
the format of the example output as close as possible.
- Be sure to properly document your source code, as described in
Program 1. After ensuring that your program compiles and executes
correctly on the omega machine, run the program /public/cse/2320-501/handin3 to electronically hand in your source file.
All source code must be in one file (i.e., no separate .h and .c files).
Do not turn in a printout of your source code in class.