/** Our internal representation of a Paren * in the X0 language. * See http://www.radford.edu/itec380/2019spring-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 ) { UtilIan.verifyToken( UtilIan.nextSplittingBy(s,punctuation), 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); UtilIan.verifyToken( UtilIan.nextSplittingBy(s,punctuation), STOP_TOKEN); // Consume the closing "]", and continue. 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 = 0; hashSoFar *= 0b11111; hashSoFar += this.e.hashCode(); cachedHash = hashSoFar; } return cachedHash; } private Integer cachedHash = null; }