forked from leethater/ADS4_2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.java
46 lines (38 loc) · 1.08 KB
/
Extensions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.awt.Graphics2D;
import java.util.List;
import java.util.ArrayList;
class Extensions{
}
class WhileInstruction extends Instruction{
protected Expression expression;
protected Instruction instruction;
public WhileInstruction(Expression expr,Instruction ins){
expression=expr;
instruction=ins;
}
public void execute(Graphics2D g, List<Identifier> map) throws Exception{
while(expression.value(map)!=0) {
instruction.execute(g,map);
}}
}
class ForInstruction extends Instruction{
protected Declaration dec;
protected Expression condition;
protected Assignment affectation;
protected Instruction list;
public ForInstruction(Declaration dec,Expression cond, Assignment aff, Instruction sup){
this.dec=dec;
this.condition=cond;
affectation=aff;
list=sup;
}
public void execute(Graphics2D g, List<Identifier> map) throws Exception{
List<Identifier> m = new ArrayList<Identifier>();
m.addAll(map);
dec.execute(g,m);
while(condition.value(m)!=0){
list.execute(g,m);
affectation.execute(g,m);
}
}
}