Exemplo n.º 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;
}
Exemplo n.º 2
0
void LetStmt::execute(EvalState & state) {
    state.setValue(identifier, exp->eval(state));
}
Exemplo n.º 3
0
void InputStmt::execute(EvalState & state) {
    int value = getInteger("? ");
    state.setValue(identifier, value);
}
Exemplo n.º 4
0
void LetStmt::execute(EvalState &state) {
    int value = exp->eval(state);
    state.setValue(identifier, value);
}