summaryrefslogtreecommitdiff
path: root/src/minijava/typecheck/PrintError.java
blob: 12eb3c5481adaf8413c7a911baa6a2fff3ae0ccf (plain)
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
/**
 * 存放错误信息并统一打印
 */
package minijava.typecheck;

import java.util.Vector;

public class PrintError {
	private static Vector<String> errors = new Vector<String>();

	public static void print(int line, int column, String error_msg) {
		String msg = "Line " + line + " Column " + column + ": " + error_msg;
		errors.addElement(msg); // 存储错误信息
	}

	// 统一进行打印
	public static void printAll() {
		int sz = errors.size();
		for (int i = 0; i < sz; i++) {
			System.out.println(errors.elementAt(i));
		}
	}
	
	public static void outputResult() {
		if (errors.size()>0) {
			System.out.println("Type error");
		} else {
			System.out.println("Program type checked successfully");
		}
	}
}