trassare.com

com.trassare.calculator.engine
Class InfixCalculator

java.lang.Object
  extended by com.trassare.calculator.engine.InfixCalculator

public class InfixCalculator
extends Object

InfixCalculator parses, calculates, and prints the results of a series of floating-point arithmetic expressions, one to a line, as given by the following grammar:

 command -> { expression { ! | >> Identifier } } \n
 expression -> term { + term | - term }
 term -> { * power | / power }
 power -> factor [ ^ power ] | { - } { ln | sin | cos | tan | asin | acos | atan}? power
 factor -> ( expression ) | -factor | Number | @

Historical stuff (the origins of this application): CS 152, Fall, 2005
Programming Assignment #1
Due: October 11, 2005
Class: Section 1, TTh 0900-1015

Version:
2 September 2006
Author:
Samuel Trassare

Constructor Summary
InfixCalculator(ExpressionScanner inS)
          Construct a new InfixCalculator class using the ExpressionScanner provided by Doctor Kenneth Louden.
 
Method Summary
 BigDecimal go()
          Begin execution of the InfixCalculator.
 void resetScanner(PushbackReader instream)
          Supply the calculator with a new input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InfixCalculator

public InfixCalculator(ExpressionScanner inS)
Construct a new InfixCalculator class using the ExpressionScanner provided by Doctor Kenneth Louden.

Parameters:
inS - the new ExpressionScanner.
Method Detail

go

public final BigDecimal go()
                    throws ParseException
Begin execution of the InfixCalculator.

Returns:
the completely evaulated expression.
Throws:
ParseException - in any error condition a ParseException is thrown

resetScanner

public final void resetScanner(PushbackReader instream)
Supply the calculator with a new input stream. This function is necessary if input is delivered via a StringReader wrapped in the PushbackReader. Unfortunately StringReaders don't have a "rewind" capability so instead, supply a new input. This method calls it's evil twin in ExpressionScanner.

Parameters:
instream - the new PushbackReader to read from.

trassare.com