Interface Expr

All Known Subinterfaces:
Value
All Known Implementing Classes:
BinOp, IfZero, Num, Paren

sealed interface Expr permits BinOp, IfZero, Paren, Value
An `Expr` represents (the parse tree of) an OG0 expression.
See Also:
  • invalid reference
    implementations `BinOp` etc, for its subtypes/variants.
  • Field Summary

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

    Modifier and Type
    Method
    Description
    Evaluate a given Expr.
    static Expr
    Return (our internal representation of) the first expression in s.
    static Expr
    Return (our internal representation of) the first expression in s.
    static Expr
    parse(Scanner s, String punctuation)
    Return (our internal representation of) the first expression in s.
    Return a String representation of this Expr.
  • Field Details

  • Method Details

    • eval

      Value eval()
      Evaluate a given Expr.
      Returns:
      the Value this Expr evaluates to. (In OG0, all values are numbers (doubles), but in OG3 that will change, which is why we have pre-emptively made the return type 'Value'.)
    • toString

      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

      static Expr parse(String s)
      Return (our internal representation of) the first expression in s.
      Parameters:
      s - The source code for exactly one Expr. Must by syntactically correct.
      Returns:
      (our internal representation of) the expression s.
    • parse

      static Expr parse(Scanner s)
      Return (our internal representation of) the first expression in s. Side-effect: consume *exactly* the chars of that expr from the front of `s`.
      Parameters:
      s - A scanner starting with the source code for an Expr.
      Returns:
      (our internal representation of) the expression at front of `s`.
    • parse

      static Expr parse(Scanner s, String punctuation)
      Return (our internal representation of) the first expression in s. Side-effect: consume *exactly* the chars of that expr from the front of `s`.
      Parameters:
      s - A scanner starting with the source code for an Expr.
      punctuation - A string of the chars to be interpreted as puncutation (*and* not part larger tokens).
      Returns:
      (our internal representation of) the expression at front of `s`.