20-CS-122-001 Computer Science II Spring 2012
Brownie Point Assignment

Virtual functions, classes, inheritance, lists, queues, stacks, applications

Evaluate Simple Arithmetic Expressions

For 15 brownie points (not required)
(submit instructions: here)


This is an addendum to the first brownie assignment which asked to build a program that evaluates arithmetic expressions. If you complete that one on your own, you are an ace programmer. However, since that assignment proved too hard for most students, we offer this pared down version instead.

In this assignment you get working code (that is, code that compiles and runs) for an arithmetic evaluator, a stack class, and a class that helps read standard input as a collection of string tokens. The evaluator (parse.cc) does not correctly return a result in some cases, namely when parentheses are implied. For example, an input of

evaluates to 27 instead of 21 because this should be read as
but instead is read as
The assignment is to fix the code so that it works correctly on all inputs - that is, all implied parens are treated properly (* and / have higher precedence than + and -). Only parse.cc needs to be fixed.

Information on compiling this package and using parse.cc is found in the file parse.cc. A Makefile is provided to make compilation easy.


    stacker.h     Include file for the Stack class
    stacker.cc     File containing code for the Stack class
    tokenizer.h     Include file for the Tokenizer class
    tokenizer.cc     File containing code for the Tokenizer class
    parse.cc     Code for the Parse class and the means to run it
    Makefile     For easy compilation
    arith_1.sample     Expression sample 1 - usage: parse < arith_1.sample
    arith_2.sample     Expression sample 2 - usage: parse < arith_2.sample