AddExpression.java

package edu.udel.cis.vsl.tass.model.impl.expression;

import edu.udel.cis.vsl.tass.model.IF.ModelFactoryIF;
import edu.udel.cis.vsl.tass.model.IF.SyntaxException;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF.TypeKind;

public class AddExpression extends BinaryExpression {

	public AddExpression(ModelFactoryIF factory, Expression left,
			Expression right) throws SyntaxException {
		super(factory, ExpressionKind.ADD, left, right);

		TypeIF leftType = left.type;
		TypeIF rightType = right.type;

		if (!leftType.isNumeric()) {
			throw new SyntaxException(left, "Addition requires numeric type");
		}
		if (!rightType.isNumeric()) {
			throw new SyntaxException(right, "Addition requires numeric type");
		}
		if (leftType.kind() == TypeKind.INTEGER) {
			type = rightType;
		} else {
			type = leftType;
		}
	}

	public String toString() {
		return left.atomString() + "+" + right.atomString();
	}

	public String atomString() {
		return "(" + this + ")";
	}

}