EOS 2  1.1.0
Einfache Objektbasierte Sprache
Sequence.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.baseparser;
2 
3 import de.lathanda.eos.vm.Command;
4 import de.lathanda.eos.vm.Marker;
5 import de.lathanda.eos.vm.ProgramNode;
6 
7 import java.util.ArrayList;
8 import java.util.List;
9 
16 public class Sequence extends Node implements ProgramSequence {
17 
18  private final ArrayList<Node> sequence;
19  int index = 0;
20 
21  public Sequence() {
22  this.sequence = new ArrayList<>();
23  }
24 
25  public Sequence(List<Node> sequence) {
26  this.sequence = new ArrayList<>();
27  this.sequence.addAll(sequence);
28  }
29 
30  public void append(Sequence s) {
31  for (Node n : s.sequence) {
32  append(n);
33  }
34  }
35 
36  public void append(Node s) {
37  sequence.add(s);
38  if (marker == null) {
39  marker = new Marker(s, this);
40  } else {
41  marker.extend(s.getMarker());
42  }
43  }
44 
45  @Override
46  public ArrayList<ProgramNode> getInstructions() {
47  ArrayList<ProgramNode> temp = new ArrayList<ProgramNode>(sequence.size());
48  sequence.forEach(i -> temp.add(i));
49  return temp;
50  }
51 
52  @Override
53  public void compile(ArrayList<Command> ops, boolean autoWindow) throws Exception {
54  for (Node instruction : sequence) {
55  if (instruction.getType().isVoid()) {
56  // none void instruction would corrupt the parameter stack
57  // we can choose between adding an artificial consumer or to not
58  // compile the instruction
59  // as this type of instruction has no effect, we do not compile
60  // it
61  instruction.compile(ops, autoWindow);
62  }
63  }
64  }
65 
66  @Override
67  public void resolveNamesAndTypes(Expression with, Environment env) {
68  sequence.stream().forEachOrdered((instruction) -> {
69  instruction.resolveNamesAndTypes(with, env);
70  if (!instruction.getType().isVoid()) {
71  env.addError(instruction.getMarker(), "StatementWithReturn", instruction);
72  }
73  });
74  }
75 
76  @Override
77  public String toString() {
78  StringBuilder res = new StringBuilder();
79  for (MarkedNode n : sequence) {
80  res.append(n).append("\n");
81  }
82  return res.toString();
83  }
84 
85  @Override
86  public String getLabel() {
87  return null; // no label
88  }
89 }
void resolveNamesAndTypes(Expression with, Environment env)
Definition: Sequence.java:67
ArrayList< ProgramNode > getInstructions()
Definition: Sequence.java:46
Sequence(List< Node > sequence)
Definition: Sequence.java:25
void compile(ArrayList< Command > ops, boolean autoWindow)
Definition: Sequence.java:53
void extend(Marker marker)
Definition: Marker.java:86
Impressum