starting to implement program

This commit is contained in:
2018-05-06 21:34:49 +02:00
parent fb690e38f9
commit 3ce0505f4e
3 changed files with 377 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package worms.programs;
public abstract class BinaryExpression<L, R> implements Expression {
protected final L left;
protected final R right;
public BinaryExpression(L left, R right) {
this.left = left;
this.right = right;
}
}

View File

@@ -0,0 +1,7 @@
package worms.programs;
public interface Expression<T> {
T execute();
}

View File

@@ -0,0 +1,358 @@
package worms.programs;
import worms.model.Program;
import worms.util.ModelException;
import worms.util.MustNotImplementException;
import worms.programs.Expression;
import java.util.List;
public class ProgramFactory implements IProgramFactory {
/**
* Create a program from the given arguments.
*
* @param procs The procedure definitions for the program.
* @param main The main statement of the program. Most likely this is a
* sequence statement.
* @return A new program.
*/
@Override
public Object createProgram(List procs, Object main) throws ModelException {
System.out.println("create program");
return new Program();
}
// TODO checken of dit moet
// /**
// * Create a program from the given argument.
// *
// * @param main The main statement of the program. Most likely this is a
// * sequence statement.
// * @return A new program without procedure definitions.
// */
// @Override
// public Object createProgram(Object main) throws ModelException {
// return null;
// }
/**
* Create a procedure definition with the given name and body.
*
* @param procedureName The name of the procedure
* @param body
* @param sourceLocation
*/
@Override
public Object createProcedureDefinition(String procedureName, Object body, SourceLocation sourceLocation) {
return null;
}
/**
* Create a statement that assigns the value obtained by evaluating the
* given expression to a variable with the given name.
*
* @param variableName
* @param value
* @param sourceLocation
*/
@Override
public Object createAssignmentStatement(String variableName, Object value, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Create a print statement that prints the value obtained by evaluating the
* given expression.
*
* @param value
* @param sourceLocation
*/
@Override
public Object createPrintStatement(Object value, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Create a turn statement that makes the worm that is executing the program
* turn by the amount obtained by evaluating the given expression.
*
* @param angle
* @param location
*/
@Override
public Object createTurnStatement(Object angle, SourceLocation location) throws ModelException {
return null;
}
/**
* Create a statement that makes the worm that is executing the program move
* one step.
*
* @param location
*/
@Override
public Object createMoveStatement(SourceLocation location) throws ModelException {
return null;
}
/**
* Returns a statement that makes the worm that is executing the program jump.
*
* @param location
*/
@Override
public Object createJumpStatement(SourceLocation location) throws ModelException {
return null;
}
/**
* Returns a statement that makes the worm that is executing the program eat.
*
* @param location
*/
@Override
public Object createEatStatement(SourceLocation location) {
return null;
}
/**
* Returns a statement that makes the worm that is executing the program fire
* a weapon.
*
* @param location
*/
@Override
public Object createFireStatement(SourceLocation location) throws ModelException {
return null;
}
/**
* Create a sequence of statements involving the given list of statements.
*
* @param statements
* @param sourceLocation
*/
@Override
public Object createSequenceStatement(List statements, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Create an if-then-else statement involving the given condition and the
* given then-part and else-part.
* The else-part may be null.
*
* @param condition
* @param ifBody
* @param elseBody
* @param sourceLocation
*/
@Override
public Object createIfStatement(Object condition, Object ifBody, Object elseBody, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Create a while statement involving the given condition and given body.
*
* @param condition
* @param body
* @param sourceLocation
*/
@Override
public Object createWhileStatement(Object condition, Object body, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Create a break statement.
*
* @param sourceLocation
*/
@Override
public Object createBreakStatement(SourceLocation sourceLocation) throws ModelException, MustNotImplementException {
return null;
}
/**
* Create an invoke statement that invokes the procedure with the given name.
*
* @param procedureName
* @param sourceLocation
*/
@Override
public Object createInvokeStatement(String procedureName, SourceLocation sourceLocation) throws ModelException, MustNotImplementException {
return null;
}
/**
* Create an expression that evaluates to the current value of the given
* variable.
*
* @param variableName
* @param sourceLocation
*/
@Override
public Object createReadVariableExpression(String variableName, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Creates an expression that represents a literal double value.
*
* @param value
* @param location
*/
@Override
public Object createDoubleLiteralExpression(double value, SourceLocation location) throws ModelException {
return null;
}
/**
* Creates an expression that represents a literal boolean value.
*
* @param value
* @param location
*/
@Override
public Object createBooleanLiteralExpression(boolean value, SourceLocation location) throws ModelException {
return null;
}
/**
* Creates an expression that represents the null value.
*
* @param location
*/
@Override
public Object createNullExpression(SourceLocation location) throws ModelException {
return null;
}
/**
* Creates an expression that represents the self value, evaluating to the
* worm that executes the program.
*
* @param location
*/
@Override
public Object createSelfExpression(SourceLocation location) throws ModelException {
return null;
}
/**
* Returns an expression that evaluates to the addition of the values
* obtained by evaluating the given left and second expressions.
*
* @param left
* @param right
* @param location
*/
@Override
public Object createAdditionExpression(Object left, Object right, SourceLocation location) throws ModelException {
Expression addition = new BinaryExpression<>(left, right) {
@Override
public Object execute() {
return this.left + this.right;
}
};
return new Program();
}
/**
* Returns an expression that evaluates to the conjunction of the values
* obtained by evaluating the given left and right expressions.
*
* @param left
* @param right
* @param sourceLocation
*/
@Override
public Object createAndExpression(Object left, Object right, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Returns an expression that evaluates to true when the given expression
* evaluates to false, and vice versa.
*
* @param expression
* @param sourceLocation
*/
@Override
public Object createNotExpression(Object expression, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Returns an expression that evaluates to true if the evaluation of the
* left expression yields a value that is equal to the value obtained by
* evaluating the right expression.
*
* @param left
* @param right
* @param location
*/
@Override
public Object createEqualityExpression(Object left, Object right, SourceLocation location) throws ModelException {
return null;
}
/**
* Returns an expression that evaluates to true if the evaluation of the
* left expression yields a value that is less than the value obtained by
* evaluating the right expression.
*
* @param left
* @param right
* @param location
*/
@Override
public Object createLessThanExpression(Object left, Object right, SourceLocation location) {
return null;
}
@Override
public Object createSearchObjectExpression(Object angleDelta, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Returns an expression that evaluates to a boolean reflecting whether or not
* the executing worm belongs to the same team as the worm to which the given
* expression evaluates.
*
* @param entity
* @param sourceLocation
*/
@Override
public Object createSameTeamExpression(Object entity, SourceLocation sourceLocation) throws ModelException, MustNotImplementException {
return null;
}
/**
* Returns an expression that evaluates to the distance between the executing worm
* and the game object to which the given expression evaluates.
*
* @param entity
* @param sourceLocation
*/
@Override
public Object createDistanceExpression(Object entity, SourceLocation sourceLocation) throws ModelException {
return null;
}
/**
* Returns a boolean indicating whether or not the object to which the given
* expression evaluates is a worm.
*
* @param entity
* @param sourceLocation
*/
@Override
public Object createIsWormExpression(Object entity, SourceLocation sourceLocation) throws ModelException {
return null;
}
}