Section D.12 Exercise Sheet 12
1. Express Expressions.
In this exercise you should the complete No Hau's unfinished project Expressions. The project implements a representation for simple arithmetic expressions. The corresponding git
repo is: https://gitlab.cs.uni-saarland.de/programming-2/Expressions.git
The documentation of the project provides the specification. Please proceed as follows:
-
Create classes that implement the expressions with binary operators \(+, -, \ast, \div\) as well as the unary minus. These classes should inherit from
BinaryExpression
orUnaryExpression
, respectively. Extend the classes with fitting constructors.Remark: To ensure that the tests work as expected, you should name the classes in the following way:
AddExpression
,SubExpression
,MulExpression
,DivExpression
,NegExpression
Implement the method
public String toString()
in the three abstract classesUnaryExpression
,ConstExpression
andBinaryExpression
.Implement
public boolean equals(Object o)
. Make sure that the method considers expressions that evaluate to the same value as equal.Complete the project by implementing
public int eval()
and add aMain
class with a main method such that the project can be used to evaluate arbitrary expressions.(Bonus): Create classes to support the additional operators \(\wedge, \vee, \) and \(\neg\) (
AndExpression
,OrExpression
,NotExpression
). You will also have to extend theEnum Operators
. For subtask 1, 2 and 4 proceed as before. For subtask 3 you should think whether a definition analogous to the arithmetic expressions is the right way to go.
202207011400
The solution of the task is on branch deploy/basic/eval/solution
of the given repository.
The solution of the task with bonus is on branch deploy/advanced/eval/solution
.