Class Expr

Direct Known Subclasses:
BinOp, IfZero, Paren, Value

public abstract class Expr extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Value
    Evaluate a given Expr.
    static Expr
    Return (our internal representation of) the expression s.
    static Expr
    Return (our internal representation of) the expression at front of s.
    static Expr
    parse(Scanner s, String punctuation)
    Return (our internal representation of) the expression at front of s.
    abstract String
    Return a String representation of this Expr.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Expr

      public Expr()
  • Method Details

    • eval

      public abstract Value eval()
      Evaluate a given Expr.
      Returns:
      the Value this Expr evaluates to. (In X0, all values are numbers (doubles), but in X3 that will change, which is why we have pre-emptively made the return type 'Value'.)
    • 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.
    • 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.
    • parse

      public static Expr parse(Scanner s)
      Return (our internal representation of) the expression at front of s.
      Parameters:
      s - A scanner reading the source code for exactly one Expr. May throw InputMismatchExpression if Expr is not syntactically correct.
      Returns:
      (our internal representation of) the expression s.
    • parse

      public static Expr parse(Scanner s, String punctuation)
      Return (our internal representation of) the expression at front of s.
      Parameters:
      s - A scanner reading the source code for exactly one Expr. May throw InputMismatchExpression if Expr is not syntactically correct.
      punctuation - a string of characters to be considered punctuation (which also delimits).
      Returns:
      (our internal representation of) the expression s.