EOS 2  1.1.0
Einfache Objektbasierte Sprache
Sum.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.baseparser;
2 
3 import java.util.ArrayList;
4 
5 import de.lathanda.eos.vm.Command;
6 import de.lathanda.eos.vm.commands.AddD;
7 import de.lathanda.eos.vm.commands.AddI;
8 import de.lathanda.eos.vm.commands.Concatenate;
9 
18 public class Sum extends Expression {
19  private final Expression left;
20  private final Expression right;
21  private boolean isConcatenate = false;
22 
23  public Sum(Expression left, Expression right) {
24  this.left = left;
25  this.right = right;
26  prio = 4;
27  }
28 
29  @Override
30  public void compile(ArrayList<Command> ops, boolean autoWindow) throws Exception {
31  left.compile(ops, autoWindow);
32  right.compile(ops, autoWindow);
33  if (isConcatenate) {
34  ops.add(new Concatenate());
35  } else if (type.isInteger()) {
36  ops.add(new AddI());
37  } else {
38  ops.add(new AddD());
39  }
40  }
41 
42  @Override
43  public void resolveNamesAndTypes(Expression with, Environment env) {
44  left.resolveNamesAndTypes(with, env);
45  right.resolveNamesAndTypes(with, env);
46  if (!left.getType().isNumber() || !right.getType().isNumber()) {
47  isConcatenate = true;
48  type = Type.getString();
49  } else {
50  isConcatenate = false;
51  type = left.getType().mergeTypes(right.getType());
52  }
53  }
54 
55  @Override
56  public String toString() {
57  return "(" + left + "+" + right + ")";
58  }
59 
60  @Override
61  public String getLabel() {
62  return createText("Sum.Label", getLabelLeft(left), getLabelRight(right));
63  }
64 }
String getLabelRight(Expression e)
Definition: Expression.java:82
abstract void compile(ArrayList< Command > ops, boolean autoWindow)
final String createText(String id, Object... args)
Definition: Node.java:34
abstract void resolveNamesAndTypes(Expression with, Environment env)
void resolveNamesAndTypes(Expression with, Environment env)
Definition: Sum.java:43
void compile(ArrayList< Command > ops, boolean autoWindow)
Definition: Sum.java:30
Sum(Expression left, Expression right)
Definition: Sum.java:23
static SystemType getString()
Definition: Type.java:96
Type mergeTypes(Type right)
Definition: Type.java:62
Impressum