Search in sources :

Example 1 with LNumber

use of lucee.runtime.interpreter.ref.literal.LNumber in project Lucee by lucee.

the class CFMLExpressionInterpreter method number.

/**
 * Transfomiert einen numerische Wert.
 * Die Laenge des numerischen Wertes interessiert nicht zu uebersetzungszeit,
 * ein "Overflow" fuehrt zu einem Laufzeitfehler.
 * Da die zu erstellende CFXD, bzw. dieser Transfomer, keine Vorwegnahme des Laufzeitsystems vornimmt.
 * <br />
 * EBNF:<br />
 * <code>["+"|"-"] digit {digit} {"." digit {digit}};</code>
 * @return CFXD Element
 * @throws PageException
 */
private Ref number() throws PageException {
    // check first character is a number literal representation
    StringBuilder rtn = new StringBuilder(6);
    // get digit on the left site of the dot
    if (cfml.isCurrent('.'))
        rtn.append('0');
    else
        digit(rtn);
    // read dot if exist
    if (cfml.forwardIfCurrent('.')) {
        rtn.append('.');
        int before = cfml.getPos();
        digit(rtn);
        if (before < cfml.getPos() && cfml.forwardIfCurrent('e')) {
            Boolean expOp = null;
            if (cfml.forwardIfCurrent('+'))
                expOp = Boolean.TRUE;
            else if (cfml.forwardIfCurrent('-'))
                expOp = Boolean.FALSE;
            if (cfml.isCurrentDigit()) {
                if (expOp == Boolean.FALSE)
                    rtn.append("e-");
                else if (expOp == Boolean.TRUE)
                    rtn.append("e+");
                else
                    rtn.append('e');
                digit(rtn);
            } else {
                if (expOp != null)
                    cfml.previous();
                cfml.previous();
            }
        }
        // read right side of the dot
        if (before == cfml.getPos())
            throw new InterpreterException("Number can't end with [.]");
    } else // scientific notation
    if (cfml.forwardIfCurrent('e')) {
        Boolean expOp = null;
        if (cfml.forwardIfCurrent('+'))
            expOp = Boolean.TRUE;
        else if (cfml.forwardIfCurrent('-'))
            expOp = Boolean.FALSE;
        if (cfml.isCurrentBetween('0', '9')) {
            rtn.append('e');
            if (expOp == Boolean.FALSE)
                rtn.append('-');
            else if (expOp == Boolean.TRUE)
                rtn.append('+');
            digit(rtn);
        } else {
            if (expOp != null)
                cfml.previous();
            cfml.previous();
        }
    }
    cfml.removeSpace();
    mode = STATIC;
    return new LNumber(rtn.toString());
}
Also used : LNumber(lucee.runtime.interpreter.ref.literal.LNumber) LBoolean(lucee.runtime.interpreter.ref.literal.LBoolean)

Example 2 with LNumber

use of lucee.runtime.interpreter.ref.literal.LNumber in project Lucee by lucee.

the class CFMLExpressionInterpreter method negateMinusOp.

/**
 * Liest die Vordlobe einer Zahl ein
 * @return CFXD Element
 * @throws PageException
 */
private Ref negateMinusOp() throws PageException {
    // And Operation
    if (cfml.forwardIfCurrent('-')) {
        if (cfml.forwardIfCurrent('-')) {
            cfml.removeSpace();
            Ref expr = clip();
            Ref res = preciseMath ? new BigMinus(expr, new LNumber(new Double(1)), limited) : new Minus(expr, new LNumber(new Double(1)), limited);
            return new Assign(expr, res, limited);
        }
        cfml.removeSpace();
        return new Negate(clip(), limited);
    }
    if (cfml.forwardIfCurrent('+')) {
        if (cfml.forwardIfCurrent('+')) {
            cfml.removeSpace();
            Ref expr = clip();
            Ref res = preciseMath ? new BigPlus(expr, new LNumber(new Double(1)), limited) : new Plus(expr, new LNumber(new Double(1)), limited);
            return new Assign(expr, res, limited);
        }
        cfml.removeSpace();
        return new Casting("numeric", CFTypes.TYPE_NUMERIC, clip());
    }
    return clip();
}
Also used : Casting(lucee.runtime.interpreter.ref.cast.Casting) Ref(lucee.runtime.interpreter.ref.Ref) LNumber(lucee.runtime.interpreter.ref.literal.LNumber) BigPlus(lucee.runtime.interpreter.ref.op.BigPlus) Assign(lucee.runtime.interpreter.ref.var.Assign) DynAssign(lucee.runtime.interpreter.ref.var.DynAssign) Negate(lucee.runtime.interpreter.ref.op.Negate) Plus(lucee.runtime.interpreter.ref.op.Plus) BigPlus(lucee.runtime.interpreter.ref.op.BigPlus) BigMinus(lucee.runtime.interpreter.ref.op.BigMinus) BigMinus(lucee.runtime.interpreter.ref.op.BigMinus) Minus(lucee.runtime.interpreter.ref.op.Minus)

Aggregations

LNumber (lucee.runtime.interpreter.ref.literal.LNumber)2 Ref (lucee.runtime.interpreter.ref.Ref)1 Casting (lucee.runtime.interpreter.ref.cast.Casting)1 LBoolean (lucee.runtime.interpreter.ref.literal.LBoolean)1 BigMinus (lucee.runtime.interpreter.ref.op.BigMinus)1 BigPlus (lucee.runtime.interpreter.ref.op.BigPlus)1 Minus (lucee.runtime.interpreter.ref.op.Minus)1 Negate (lucee.runtime.interpreter.ref.op.Negate)1 Plus (lucee.runtime.interpreter.ref.op.Plus)1 Assign (lucee.runtime.interpreter.ref.var.Assign)1 DynAssign (lucee.runtime.interpreter.ref.var.DynAssign)1