summaryrefslogtreecommitdiffstats
path: root/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/EvalIter.java
blob: f356491d386cffdb1cac8f93994ff3df29c46583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package net.sven_eisenhauer.swa_prakt1;

public class EvalIter implements ExpIter {

	@Override
	public Number traverse(ArithmeticExpression exp) {
		if(exp instanceof ArithmeticVariable) {
			return ((ArithmeticVariable) exp).getValue();
		} else {
			ArithmeticOperation actOp = (ArithmeticOperation) exp;
			Number leftVal = traverse(actOp.getLeftOperand());
			Number rightVal = traverse(actOp.getRightOperand());
			return actOp.doOperation(leftVal, rightVal);			
		}
	}

}