/** Our internal representation of a Paren * in the T0 language. * See http://www.radford.edu/itec380/2018fall-ibarland/Homeworks/Project/ * * @author Ian Barland * @version 2018.Nov.16 */ public class Paren extends Expr { Expr e; static final String START_TOKEN = "<"; static final String STOP_TOKEN = ">"; Paren( Expr _e ) { this.e = _e; } public String toString(/* Paren this */) { return START_TOKEN + this.e.toString() + STOP_TOKEN ; } public static Paren parse( java.util.Scanner s, String punctuation ) { assert UtilIan.nextSplittingBy(s,punctuation).equals(START_TOKEN); // Consume the opening '<' and continue. // NOTE: recur with `Expr.parse` -- not `parse` = `Paren.parse` which is NOT what we want! Expr theInsideExpr = Expr.parse(s,punctuation); assert UtilIan.nextSplittingBy(s,punctuation).equals(STOP_TOKEN); // consume the closing '>' return new Paren(theInsideExpr); } public Value eval() { return this.e.eval(); } @Override public boolean equals( /* Paren this, */ Object that) { if (this==that) { return true; } else if (that==null) { return false; } else if (this.getClass() != that.getClass()) { return false; } else { Paren thatt = (Paren) that; return this.e.equals(thatt.e); } } @Override public int hashCode() { if (cachedHash == null) { int hashSoFar = (int)0x3141834e907b1159L; // fingerprint hashSoFar += this.e.hashCode(); cachedHash = hashSoFar; } return cachedHash; } private Integer cachedHash = null; }