public boolean addRule(Rule rule){
  if (validRule(rule)) {
    rules.add(rule);
    updateVarsAndTerminals(rule);
    return true;
  }
 else {
    return false;
  }
}

public boolean addRule ( Rule rule ) { if ( validRule ( rule ) ) { rules . add ( rule ) ; updateVarsAndTerminals ( rule ) ; return true ; } else { return false ; } }
add a single rule the grammar , testing it for structural and probability validity .
