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