import java.util.Vector;


/**
 * This class keeps an axiom (the initiating production) and a Vector of Rules.
 * Each Rule contains a variable, and a production which the variable stands
 * for. Rules are retrieved by the Interpreter--given a variable, getRule
 * passes back the corresponding production.
 * (called by: Lsystem.java, Interpreter.java);
 *
 * @author Scott Teresi, April 1999, www.teresi.us
 */



public class Rules {

  static Vector rules = new Vector();
  static String axiom = new String();


  public Rules () {
  }


  public void add (String str) {
    if (str != null)
      rules.addElement(new Rule(str));
  }
  

  public int size () {
    return rules.size();
  }


  public void setAxiom (String str) {
    axiom = str;
  }


  public String getAxiom () {
    return axiom;
  }


  public static String getRule (char ruleChar) {

    String production = new String();

    for (int i = 0; i < rules.size(); i ++) {
      Rule r = (Rule) rules.elementAt(i);
      if (r.var == ruleChar)
	production = r.production;
    }
    if (production == null)
      System.out.println("No production for " + ruleChar);
    return production;
  }



  public class Rule {

    public char var;
    public String production;

    public Rule (String str) {
      var = str.charAt(0);
      production = str.substring(2, str.length());
    }
  }

}
