package ca.ubc.cs411.abe;

public class If extends ABE {
    private ABE pred, conseq, altern;

    public If(ABE pred, ABE conseq, ABE altern) {
        if (pred.typeOf() != Type.BOOL) {
            throw new Error("If constructor passed a non-Bool predicate: " + pred);
        } else if (conseq.typeOf() != altern.typeOf()) {
            throw new Error("If constructor passed consequence and alternative expressions with different types: " + conseq + ", " + altern);
        }
        this.pred = pred;
        this.conseq = conseq;
        this.altern = altern;
    }

    @Override
    public Value interp() {
        if (pred.interp().toBool()) {
            return conseq.interp();
        }
        return altern.interp();
    }

    @Override
    public Type typeOf() {
        // Invariant: conseq and altern have the same type
        return conseq.typeOf();
    }

    @Override
    public String toString() {
        return "If(" + pred + "," + conseq + "," + altern + ")";
    }
}

@@ -135,24 +135,323 @@
 E altern) %7B%0A
+        this.pred = pred;%0A        this.conseq = conseq;%0A        this.altern = altern;%0A    %7D%0A%0A    @Override%0A    public Value interp() %7B%0A        if (pred.interp().toBool()) %7B%0A            return conseq.interp();%0A        %7D%0A        return altern.interp();%0A    %7D%0A%0A    @Override%0A    public Type typeOf() %7B%0A
         if (
@@ -777,366 +777,8 @@
   %7D%0A
-        this.pred = pred;%0A        this.conseq = conseq;%0A        this.altern = altern;%0A    %7D%0A%0A    @Override%0A    public Value interp() %7B%0A        if (pred.interp().toBool()) %7B%0A            return conseq.interp();%0A        %7D%0A        return altern.interp();%0A    %7D%0A%0A    @Override%0A    public Type typeOf() %7B%0A        // Invariant: conseq and altern have the same type%0A
     

Allow any ABE expressions to be used for predicate/consequence/alternative expressions, only throw type checking errors in typeOf