use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class SimpleExprTest method testIfElse.
@Test
public void testIfElse() {
List<Token> tokens = getSyntaxTree("call(1, true ? 1 : 2, 'foobar');");
Assert.assertEquals(1, tokens.size());
Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
Assert.assertTrue(((ExprStmtToken) tokens.get(0)).getLast() instanceof CallExprToken);
CallExprToken call = (CallExprToken) ((ExprStmtToken) tokens.get(0)).getLast();
Assert.assertEquals(3, call.getParameters().size());
Assert.assertTrue(call.getParameters().get(0).getSingle() instanceof IntegerExprToken);
Assert.assertTrue(call.getParameters().get(1).getTokens().get(1) instanceof ValueIfElseToken);
ValueIfElseToken ifElse = (ValueIfElseToken) call.getParameters().get(1).getTokens().get(1);
Assert.assertTrue(ifElse.getValue().getSingle() instanceof IntegerExprToken);
Assert.assertTrue(ifElse.getAlternative().getSingle() instanceof IntegerExprToken);
Assert.assertTrue(call.getParameters().get(2).getSingle() instanceof StringExprToken);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class SyntaxAnalyzerTest method testSimple.
@Test
public void testSimple() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("foobar;"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().listIterator().next() instanceof ExprStmtToken);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class BodyCompiler method write.
@Override
public void write(BodyStmtToken token) {
if (token != null) {
for (ExprStmtToken line : token.getInstructions()) {
expr.writeTickTrigger(line);
expr.writeExpression(line, false, false);
}
}
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class EchoCompiler method write.
@Override
public void write(EchoStmtToken token) {
for (ExprStmtToken argument : token.getArguments()) {
expr.writePushEnv();
expr.writeExpression(argument, true, false);
expr.writePopBoxing();
expr.writeSysDynamicCall(Environment.class, "echo", void.class, Memory.class);
}
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class StringBuilderValueCompiler method writeBuilder.
public void writeBuilder(List<Token> tokens, boolean binary) {
expr.writePushNewObject(StringBuilder.class);
for (Token el : tokens) {
//writePushDup();
if (el instanceof ValueExprToken) {
expr.writePush((ValueExprToken) el, true, false);
} else if (el instanceof ExprStmtToken) {
//unexpectedToken(el);
expr.writeExpression((ExprStmtToken) el, true, false, true);
} else
expr.unexpectedToken(el);
StackItem.Type peek = expr.stackPeek().type;
if (!peek.isConstant()) {
expr.writeSysDynamicCall(StringBuilder.class, "append", StringBuilder.class, Object.class);
} else
expr.writeSysDynamicCall(StringBuilder.class, "append", StringBuilder.class, peek.toClass());
}
expr.writeSysDynamicCall(StringBuilder.class, "toString", String.class);
if (binary) {
expr.writeSysStaticCall(BinaryMemory.class, "valueOf", Memory.class, String.class);
}
}
Aggregations