Hi everyone, I am currently implementing a simple programming language for learning, but I need some advice. I am currently developing my own interpreter and am having a problem.
My language is a subset of C, and I have a problem with implementing a stack interpreter. The following language will be compiled in the following language:
somefunc () { 1 + 2; } main () { somefunc (); }
Now this is good, but when "1 + 2" is computed, the result is pushed onto the stack, and then the function returns, but the stack still has a number, and this should not be. How can I get around this problem?
I was thinking about saving the βstateβ of the stack before calling the function and restoring the βstateβ after calling the function. For example, keeping the number of elements on the stack, then execute the function code, go back, and then put it from the stack until we have the same number of elements as before (or maybe +1 if the function returned something).
Any ideas? Thanks for any tips!
c ++ interpreter vm-implementation
Filip jeremic
source share