예제 #1
0
  private Object interpretUservariable(String userVariableName) {
    List<InternToken> internTokenList = new LinkedList<InternToken>();
    internTokenList.add(new InternToken(InternTokenType.USER_VARIABLE, userVariableName));
    InternFormulaParser internParser = new InternFormulaParser(internTokenList);
    FormulaElement parseTree = internParser.parseFormula();
    Formula userVariableFormula = new Formula(parseTree);

    return userVariableFormula.interpretObject(firstSprite);
  }
예제 #2
0
  public void testNotExistingLookSensorValues() {

    List<InternToken> internTokenList = new LinkedList<InternToken>();
    internTokenList.add(new InternToken(InternTokenType.SENSOR, ""));
    InternFormulaParser internParser = new InternFormulaParser(internTokenList);
    FormulaElement parseTree = internParser.parseFormula();

    assertNull("Invalid sensor parsed:   NOT_EXISTING_SENSOR)", parseTree);
    int errorTokenIndex = internParser.getErrorTokenIndex();
    assertEquals("Error Token Index is not as expected", 0, errorTokenIndex);
  }
예제 #3
0
  public void testNotExistingUservariable() {
    List<InternToken> internTokenList = new LinkedList<InternToken>();
    internTokenList.add(
        new InternToken(InternTokenType.USER_VARIABLE, "NOT_EXISTING_USER_VARIABLE"));
    InternFormulaParser internParser = new InternFormulaParser(internTokenList);
    FormulaElement parseTree = internParser.parseFormula();

    assertNull("Invalid user variable parsed:   NOT_EXISTING_USER_VARIABLE)", parseTree);
    int errorTokenIndex = internParser.getErrorTokenIndex();
    assertEquals("Error Token Index is not as expected", 0, errorTokenIndex);
  }
예제 #4
0
 public Double interpretSensor(Sensors sensor) {
   List<InternToken> internTokenList = new LinkedList<InternToken>();
   internTokenList.add(new InternToken(InternTokenType.SENSOR, sensor.name()));
   InternFormulaParser internParser = new InternFormulaParser(internTokenList);
   FormulaElement parseTree = internParser.parseFormula();
   Formula sensorFormula = new Formula(parseTree);
   try {
     return sensorFormula.interpretDouble(testSprite);
   } catch (InterpretationException interpretationException) {
     Log.d(
         getClass().getSimpleName(),
         "Formula interpretation for Sensor failed.",
         interpretationException);
   }
   return Double.NaN;
 }
예제 #5
0
  public static boolean saveFormulaForUserBrickParameterChange() {
    InternFormulaParser formulaToParse = formulaEditorEditText.getFormulaParser();
    FormulaElement formulaParseTree = formulaToParse.parseFormula();

    switch (formulaToParse.getErrorTokenIndex()) {
      case PARSER_OK:
        currentFormula.setRoot(formulaParseTree);
        if (onFormulaChangedListener != null) {
          onFormulaChangedListener.onFormulaChanged(
              formulaBrick, currentBrickField, currentFormula);
        }
        if (formulaEditorBrick != null) {
          currentFormula.refreshTextField(brickView);
        }
        formulaEditorEditText.formulaSaved();
        return true;
    }
    return false;
  }
예제 #6
0
  public boolean saveFormulaIfPossible() {
    InternFormulaParser formulaToParse = formulaEditorEditText.getFormulaParser();
    FormulaElement formulaParseTree = formulaToParse.parseFormula();

    switch (formulaToParse.getErrorTokenIndex()) {
      case PARSER_OK:
        currentFormula.setRoot(formulaParseTree);
        if (onFormulaChangedListener != null) {
          onFormulaChangedListener.onFormulaChanged(
              formulaBrick, currentBrickField, currentFormula);
        }
        if (formulaEditorBrick != null) {
          currentFormula.refreshTextField(brickView);
        }
        formulaEditorEditText.formulaSaved();
        showToast(R.string.formula_editor_changes_saved, false);
        return true;
      case PARSER_STACK_OVERFLOW:
        return checkReturnWithoutSaving(PARSER_STACK_OVERFLOW);
      default:
        formulaEditorEditText.setParseErrorCursorAndSelection();
        return checkReturnWithoutSaving(PARSER_INPUT_SYNTAX_ERROR);
    }
  }