summaryrefslogtreecommitdiff
path: root/src/minijava/symboltable/MStatement.java
blob: 6410ca08b4a3d95bfadd697378556cca1075e9ef (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package minijava.symboltable;

public class MStatement extends MType {
	public enum Keyword {
		Block, Assign, ArrAssign, If, While, Print;
	}
	Keyword s_type;
	public MStatementList s_list; // for block statement
	public MIdentifier s_id; // for assign, array assign
	public MExpression e_first, e_second; // for assign(e_first), array assign, if, while, print
	public MStatement s_first, s_second; // for if, while
	
	public MStatement(Keyword keyw) {
		s_type = keyw;
		s_list = null;
		s_id = null;
		e_first = e_second = null;
		s_first = s_second = null;
	}
	
	public void printStatement(int spaces) {
		String sp = OutputFormat.spaces(spaces);
		
		switch (s_type) {
		case Block:
			System.err.println(sp+"Block statement:");
			break;
		case Assign:
			System.err.print(sp+"="+" ("+s_id.getName()+") (");
			e_first.printExpr(0);
			System.err.println(")");
			break;
		case ArrAssign:
			System.err.println(sp+"[]=");
			break;
		case If:
			System.err.println(sp+"if");
			break;
		case While:
			System.err.println(sp+"while");
			break;
		case Print:
			System.err.println(sp+"print");
			break;
		}
	}
}