Sign in to follow this  

Hmmm.....design problem

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a little scripting language. So, You have an instruction like "7 + 4", right, and then you have an assignment instruction: "variable = 7 + 4;". I am having a problem. I have a basic instruction class. There is a Variable object (class with float, int, string, so can hold either value) that is used as the return value for that instruction: eg. a multiplication or addition instruction. Each instruction object has a function 'execute' (defined as pure virtual in the parent class). For the assignment instruction, it has an Instruction* data member that points to an Instruction object that it calls execute on and then grabs the return value and then assigns it. So, the problem now is, I have a vector of Instruction objects, and this object that the return value is grabbed from comes OFF THE ASSIGNMENT OBJECT instead of being in the vector that all the other instructions are in. I saw that this really wasn't the best way because that could become really confusing. I also thought of splitting it up into 2 instructions. So vector[i] would be the addition instruction and that would keep its value, and then the value would be passed to the assignment instruction (vector[i+1]), and then it would do the assignment. Is this a better way? Can someone think of a better way than this?

Share this post


Link to post
Share on other sites
I think for arithmetic you would find a stack more advantageous and less confusing.

I suggest all arithmetic operations should be done on the stack and the assignment pops the top of the stack.

Does this help?

Share this post


Link to post
Share on other sites

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this