class Expr
	begin
		int kind, priority; 
		^char operator; 
		^Expr left, right;
	end

int freeNode = 0;
[ 10 ]Expr nodeHeap;

^Expr new( 
	int kind, priority; 
	^char operator; 
	^Expr left, right;
	) 
	begin
		^Expr node = nodeHeap[ freeNode++ ];
		node.kind = kind;
		node.priority = priority;
		node.operator = operator;
		node.left = left;
		node.right = right;
		return node;
	end

int IDENT = 1, BIN = 2;

void parenth( int level, priority; ^Expr expr; ^char result; )
	begin
		[ 20 ]char result1;
		toString( level + 1, expr, result1 );
		if expr.priority < priority then
			sprintf( result, "(%s)", result1 );
		else
			sprintf( result, "%s", result1 );
		end
	end

void toString( int level; ^Expr expr; ^char result; )
	begin
		[ 20 ]char left, right;
		if expr.kind == IDENT then
			sprintf( result, "%s", expr.operator );
		elif expr.kind == BIN then
			parenth( level + 1, expr.priority, expr.left, left );
			parenth( level + 1, expr.priority+1, expr.right, right );
			sprintf( result, "%s%s%s", left, expr.operator, right );
		end
	end

^Expr expr1 = new( IDENT, 3, "a", null, null );
^Expr expr2 = new( IDENT, 3, "b", null, null );
^Expr expr3 = new( IDENT, 3, "c", null, null );
^Expr expr4 = new( BIN, 1, "+", expr1, expr2 );
^Expr expr = new( BIN, 2, "*", expr4, expr3 );

[ 20 ]char result;
toString( 1, expr, result );
printf( "%s\n", result );
