summaryrefslogtreecommitdiff
path: root/src/minijava/symboltable/MExpression.java
blob: 17d6db8d1e7481c6fe7e6e8914460aa17c7b296c (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package minijava.symboltable;

public class MExpression extends MType {
	public enum Operator {
		And, Smaller, Plus, Minus, Times, ArrayLookup,
		ArrayLen, MsgSend, Primary;
	}
	Operator e_op;
	public MExpression first, second;
	// for msgsend, we need an identifier and a expression list
	public MIdentifier e_id;
	public MExpressionList e_list;
	// Expression type
	public MPrimaryExpr e_exp;
	// Expression value (for primary expression)
	public String e_val;
	
	public MExpression(Operator op) {
		e_op = op;
		e_exp = new MPrimaryExpr();
		e_list = new MExpressionList();
	}
	
	public void printExpr(int spaces) {
		System.err.print(OutputFormat.spaces(spaces));
		
		switch (e_op) {
		case Primary:
			e_exp.printPrimExpr(0);
			break;
		case And:
			first.printExpr(0);
			System.err.print("&&");
			second.printExpr(0);
			break;
		case Smaller:
			first.printExpr(0);
			System.err.print("<");
			second.printExpr(0);
			break;
		case Plus:
			first.printExpr(0);
			System.err.print("+");
			second.printExpr(0);
			break;
		case Minus:
			first.printExpr(0);
			System.err.print("-");
			second.printExpr(0);
			break;
		case Times:
			first.printExpr(0);
			System.err.print("*");
			second.printExpr(0);
			break;
		case ArrayLookup:
		case ArrayLen:
		case MsgSend:
		}
	}
}