import java.io.*;
import java.util.Vector;

public class TranslateVisitor extends StatementTreeVisitor {
    void visitCompoundNode(Vector body) {
	for (int i=0; i<body.size(); i++)
	    ((StatementTree)body.elementAt(i)).Accept(this);
    }
    void visitAssignNode(String lhs, ExpressionTree rhs) {
	// print instructions which, when executed, will leave 
	// expression value at top of stack
	rhs.Accept(new TranslateExpVisitor());  
	System.out.println("pop "+lhs);
    }
    void visitIfThenNode(ExpressionTree cond, StatementTree body) {
	// print instructions which, when executed, will leave 
	// expression value at top of stack
	UniqueLabel skiplabel = new UniqueLabel();
	cond.Accept(new TranslateExpVisitor());  
	System.out.println("JFalse "+skiplabel.toString());
	body.Accept(this);
	System.out.println("Define "+skiplabel.toString());
    }
}
