コード例 #1
0
  public String[] analyze(String input) {
    StringTokenizer stringTokenizer =
        new StringTokenizer(input.replace(" ", ""), "+-*/()<!F", true);
    String tokens[] = new String[stringTokenizer.countTokens()];

    for (int i = 0; i < tokens.length; i++) {
      tokens[i] = stringTokenizer.nextToken();
    }

    for (int i = 0; i < tokens.length; i++) {
      for (Token token : Token.values()) {
        if (tokens[i].equals(token.getCharacter())) {
          tokens[i] = token.name();
        } else {
          try {
            Integer.parseInt(tokens[i]);
            break;
          } catch (NumberFormatException ex) {
          }
        }
      }
    }

    return tokens;
  }