1: package compiler;
2:
3: import java.io.BufferedWriter;
4:
5: public class Err {
6:
7: public int errCount = 0;
8: public static final String[] errInfo = new String[]{
9: "",
10: "1.应是=而不是:=",
11: "2.=后应为数",
12: "3.标识符后应为=",
13: "4.const,var,procedure 后应为标识符",
14: "5.漏掉逗号或分号",
15: "6.过程说明后的符号不正确",
16: "7.应为语句",
17: "8.程序体内语句后的符号不正确",
18: "9.应为句号",
19: "10.语句之间漏分号",
20: "11.标识符未说明",
21: "12.不可向常量或过程名赋值",
22: "13.应为赋值运算符:=",
23: "14.call后应为标识符",
24: "15.不可调用常量或变量",
25: "16.应为then",
26: "17.应为分号或end",
27: "18.应为do",
28: "19.语句后的符号不正确",
29: "20.应为关系运算符",
30: "21.表达式内不可有过程标识符",
31: "22.漏右括号",
32: "23.因子后不可为此符号",
33: "24.表达式不能以此符号开始",
34: "25.这个数太大",
35: "26.Not Defined Yet",
36: "27.Not Defined Yet",
37: "28.Not Defined Yet",
38: "29.Not Defined Yet",
39: "30.Not Defined Yet",
40: "31.数越界",
41: "32.嵌套层数过大",
42: "33.格式错误,应为右括号",
43: "34.格式错误,应为左括号",
44: "35.read()中的变量未声明"
45: };
46:
47: /**
48: * 打印错误信息
49: * @param errcode
50: */
51: public void report(int errcode,int line) {
52: try {
53: System.out.println("*** line( "+line+"):" + errInfo[errcode] + " ***");
54: PL0.errWriter.write("*** line ( "+line+"):"+ errInfo[errcode] + " ***\n");
55: errCount++;
56: }catch(Exception e){
57: e.printStackTrace();
58: System.out.println("***print error infomation meet with error***");
59: }
60:
61: }
62: }