I am interested in expanding my knowledge of computer programming by introducing a stack-based programming language. I’m looking for tips on where to start, as I intend to have functions like pushint 1 for this that push an integer with a value of 1 to the top of the stack and control the flow with labels like L01: jump L01: ".
So far I have implemented the C # implementation for what I want my language to work (I wanted to associate with it, but IDEOne is blocked), but it is very dirty and needs to be optimized. It converts the input to XML and then parses it. My goals are to go to a lower level of the language (possibly C / C ++), but my problems are implementing a stack that can store different types of data and does not have a fixed size.
In the end, I would also like to implement arrays and functions. Also, I think I need a better Lexer, and I wonder if parsing would be a good idea for such a simplified language.
Any advice / criticism is welcome, and please consider that I am still new to programming (I just completed CompSci I AP). Links to stack-based open source languages are also welcome.
Here is the basic program that I would like to try and interpret / compile (where [this is a comment] ):
[Hello World!] pushchar '\n' pushstring "Hello World!" print [Count to 5 and then count down!] pushint 1 setlocal 0 L01: pushchar '\n' getlocal 0 print [print x + '\n'] getlocal 0 increment setlocal 0 [x = x + 1] pushint 5 getlocal 0 lessthan [x < 5] iftrue L01 L02: pushchar '\n' getlocal 0 print [print x + '\n'] getlocal 0 decrement setlocal 0 [x = x - 1] pushint 0 getlocal 0 greaterthan [x > 0] iftrue L02
Expected Result:
Hello World! 1 2 3 4 5 4 3 2 1
Wingpad
source share