Package com.googlecode.aviator.lexer.token

Examples of com.googlecode.aviator.lexer.token.Variable


            }
            // binary operation as variable for seq functions
            if (lookhead.getType() == TokenType.Char) {
                CharToken charToken = (CharToken) lookhead;
                // make it as variable
                lookhead = new Variable(charToken.getLexeme(), charToken.getStartIndex());
            }
            move(true);
            // function
            if (prevToken.getType() == TokenType.Variable && expectLexeme("(")) {
                method();
View Full Code Here


            popOperand();
            popOperand();
            break;
        case Variable:
            // load variable
            Variable variable = (Variable) lookhead;
            if (variable.equals(Variable.TRUE)) {
                mv.visitFieldInsn(GETSTATIC, "com/googlecode/aviator/runtime/type/AviatorBoolean", "TRUE",
                    "Lcom/googlecode/aviator/runtime/type/AviatorBoolean;");
                pushOperand(0);
            }
            else if (variable.equals(Variable.FALSE)) {
                mv.visitFieldInsn(GETSTATIC, "com/googlecode/aviator/runtime/type/AviatorBoolean", "FALSE",
                    "Lcom/googlecode/aviator/runtime/type/AviatorBoolean;");
                pushOperand(0);
            }
            else if (variable.equals(Variable.NIL)) {
                mv.visitFieldInsn(GETSTATIC, "com/googlecode/aviator/runtime/type/AviatorNil", "NIL",
                    "Lcom/googlecode/aviator/runtime/type/AviatorNil;");
                pushOperand(0);
            }
            else {
                // check if it is a function name
                // if
                // (AviatorEvaluator.FUNC_MAP.keySet().contains(variable.getLexeme()))
                // {
                // throw new CompileExpressionErrorException("index=" +
                // variable.getStartIndex() + ","
                // + variable.getLexeme() +
                // " is a function name,please don't use it as variable");
                // }

                mv.visitTypeInsn(NEW, "com/googlecode/aviator/runtime/type/AviatorJavaType");
                mv.visitInsn(DUP);
                mv.visitLdcInsn(variable.getLexeme());
                mv.visitMethodInsn(INVOKESPECIAL, "com/googlecode/aviator/runtime/type/AviatorJavaType", "<init>",
                    "(Ljava/lang/String;)V");
                pushOperand(2);
                popOperand();
                popOperand();
View Full Code Here

    }


    @Test
    public void testOnConstant_Variable() throws Exception {
        this.codeGenerator.onConstant(new Variable("a", 0));
        Expression exp = this.codeGenerator.getResult();
        HashMap<String, Object> env = new HashMap<String, Object>();
        long now = System.currentTimeMillis();
        env.put("a", now);
        Object result = exp.execute(env);
View Full Code Here

    public void doArithOpTest(OperatorType operatorType) throws Exception {
        NumberToken a = new NumberToken(3L, "3");
        NumberToken b = new NumberToken(3.5d, "3.5");
        Map<String, Object> env = new HashMap<String, Object>();
        env.put("c", 9L);
        codeGenerator.onConstant(new Variable("c", 0));
        codeGenerator.onConstant(a);
        codeGenerator.onConstant(b);
        switch (operatorType) {
        case ADD:
            codeGenerator.onAdd(null);
View Full Code Here

            result = eval(env);
            assertEquals(Boolean.TRUE, result);
            break;
        case LT:
            codeGenerator.onConstant(a);
            codeGenerator.onConstant(new Variable("c", 0));
            codeGenerator.onLt(null);
            result = eval(env);
            assertEquals(Boolean.TRUE, result);
            break;
        case LE:
View Full Code Here

    }


    @Test
    public void testOnMethod_withoutArguments() throws Exception {
        codeGenerator.onMethodName(new Variable("sysdate", -1));
        codeGenerator.onMethodInvoke(null);
        Object result = eval(new HashMap<String, Object>());
        assertNotNull(result);
        assertTrue(result instanceof Date);
    }
View Full Code Here

    }


    @Test
    public void testOnMethod_withTwoArguments() throws Exception {
        codeGenerator.onMethodName(new Variable("string.substring", -1));
        codeGenerator.onConstant(new StringToken("hello", -1));
        codeGenerator.onMethodParameter(null);
        codeGenerator.onConstant(new NumberToken(2L, "2"));
        codeGenerator.onMethodParameter(null);
        codeGenerator.onConstant(new NumberToken(5L, "5"));
View Full Code Here

            do {
                sb.append(peek);
                nextChar();
            } while (Character.isJavaIdentifierPart(peek) || peek == '.');
            String lexeme = sb.toString();
            Variable variable = new Variable(lexeme, startIndex);
            // If it is a reserved word(true or false)
            if (symbolTable.contains(lexeme)) {
                return symbolTable.getVariable(lexeme);
            }
            else {
View Full Code Here

TOP

Related Classes of com.googlecode.aviator.lexer.token.Variable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.