Interface Expr
- All Known Subinterfaces:
Expr.Value
- All Known Implementing Classes:
Expr.BinOp
,Expr.IfZero
,Expr.Num
,Expr.Paren
An `Expr` represents (the parse tree of) an expression in E0.
See the internal records like `BinOp` etc, for specific variants.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
Our internal representation of a BinOp in the E0 language.static final record
Our internal representation of a IfZero expr in the E0 language.static final record
Our internal representation of a number in the E0 language.static final record
Our internal representation of a Paren in the E0 language.static interface
Abstract class Value - The type of all Expressions which self-evaluate: Numbers, and (later, in E3) functions. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault Expr.Value
eval()
Evaluate a given Expr.default String
Return a String representation of this 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
Return (our internal representation of) the first expression in s.
-
Field Details
-
PUNCTUATION
- See Also:
-
EPSILON
static final double EPSILON- See Also:
-
-
Method Details
-
eval
Evaluate a given Expr.- Returns:
- the Value this Expr evaluates to. (In E0, all values are numbers (doubles), but in E3 that will change, which is why we have pre-emptively made the return type 'Value'.)
-
myToString
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.- Returns:
- a String representation of this Expr.
-
parse
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
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
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`.
-