Пример #1
0
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);
}