Ejemplo n.º 1
0
  /**
   * We can assume that there is neither '&&' nor '||' in the literal, and focus on transforming the
   * literal according to the type of atoms. Currently, only int operations and floating operations
   * are supported.
   *
   * @param literal
   * @param typeId
   * @return
   */
  public static String fromLiteral2KExpr(String literal, int typeId) {
    String kexp = literal;
    // replace each pattern in the array to its corresponding k-form.
    String[] transformCandidates = null;
    if (typeId == TypeMapping.INT_OPERAND) transformCandidates = TypeMapping.infixOP;
    else if (typeId == TypeMapping.FLOAT_OPERAND) transformCandidates = TypeMapping.commonInfixOP;
    else if (typeId == TypeMapping.BOOL_OPERAND) transformCandidates = TypeMapping.boolOP;
    else if (typeId == TypeMapping.STRING_OPERAND) transformCandidates = TypeMapping.commonInfixOP;
    else transformCandidates = null;

    if (transformCandidates == null) return literal.replaceAll("(?<=\\W)==(?=\\W)", "==K");

    for (int i = 0; i < transformCandidates.length; i++) {
      String curOp = transformCandidates[i];
      if (!literal.contains(curOp)) continue;

      kexp = kexp.replaceAll(toRegEx(curOp), TypeMapping.convert2KOP(curOp, typeId));
    }

    return kexp;
  }