/
SemanticException.java
51 lines (40 loc) · 1.1 KB
/
SemanticException.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
47
48
49
50
51
package com.bajdcc.rt.error;
/**
* 语义错误
*/
public class SemanticException extends Exception {
private final SemanticErrorType type;
private final Object info;
public SemanticException(Object info, String message, SemanticErrorType type) {
super(message);
this.type = type;
this.info = info;
}
public SemanticErrorType getType() {
return type;
}
@Override
public String toString() {
return String.format("%s #%s# \"%s\"", super.toString(), type.getName(), info);
}
public enum SemanticErrorType {
REDECL("重复定义"),
UNDECL("未定义"),
NETYPE("类型不一致"),
ERANGE("范围非法"),
ETOKEN("表达式无意义"),
EPARAM("参数非法"),
ENIMPL("尚未实现"),
ENOANS("无可用解");
private String name;
SemanticErrorType(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}