mic.calc
Class Mic

java.lang.Object
  extended by mic.calc.Mic

public class Mic
extends java.lang.Object

Provides the evaluator that calculates integer expressions.

Author:
Burkhardt Renz

Constructor Summary
Mic()
           
 
Method Summary
 int calculate(java.lang.String expression)
          Calculates the expression.
 java.lang.String evaluate(java.lang.String expression)
          Evaluates the expression.
 void printSyntaxTree(java.lang.String expression, java.io.Writer out)
          Prints the syntax tree of the expression to writer out.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mic

public Mic()
Method Detail

calculate

public final int calculate(java.lang.String expression)
                    throws java.lang.IllegalStateException,
                           java.lang.NumberFormatException,
                           ParseException
Calculates the expression.

Parameters:
expression - to be calculated
Returns:
integer value of expression according to the specification of eval in m4
Throws:
ParseException - if the syntax of the expression is invalid
java.lang.NumberFormatException - if the parsing of numbers yields invalid results
java.lang.IllegalStateException - if the syntax tree is invalid,
java.io.IOException
Pre:
expression != null

evaluate

public final java.lang.String evaluate(java.lang.String expression)
                                throws java.lang.NumberFormatException,
                                       java.lang.IllegalStateException,
                                       ParseException
Evaluates the expression.

Parameters:
expression - to be calculated
Returns:
evaluation of expression (as a string) according to the specification of eval in m4
Throws:
ParseException - if the syntax of the expression is invalid
java.lang.NumberFormatException - if the parsing of numbers yields invalid results
java.lang.IllegalStateException - if the syntax tree is invalid
Pre:
expression != null

printSyntaxTree

public final void printSyntaxTree(java.lang.String expression,
                                  java.io.Writer out)
                           throws ParseException,
                                  java.io.IOException
Prints the syntax tree of the expression to writer out.

Parameters:
expression - to be parsed
out - where to write the syntax tree
Throws:
ParseException - in case of syntax error
java.io.IOException - in case of io error
Pre:
expression != 0; out != null
Effects:
parses the expression, generates the syntax tree and prints it on out