Компиляторы 4 лаба (7) Message & Compiler

 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
import java.util.ArrayList;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.*;
import java.lang.*;
public class Message {
public boolean IsError;
public String Text;
public Message (boolean isError, String text) {
IsError = isError;
Text = text;
}
}
public class Compiler {
private SortedMap<Position,Message> messages;
public Compiler(){
messages = new TreeMap<Position, Message>();
}
public void AddMessage (boolean isErr, Position c, String text) {
messages.put(c, new Message(isErr,text));
}
public void OutputMessages(){
for(Map.Entry<Position, Message> entry: messages.entrySet()){
Position key = entry.getKey();
Message value = entry.getValue();
System.out.print(value.IsError ? "Error":"Warning");
System.out.print(" " + key + ": ");
System.out.println(value.Text);
}
}
}