All pastes #940231 Raw Edit

Unnamed

public java v1 · immutable
·published 2008-03-12 20:51 UTC
rendered paste body
  private static final Pattern numberPattern = Pattern.compile("^_*[\\d.,]+$");  private static final Pattern operatorPattern = Pattern.compile("^[-+*/]$");  private static final Pattern parenPattern = Pattern.compile("^[()]$");  /**   * Inspects the given string and returns an appropriate instance of a   * subclass of {@link Token}.   *   * @param tok the token to evaluate.   * @return <code>Token</code> representation of <code>tok</code>.   */  public static Token toToken(String tok) {	  if(Assignment2.operatorPattern.matcher(tok).matches()){		  return new Operator(tok);	  } else if(Assignment2.numberPattern.matcher(tok).matches()){		  return new Operand(Double.parseDouble(tok));	  } else if(Assignment2.parenPattern.matcher(tok).matches()){		  return new Parenthesis(tok);	  } else throw new java.lang.RuntimeException();  }