Class Expr

java.lang.Object
  extended by Expr
Direct Known Subclasses:
BinExpr, ParenExpr, ParityExpr, Value

public abstract class Expr
extends Object

class Expr, our internal representation of an expression in the O0 language. See http://www.radford.edu/itec380/2013fall/Homeworks/hw06.html

Version:
2008.Nov.30
Author:
Ian Barland

Field Summary
static String PUNCTUATION
           
 
Constructor Summary
Expr()
           
 
Method Summary
abstract  Value eval()
          Evaluate a given Expr.
 int hashCode()
           
static Expr parse(Scanner s)
          Return (our internal representation of) the expression s.
static Expr parse(String s)
          Return (our internal representation of) the expression s.
abstract  String toString()
          Return a String representation of this Expr.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PUNCTUATION

public static final String PUNCTUATION
Constructor Detail

Expr

public Expr()
Method Detail

eval

public abstract Value eval()
Evaluate a given Expr.

Returns:
the Value this Expr evaluates to. (In O0, all values are numbers (doubles), but in O3 that will change, which is why we have pre-emptively made the return type 'Value'.)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

parse

public static Expr parse(Scanner s)
Return (our internal representation of) the expression s.

Parameters:
s - A scanner reading the source code for exactly one Expr. Must by syntactically correct.
Returns:
(our internal representation of) the expression s.

parse

public static Expr parse(String s)
Return (our internal representation of) the expression s.

Parameters:
s - The source code for exactly one Expr. Must by syntactically correct.
Returns:
(our internal representation of) the expression s.

toString

public abstract String toString()
Return a String representation of this Expr. The result will be something which can be passed into 'parse(String)' to get the same Expr back. That is, toString and parse are inverses of each other.

Overrides:
toString in class Object
Returns:
a String representation of this Expr.