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); }
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); }
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); }
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; }
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; }
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); } }