// Arithmetical Expressions
// Version 1 -- just toString()

/* Grammar for internal syntax

Exp t ::= CStr  (String s)
        | CInt  (int i)
        | Plus  (Exp t1, Exp t2)        
        | Minus (Exp t1, Exp t2)        
        | Len   (Exp t)
        | Str   (Exp t)
*/

interface Exp extends Cloneable {
    String toString ();
}

class CStr implements Exp {
    private String s;
    CStr (final String s) { this.s = s; }
    public String toString() { return "\"" + s + "\""; }
}

class CInt implements Exp {
    private int i;
    CInt (final int i) { this.i = i; }
    public String toString() { return Integer.toString(i); }
}

class Plus implements Exp {
    private Exp t1, t2;
    Plus (final Exp t1, final Exp t2) { this.t1 = t1; this.t2 = t2; }
    public String toString() { 
	return "(" + t1.toString() + " + " + t2.toString() + ")";
    }
}

class Minus implements Exp {
    private Exp t1, t2;
    Minus (final Exp t1, final Exp t2) { this.t1 = t1; this.t2 = t2; }
    public String toString() { 
	return "(" + t1.toString() + " - " + t2.toString() + ")";
    }
}

class Len implements Exp {
    private Exp t;
    Len (final Exp t) { this.t = t; }
    public String toString() {
	return t.toString() + ".length()" ;
    }
}

class Str implements Exp {
    private Exp t;
    Str (final Exp t) { this.t = t; }
    public String toString() {
	return "Integer.toString(" + t.toString() + ")";
    }
}
