CS 2401 Assignment #6

Due Date: Monday, March 28 or Tuesday, March 29, depending on the day of your lab.

Objective: The goal of this assignment is to practice the use of stacks in compiling.

Part 1: Write a program that, given a postfix expression, computes its value. Allow your program to take arbitrary non-negative integers, blank spaces between numbers and/or symbols, and the power operation symbol ^ in addition to the usual arithmetic operations +, -, *, and /, so that 23^ (or 2 3 ^) means 2^3, i.e., raising 2 to the power 3.

Part 2: Write a compiler program that takes, as inputs, usual (infix) expressions containing +, -, *, /, and ^, and uses the stacks to compute their values.

Comment: The book has a detailed code, but without the extra power operation.

For extra credit: Write a compiler program that allows variables in the expressions; for each variable, your program should ask the user for the value of this variable, and then compute the value of this expression.