Search in sources :

Example 1 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class Redsnake method buildAST.

public Statement buildAST(CharStream inputStream) {
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.statement();
    return (Statement) astBuilder.visit(t);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) TokenStream(org.antlr.v4.runtime.TokenStream) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) Statement(net.taken.redsnake.tree.statements.Statement) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 2 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class ProgramTest method shouldReturnSomethingWhenParsingStmt.

@Test
void shouldReturnSomethingWhenParsingStmt() {
    Statement stmt = parseStatement("598");
    assertEquals(new RedsInteger(598), stmt.execute(env));
}
Also used : TestUtils.parseStatement(net.taken.redsnake.tree.TestUtils.parseStatement) Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 3 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class AssignmentTest method shouldStoreVariableWhenParseAssignment.

@Test
void shouldStoreVariableWhenParseAssignment() {
    Statement stmt = parseStatement("a = 771");
    stmt.execute(env);
    assertEquals(new RedsInteger(771), env.getVariable("a"));
}
Also used : Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 4 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldBeRightAssociativeWhenExecuteBinaryExprPow.

@Test
void shouldBeRightAssociativeWhenExecuteBinaryExprPow() {
    Statement stmt = parseStatement("2**3**2");
    assertEquals(new RedsInteger(512), stmt.execute(env));
}
Also used : TestUtils.parseStatement(net.taken.redsnake.tree.TestUtils.parseStatement) Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 5 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldPrioritizeUnaryMinusOverMultiplyDivideAndModulo.

@Test
void shouldPrioritizeUnaryMinusOverMultiplyDivideAndModulo() {
    Statement stmt = parseStatement("2*-1/-1*(1%-(-2))");
    assertEquals(new RedsInteger(2), stmt.execute(env));
}
Also used : TestUtils.parseStatement(net.taken.redsnake.tree.TestUtils.parseStatement) Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Aggregations

Statement (net.taken.redsnake.tree.statements.Statement)8 RedsInteger (net.taken.redsnake.lang.RedsInteger)7 Test (org.junit.jupiter.api.Test)7 TestUtils.parseStatement (net.taken.redsnake.tree.TestUtils.parseStatement)5 RedsnakeLexer (net.taken.redsnake.parser.RedsnakeLexer)1 RedsnakeParser (net.taken.redsnake.parser.RedsnakeParser)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 TokenStream (org.antlr.v4.runtime.TokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1