import java.util.*;

public abstract class ParseNode implements GrammarTypes {
  protected static int nesting = 0;

  protected Vector children;
  public ParseNode() { children = new Vector(0); }
  public int numChildren() { return children.size(); }
  public ParseNode getChild(int i) { return (ParseNode) children.elementAt(i); }
  public void addChild(ParseNode node) { children.addElement(node); }
  protected void printChildren() {
    for (int c=0; c<numChildren(); c++) 
      getChild(c).print();
  }
  protected void printSpaces() { 
    sprint("\n");
    for (int s=0; s<nesting*4; s++) 
      sprint(" ");
  }
  
  protected void print() {
    printSpaces();
    sprint("["); 
    nesting++;
    sprint(grammarNames[getType()]);
    sprint(" ");
    printChildren();
    sprint("]");
    nesting--;
  }
  
  protected void sprint(String s) { System.out.print(s); } 
  public abstract int getType() ;
  public abstract ParseNode interpret(SymbolTable st) 
    throws InterpretException, BreakException, ReturnException;
}
