Search in sources :

Example 6 with CodeGenerator

use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.

the class ExpressionParser method withoutElse.

private boolean withoutElse() {
    final CodeGenerator cg = getCodeGeneratorWithTimes();
    cg.onConstant(Variable.NIL);
    cg.onTernaryRight(this.lookhead);
    return false;
}
Also used : CodeGenerator(com.googlecode.aviator.code.CodeGenerator)

Example 7 with CodeGenerator

use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.

the class ExpressionParser method elseStatement.

private boolean elseStatement(final boolean isWhile, final boolean ifBodyHasReturn) {
    if (isWhile) {
        // Call __reducer_break(nil)
        final CodeGenerator cg = getCodeGeneratorWithTimes();
        cg.onMethodName(Constants.ReducerBreakFn);
        cg.onConstant(Variable.NIL);
        cg.onMethodParameter(this.lookhead);
        cg.onMethodInvoke(this.lookhead);
        cg.onTernaryRight(this.lookhead);
        return false;
    }
    if (expectChar(';')) {
        return withoutElse();
    }
    boolean hasReturn = false;
    boolean hasElsif = this.lookhead == Variable.ELSIF;
    boolean hasElse = this.lookhead == Variable.ELSE;
    if (this.lookhead != null && (hasElse || hasElsif || ifBodyHasReturn)) {
        if (hasElse) {
            move(true);
            if (expectChar('{')) {
                this.scope.enterBrace();
                move(true);
                hasReturn = elseBody(false);
                if (expectChar('}')) {
                    this.scope.leaveBrace();
                    move(true);
                } else {
                    reportSyntaxError("missing '}' to close 'else' body");
                }
            } else {
                reportSyntaxError("expect '{' for else statement");
            }
        } else if (hasElsif) {
            hasReturn = ifStatement(false, true);
            getCodeGenerator().onTernaryRight(this.lookhead);
        } else if (ifBodyHasReturn) {
            hasReturn = elseBody(true);
        } else {
            return withoutElse();
        }
        return hasReturn;
    } else {
        // Missing else statement, always nil.
        return withoutElse();
    }
}
Also used : CodeGenerator(com.googlecode.aviator.code.CodeGenerator)

Example 8 with CodeGenerator

use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.

the class ExpressionParser method join.

public void join() {
    and();
    while (true) {
        Token<?> opToken = this.lookhead;
        if (expectChar('|')) {
            getCodeGeneratorWithTimes().onJoinLeft(opToken);
            move(true);
            if (expectChar('|')) {
                move(true);
                and();
                getCodeGeneratorWithTimes().onJoinRight(opToken);
            } else {
                reportSyntaxError("expect '|'");
            }
        } else {
            // Process operator alias
            String alias = this.instance.getOperatorAliasToken(OperatorType.OR);
            if (alias != null) {
                if (opToken != null && opToken.getType() == TokenType.Variable && opToken.getLexeme().equals(alias)) {
                    CodeGenerator cg = getCodeGeneratorWithTimes();
                    cg.onJoinLeft(opToken);
                    move(true);
                    and();
                    cg.onJoinRight(opToken);
                    continue;
                }
            }
            break;
        }
    }
}
Also used : CodeGenerator(com.googlecode.aviator.code.CodeGenerator)

Example 9 with CodeGenerator

use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.

the class ExpressionParser method and.

public void and() {
    bitOr();
    while (true) {
        Token<?> opToken = this.lookhead;
        if (expectChar('&')) {
            CodeGenerator cg = getCodeGeneratorWithTimes();
            cg.onAndLeft(opToken);
            move(true);
            if (expectChar('&')) {
                move(true);
                bitOr();
                cg.onAndRight(opToken);
            } else {
                reportSyntaxError("expect '&'");
            }
        } else {
            // Process operator alias
            String alias = this.instance.getOperatorAliasToken(OperatorType.AND);
            if (alias != null) {
                if (opToken != null && opToken.getType() == TokenType.Variable && opToken.getLexeme().equals(alias)) {
                    CodeGenerator cg = getCodeGeneratorWithTimes();
                    cg.onAndLeft(opToken);
                    move(true);
                    bitOr();
                    cg.onAndRight(opToken);
                    continue;
                }
            }
            break;
        }
    }
}
Also used : CodeGenerator(com.googlecode.aviator.code.CodeGenerator)

Aggregations

CodeGenerator (com.googlecode.aviator.code.CodeGenerator)9 EvalCodeGenerator (com.googlecode.aviator.code.EvalCodeGenerator)2 NoneCodeGenerator (com.googlecode.aviator.code.NoneCodeGenerator)2 OptimizeCodeGenerator (com.googlecode.aviator.code.OptimizeCodeGenerator)2 ASMCodeGenerator (com.googlecode.aviator.code.asm.ASMCodeGenerator)2 InterpretCodeGenerator (com.googlecode.aviator.code.interpreter.InterpretCodeGenerator)2 ExpressionLexer (com.googlecode.aviator.lexer.ExpressionLexer)2 ExpressionParser (com.googlecode.aviator.parser.ExpressionParser)2 LambdaGenerator (com.googlecode.aviator.code.LambdaGenerator)1 CompileExpressionErrorException (com.googlecode.aviator.exception.CompileExpressionErrorException)1 SymbolTable (com.googlecode.aviator.lexer.SymbolTable)1 Variable (com.googlecode.aviator.lexer.token.Variable)1 Parser (com.googlecode.aviator.parser.Parser)1 ScopeInfo (com.googlecode.aviator.parser.ScopeInfo)1 FunctionParam (com.googlecode.aviator.runtime.FunctionParam)1 LambdaFunction (com.googlecode.aviator.runtime.function.LambdaFunction)1 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1