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);
}
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);
}
}
Aggregations