예제 #1
0
파일: exp.cpp 프로젝트: Azureyjt/TCLOUD_LAB
int CompoundExp::eval(EvalState & state) {
	if (op == "=") {
		if (lhs->getType() != IDENTIFIER) {
			error("Illegal variable in assignment");
      	}
     	int val = rhs->eval(state);
      	state.setValue(((IdentifierExp *) lhs)->getName(), val);
      	return val;
   	}
   	int left = lhs->eval(state);
   	int right = rhs->eval(state);
   	if (op == "+") return left + right;
   	if (op == "-") return left - right;
   	if (op == "*") return left * right;
   	if (op == "/") {
   		if (right == 0) { 
   			cout << "DIVIDE BY ZERO" << endl;
   			error("");
   		}
   		else {
   			return left / right;
   		}
   	}
   	return 0;
}
예제 #2
0
void LetStmt::execute(EvalState & state) {
    state.setValue(identifier, exp->eval(state));
}
예제 #3
0
void InputStmt::execute(EvalState & state) {
    int value = getInteger("? ");
    state.setValue(identifier, value);
}
예제 #4
0
void LetStmt::execute(EvalState &state) {
    int value = exp->eval(state);
    state.setValue(identifier, value);
}