Search in sources :

Example 1 with CallExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken in project jphp by jphp-compiler.

the class ASMExpressionTest method testCallExpr.

@Test
public void testCallExpr() {
    ExprStmtToken expression = getASMExpression("func(1 + 2, 3) * 3").getResult();
    Assert.assertEquals(3, expression.getTokens().size());
    Assert.assertTrue(expression.getTokens().get(0) instanceof CallExprToken);
    CallExprToken call = (CallExprToken) expression.getTokens().get(0);
    Assert.assertEquals(2, call.getParameters().size());
    Assert.assertEquals("1+2", call.getParameters().get(0).getWord());
    Assert.assertEquals("3", call.getParameters().get(1).getWord());
    Assert.assertTrue(expression.getTokens().get(1) instanceof IntegerExprToken);
    Assert.assertTrue(expression.getTokens().get(2) instanceof MulExprToken);
}
Also used : CallExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) MulExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MulExprToken) IntegerExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.IntegerExprToken) Test(org.junit.Test)

Example 2 with CallExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken in project jphp by jphp-compiler.

the class ASMExpression method processToken.

protected void processToken(Token token, Stack<Token> stack, List<Token> result) {
    if (token instanceof CallExprToken) {
        CallExprToken call = (CallExprToken) token;
        if (call.getName() instanceof OperatorExprToken) {
            processOperator(stack, result, (OperatorExprToken) call.getName());
        }
        result.add(token);
    } else if (token instanceof ValueExprToken) {
        result.add(token);
    } else if (token instanceof BraceExprToken) {
        BraceExprToken brace = (BraceExprToken) token;
        if (brace.isSimpleOpened()) {
            stack.push(brace);
        } else if (brace.isSimpleClosed()) {
            if (stack.empty())
                unexpectedToken(brace);
            boolean done = false;
            do {
                Token el = stack.pop();
                if (el instanceof BraceExprToken && ((BraceExprToken) el).isSimpleOpened()) {
                    done = true;
                    break;
                }
                result.add(el);
            } while (!stack.isEmpty());
            if (!done)
                unexpectedToken(brace);
        } else
            unexpectedToken(brace);
    } else if (token instanceof OperatorExprToken) {
        OperatorExprToken operator = (OperatorExprToken) token;
        /*boolean done = !stack.empty();
            if (done){
                if (operator.isRightSide())
                    done = getPriority(stack.peek()) > prior;
                else
                    done = getPriority(stack.peek()) > prior;
            }

            if (done){
                if (prior == 1){
                    processOperator(stack, result, prior);
                    result.add(token);
                    return;
                }

                stack.push(token);
                return;
            }*/
        processOperator(stack, result, operator);
        stack.push(token);
    }
}
Also used : CallExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) OperatorExprToken(org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprToken(org.develnext.jphp.core.tokenizer.token.expr.ExprToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) OperatorExprToken(org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken) CallExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Aggregations

CallExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken)2 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)2 Token (org.develnext.jphp.core.tokenizer.token.Token)1 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)1 ExprToken (org.develnext.jphp.core.tokenizer.token.expr.ExprToken)1 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)1 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)1 MulExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MulExprToken)1 IntegerExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.IntegerExprToken)1 Test (org.junit.Test)1