int IDENT = 1, BIN = 2;
class Expr(
    int kind, priority;
    []char operator;
    Expr left, right; );
    
void toString(
    int level;
    Expr expr;
    var []char result; ) {
        []char left, right;
        if ( expr.kind == IDENT )
            result = expr.operator;
        else
            if ( expr.kind == BIN )
                {
                    parenth( level + 1, expr.priority, expr.left, left );
                    parenth( level + 1, expr.priority + 1, expr.right, right );
                    result = left + expr.operator + right;

                }
    }
    
void parenth(
    int level, priority;
    Expr expr;
    var []char result; ) {
        []char result1;
        toString( level + 1, expr, result1 );
        if ( expr.priority < priority )
            result = "(" + result1 + ")";
        else
            result = result1;

    }
    
[]char result = null;
Expr expr1 = new Expr{ IDENT, 3, "a", null, null };
Expr expr2 = new Expr{ IDENT, 3, "b", null, null };
Expr expr3 = new Expr{ IDENT, 3, "c", null, null };
Expr expr4 = new Expr{ BIN, 1, "+", expr1, expr2 };
Expr expr = new Expr{ BIN, 2, "*", expr4, expr3 };
toString( 1, expr, result );
println( result );
