import java.util.Hashtable;

/**
 * A simple Pascal type checker.  Static, because I'm lazy.
 */
public class TypeCheck
{
  static Hashtable helpers = new Hashtable();
  static SymbolTable symtab = new SymbolTable();

  public static void initialize() {
    helpers.add(PascalNonterminals.WHILE_LOOP, ...);
    helpers.add(PascalNonterminals.IF_STATEMENT,
      new Helper() {
        public void check(Node n)
        {
          check(n.getChild(0));
          if (n.getType() != TBOOLEAN)
            throw new Exception("Sorry, the test of a condtiional must return true or false");
          check(n.getChild(1));
          if (n.numChildren() == 3) { check(n.getChild(2)); }
        } // check(Node)
      });

  } // initialize()
} // class TypeCheck

public class Helper
{
  public void check(Node n) 
  {
    Helper h = helpers.get(Node.getSymbol());
    if (h != null) {
      h.check(n);
    }
    else {
      for (i = 0; i < n.numChildren(); i++)
        check(n.getChild(i));
    }
  } // check(Node)
}

