School Commit Init
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
package Models.Statements;
|
||||
|
||||
import Exceptions.BaseException;
|
||||
import Models.Expressions.IExpression;
|
||||
import Models.Program.IDictionary;
|
||||
import Models.Program.IQueue;
|
||||
import Models.Program.ProgramState;
|
||||
import Models.Types.IType;
|
||||
import Models.Values.IValue;
|
||||
|
||||
public class PrintStatement implements IStatement {
|
||||
//region Fields
|
||||
private IExpression expression;
|
||||
//endregion
|
||||
|
||||
//region Exposed Methods
|
||||
public PrintStatement(IExpression expression){
|
||||
this.expression = expression;
|
||||
}
|
||||
public String toString(){
|
||||
return "print(" + expression.toString() + ")";
|
||||
}
|
||||
|
||||
public IStatement copy(){
|
||||
return new PrintStatement(expression.copy());
|
||||
}
|
||||
|
||||
public ProgramState execute(ProgramState state) throws BaseException{
|
||||
IQueue<IValue> output = state.getOutput();
|
||||
output.enqueue(expression.evaluate(state.getSymbolTable(), state.getHeap() ));
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary<String, IType> typeCheck(IDictionary<String, IType> typeTable) throws BaseException{
|
||||
expression.typeCheck(typeTable);
|
||||
return typeTable;
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
Reference in New Issue
Block a user