/** * Parses a real number literal. * * @return A real number literal. * * @throws SourceCodeException If the next token in the sequence is not a real number literal. */ public NumericType doubleLiteral() throws SourceCodeException { Token valToken = consumeToken(FLOATING_POINT_LITERAL); NumericType result = new DoubleLiteral(Double.parseDouble(valToken.image)); // Set the position that the literal was parsed from. SourceCodePosition position = new SourceCodePositionImpl(valToken.beginLine, valToken.beginColumn, valToken.endLine, valToken.endColumn); result.setSourceCodePosition(position); return result; }
/** * Parses a real number literal. * * @return A real number literal. * * @throws SourceCodeException If the next token in the sequence is not a real number literal. */ public Term doubleLiteral() throws SourceCodeException { Token valToken = consumeToken(FLOATING_POINT_LITERAL); NumericType result = new DoubleLiteral(Double.parseDouble(valToken.image)); // Set the position that the literal was parsed from. SourceCodePosition position = new SourceCodePositionImpl(valToken.beginLine, valToken.beginColumn, valToken.endLine, valToken.endColumn); result.setSourceCodePosition(position); return result; }
/** * Evaluates the arithmetic operator on its numeric argument. * * @param firstNumber The first argument. * * @return The result of performing the arithmetic operator on its argument. */ protected NumericType evaluate(NumericType firstNumber) { // If the argument is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger()) { return new IntLiteral(-firstNumber.intValue()); } else { return new DoubleLiteral(-firstNumber.doubleValue()); } } }
return new DoubleLiteral(Math.pow(firstNumber.doubleValue(), secondNumber.doubleValue()));
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() - secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() - secondNumber.doubleValue()); } } }
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() * secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() * secondNumber.doubleValue()); } } }
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() / secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() / secondNumber.doubleValue()); } } }
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() + secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() + secondNumber.doubleValue()); } } }