@Override
  public int cost(Stack<Node> stack) throws SemanticException {
    if (rulePatternIsValidWithoutWildCardChar()) {
      return costPatternWithoutWildCardChar(stack);
    }
    if (rulePatternIsValidWithWildCardChar()) {
      return costPatternWithWildCardChar(stack);
    }
    if (rulePatternIsValidWithORWildCardChar()) {
      return costPatternWithORWildCardChar(stack);
    }
    // If we reached here, either :
    // 1. patternWithWildCardChar and patternWithoutWildCardChar are both nulls.
    // 2. patternWithWildCardChar and patternWithoutWildCardChar are both not nulls.
    // This is an internal error and we should not let this happen, so throw an exception.
    throw new SemanticException (
      "Rule pattern is invalid for " + getName() + " : patternWithWildCardChar = " +
      patternWithWildCardChar + " patternWithoutWildCardChar = " +
      patternWithoutWildCardChar);
  }
This function returns the cost of the rule for the specified stack. Lower
the cost, the better the rule is matched

@param stack
         Node stack encountered so far
@return cost of the function
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/lib/RuleRegExp.java