Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Stack programming language
- BookOwl
-
Scratcher
1000+ posts
Stack programming language
Stack 1.1 has been released. Please see the end of this post for details.
Introduction
As you can probably tell from the title, this topic is about my new programming language, Stack. Stack is a stack-oriented programming language that is written in Reverse Polish notation.
Before I can show you Stack, you need to know what a stack-oriented programming language is.
Tutorial
Here is a simple “Hello, World!” program written in Stack:
Let's break this down. Stack operates on tokens, which come in two types: Literals and Operators. There are 4 different types of literals.
When Stack encounters a literal, all that it does is put it on the stack until an operator pops it off.
Operators
An operator performs an action. There are 22 built-in operators. Most operators work by popping token(s) off the stack, perform an action or calculation, and then push the result(s) back onto the stack. For example, the * operator pops two tokens from the stack, multiplies them, and then pushes the result onto the stack. The print operator works simerly, it pops a token from the stack annd then prints it. It does not push any tokens onto the stack.
A list of operators and a description of each can be found here.
So, when stack executes, it
Examples:
This section includes example Stack programs. If you have one, please post it and I may add it here!
PLEASE NOTE:
You MUST have a space at the end of each line of text in order for Stack to know where one token ends and another begins. If you do not have the spaces, you will have very weird errors.
Factorial Calculator:
@Zatnic made a
Version 1.1 Changes:
Everything that I said above is still true, however version 1.1 added several new features including:
Links:
Stack: https://scratch.mit.edu/projects/65692742/
Stack Docs: https://docs.google.com/document/d/1SwdhFJw_odmBCcUfCe1zcq7N8u-kQ7mPdzyrSQczGXM/edit?usp=sharing
Stack Studio: https://scratch.mit.edu/studios/1327736/
Stack Change Log: https://scratch.mit.edu/projects/67819620/
Please tell me what you think!
Introduction
As you can probably tell from the title, this topic is about my new programming language, Stack. Stack is a stack-oriented programming language that is written in Reverse Polish notation.
Before I can show you Stack, you need to know what a stack-oriented programming language is.
A stack-oriented programming language is one that relies on a stack machine model for passing parameters.For more information, please see the wikipedia page on Stack-oriented programming language. Now that that's out of the way, I can show how Stack works.
Stack-oriented programming languages operate upon one or more stacks, each of which may serve different purposes. Because of this, programming constructs in other programming languages may need to be modified for use in a stack-oriented programming language. Adding to this, some stack-oriented programming languages operate in Reverse Polish or postfix notation - that is, the arguments or parameters for some command are stated before the actual command itself. For example, in RPN, one would say “2, 3, multiply” instead of “multiply, 2, 3” (prefix or Polish notation) or “2 multiply 3” (infix notation).
Tutorial
Here is a simple “Hello, World!” program written in Stack:
"Hello, World" print
- Strings
- Numbers
- Bools
and - Names
When Stack encounters a literal, all that it does is put it on the stack until an operator pops it off.
Operators
An operator performs an action. There are 22 built-in operators. Most operators work by popping token(s) off the stack, perform an action or calculation, and then push the result(s) back onto the stack. For example, the * operator pops two tokens from the stack, multiplies them, and then pushes the result onto the stack. The print operator works simerly, it pops a token from the stack annd then prints it. It does not push any tokens onto the stack.
A list of operators and a description of each can be found here.
So, when stack executes
"Hello, World" print
- Pushes the “Hello, World!” string token to the stack.
- Runs the print operator which pops the “Hello, World!” token and prints it.
- There are no tokens left, so the program is done.
Examples:
This section includes example Stack programs. If you have one, please post it and I may add it here!
PLEASE NOTE:
You MUST have a space at the end of each line of text in order for Stack to know where one token ends and another begins. If you do not have the spaces, you will have very weird errors.
Factorial Calculator:
"Factorial Calculator" print
"Enter a number" input
number
in set
1 c set
1 r set
39
c get in get 1 + = if goto
r get c get * r set
c get 1 + c set
15 goto
in get string " factorial is " concat r get string concat print
@Zatnic made a
short choose your own adventure type thing:
98 ending set
"***THE STACK STORY***" print
"By someone awesome" print
23 goto
o1 o2 msg get " / Enter option number:" concat input "1" = if pop get goto
"Hi, This is ***THE STACK STORY*** / 1: Do something / 2: Stack is cool" msg set
34 o1 set 45 o2 set 10 goto
"You go do something; what do you do? / 1: Fly through a cloud! / 2: Read a story" msg set
56 o1 set 23 o2 set 10 goto
"Well, this is a story about HTML!!! / 1: Realistic HTML / 2: Unrealistic HTML" msg set
67 o1 set 71 o2 set 10 goto
"OK, how do you fly? / 1: In an airplane / 2: Duh, I'm a fairy; I fly with my wings" msg set
82 o1 set 86 o2 set 10 goto
"HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages --Wikipedia" ending get goto
"An HTML page woke up, and <blink>ed its <i>s / 1: Use CSS instead of <blink> / 2: OK, continue" msg set
90 o1 set 94 o2 set 10 goto
"You get in an airplane and go to fly through a cloud, but unfortunately, the cloud is taking a walk!" ending get goto
"You flutter over to a nearby cloud and say, 'Hi, Cloudy! Can I fly through you?' / Cloudy looks affirmative in a cloudy sort of way, and you fly through!" ending get goto
"Fine, the page <style>i {animation-duration: 1s;animation-name: blink;animation-iteration-count: 3;animation-timing-function: step-ending;}@keyframes blink {from {opacity: 1;}50% {opacity: 0;}to {opacity: 1;}}</style>ed its <i>s" ending get goto
"Then the user closed the tab and the page died" ending get goto
" / END" concat input "I said, 'END' / The story's over!" input ending get 3 + goto
Version 1.1 Changes:
Everything that I said above is still true, however version 1.1 added several new features including:
- The Stack Extension Protocol, a way to extend the language.
- The Stack API, a simple way to run Stack code from anywhere in a project and get it's result.
- Help on setting up a Stack Language Environment, a personalized execution environment containing a user's version of the Stack Language, his/hers extensions, and other data.
Links:
Stack: https://scratch.mit.edu/projects/65692742/
Stack Docs: https://docs.google.com/document/d/1SwdhFJw_odmBCcUfCe1zcq7N8u-kQ7mPdzyrSQczGXM/edit?usp=sharing
Stack Studio: https://scratch.mit.edu/studios/1327736/
Stack Change Log: https://scratch.mit.edu/projects/67819620/
Please tell me what you think!
Last edited by BookOwl (Aug. 27, 2015 16:25:28)
- al-x
-
Scratcher
45 posts
Stack programming language
You might consider changing the name because Stack is the name for a Scratch 1.4 mod. Link to old Scratch forums page for Stack
- blob8108
-
Scratcher
1000+ posts
Stack programming language
You might consider changing the name because Stack is the name for a Scratch 1.4 modI wouldn't worry about it; it's been a long time, and people are unlikely to confuse the two

- BookOwl
-
Scratcher
1000+ posts
Stack programming language
OkYou might consider changing the name because Stack is the name for a Scratch 1.4 modI wouldn't worry about it; it's been a long time, and people are unlikely to confuse the two

- BookOwl
-
Scratcher
1000+ posts
Stack programming language
Stack 1.1 has been released!
Please see the first post for details.
Please see the first post for details. - NoMod-Programming
-
Scratcher
1000+ posts
Stack programming language
Stack 1.1 has been released!Awesome!!!Please see the first post for details.
- Zatnik
-
Scratcher
100+ posts
Stack programming language
I made a (very short) choose your own adventure type thing:
98 ending set
"***THE STACK STORY***" print
"By someone awesome" print
23 goto
o1 o2 msg get " / Enter option number:" concat input "1" = if pop get goto
"Hi, This is ***THE STACK STORY*** / 1: Do something / 2: Stack is cool" msg set
34 o1 set 45 o2 set 10 goto
"You go do something; what do you do? / 1: Fly through a cloud! / 2: Read a story" msg set
56 o1 set 23 o2 set 10 goto
"Well, this is a story about HTML!!! / 1: Realistic HTML / 2: Unrealistic HTML" msg set
67 o1 set 71 o2 set 10 goto
"OK, how do you fly? / 1: In an airplane / 2: Duh, I'm a fairy; I fly with my wings" msg set
82 o1 set 86 o2 set 10 goto
"HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages --Wikipedia" ending get goto
"An HTML page woke up, and <blink>ed its <i>s / 1: Use CSS instead of <blink> / 2: OK, continue" msg set
90 o1 set 94 o2 set 10 goto
"You get in an airplane and go to fly through a cloud, but unfortunately, the cloud is taking a walk!" ending get goto
"You flutter over to a nearby cloud and say, 'Hi, Cloudy! Can I fly through you?' / Cloudy looks affirmative in a cloudy sort of way, and you fly through!" ending get goto
"Fine, the page <style>i {animation-duration: 1s;animation-name: blink;animation-iteration-count: 3;animation-timing-function: step-ending;}@keyframes blink {from {opacity: 1;}50% {opacity: 0;}to {opacity: 1;}}</style>ed its <i>s" ending get goto
"Then the user closed the tab and the page died" ending get goto
" / END" concat input "I said, 'END' / The story's over!" input ending get 3 + goto
- BookOwl
-
Scratcher
1000+ posts
Stack programming language
I made a (very short) choose your own adventure type thing:COOL! I will add that to the examples.98 ending set
"***THE STACK STORY***" print
"By someone awesome" print
23 goto
o1 o2 msg get " / Enter option number:" concat input "1" = if pop get goto
"Hi, This is ***THE STACK STORY*** / 1: Do something / 2: Stack is cool" msg set
34 o1 set 45 o2 set 10 goto
"You go do something; what do you do? / 1: Fly through a cloud! / 2: Read a story" msg set
56 o1 set 23 o2 set 10 goto
"Well, this is a story about HTML!!! / 1: Realistic HTML / 2: Unrealistic HTML" msg set
67 o1 set 71 o2 set 10 goto
"OK, how do you fly? / 1: In an airplane / 2: Duh, I'm a fairy; I fly with my wings" msg set
82 o1 set 86 o2 set 10 goto
"HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages --Wikipedia" ending get goto
"An HTML page woke up, and <blink>ed its <i>s / 1: Use CSS instead of <blink> / 2: OK, continue" msg set
90 o1 set 94 o2 set 10 goto
"You get in an airplane and go to fly through a cloud, but unfortunately, the cloud is taking a walk!" ending get goto
"You flutter over to a nearby cloud and say, 'Hi, Cloudy! Can I fly through you?' / Cloudy looks affirmative in a cloudy sort of way, and you fly through!" ending get goto
"Fine, the page <style>i {animation-duration: 1s;animation-name: blink;animation-iteration-count: 3;animation-timing-function: step-ending;}@keyframes blink {from {opacity: 1;}50% {opacity: 0;}to {opacity: 1;}}</style>ed its <i>s" ending get goto
"Then the user closed the tab and the page died" ending get goto
" / END" concat input "I said, 'END' / The story's over!" input ending get 3 + goto
- ChocolatePi
-
Scratcher
1000+ posts
Stack programming language
necro-Very cool!Very necro!
combining form
prefix: necro-
relating to a corpse or death.
“necromancy”
- ev3coolexit987654
-
Scratcher
1000+ posts
Stack programming language
@Zatnic made a:O PERFECTshort choose your own adventure type thing:98 ending set
"***THE STACK STORY***" print
"By someone awesome" print
23 goto
o1 o2 msg get " / Enter option number:" concat input "1" = if pop get goto
"Hi, This is ***THE STACK STORY*** / 1: Do something / 2: Stack is cool" msg set
34 o1 set 45 o2 set 10 goto
"You go do something; what do you do? / 1: Fly through a cloud! / 2: Read a story" msg set
56 o1 set 23 o2 set 10 goto
"Well, this is a story about HTML!!! / 1: Realistic HTML / 2: Unrealistic HTML" msg set
67 o1 set 71 o2 set 10 goto
"OK, how do you fly? / 1: In an airplane / 2: Duh, I'm a fairy; I fly with my wings" msg set
82 o1 set 86 o2 set 10 goto
"HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages --Wikipedia" ending get goto
"An HTML page woke up, and <blink>ed its <i>s / 1: Use CSS instead of <blink> / 2: OK, continue" msg set
90 o1 set 94 o2 set 10 goto
"You get in an airplane and go to fly through a cloud, but unfortunately, the cloud is taking a walk!" ending get goto
"You flutter over to a nearby cloud and say, 'Hi, Cloudy! Can I fly through you?' / Cloudy looks affirmative in a cloudy sort of way, and you fly through!" ending get goto
"Fine, the page <style>i {animation-duration: 1s;animation-name: blink;animation-iteration-count: 3;animation-timing-function: step-ending;}@keyframes blink {from {opacity: 1;}50% {opacity: 0;}to {opacity: 1;}}</style>ed its <i>s" ending get goto
"Then the user closed the tab and the page died" ending get goto
" / END" concat input "I said, 'END' / The story's over!" input ending get 3 + goto
- Jonathan50
-
Scratcher
1000+ posts
Stack programming language
Necromancer is a character from J.R.R Tolkein's The Hobbit.necro-Very cool!Very necro!
combining form
prefix: necro-
relating to a corpse or death.
“necromancy”
Necroposting is then posting on a ‘dead’ topic where the discussion has ended, not an old topic.
- liam48D
-
Scratcher
1000+ posts
Stack programming language
i am senseiNecromancer is a character from J.R.R Tolkein's The Hobbit.necro-Very cool!Very necro!
combining form
prefix: necro-
relating to a corpse or death.
“necromancy”
Necroposting is then posting on a ‘dead’ topic where the discussion has ended, not an old topic.
- WooHooBoy
-
Scratcher
1000+ posts
Stack programming language
This is pretty great! I'd like to see comments added, and XOR and binary ops and stuff.
Will you consider making this is a different language other that Scratch?
Will you consider making this is a different language other that Scratch?
- gtoal
-
Scratcher
1000+ posts
Stack programming language
This is pretty great! I'd like to see comments added, and XOR and binary ops and stuff.
Will you consider making this is a different language other that Scratch?
Just download an implementation of forth…
- BookOwl
-
Scratcher
1000+ posts
Stack programming language
Thanks to everybody who has complimented this! It means a lot! 

Once I finish and have a free afternoon, I will put this up on Github and you guys can try it out.

This is pretty great! I'd like to see comments added, and XOR and binary ops and stuff.I am actually porting Stack to Python right now! I am adding several new features, including:
Will you consider making this is a different language other that Scratch?
- Better control flow tools. Now more half working if statements or gotos!
- User-defined functions! YAY!!!

- Better boolean Ops
- And more!

Once I finish and have a free afternoon, I will put this up on Github and you guys can try it out.
- WooHooBoy
-
Scratcher
1000+ posts
Stack programming language
Thanks to everybody who has complimented this! It means a lot!I actually started my won Python port too :pThis is pretty great! I'd like to see comments added, and XOR and binary ops and stuff.I am actually porting Stack to Python right now! I am adding several new features, including:
Will you consider making this is a different language other that Scratch?I still need to add a few things, like lists and comments. I'll add binary operators to the list.
- Better control flow tools. Now more half working if statements or gotos!
- User-defined functions! YAY!!!
- Better boolean Ops
- And more!
Once I finish and have a free afternoon, I will put this up on Github and you guys can try it out.
- BookOwl
-
Scratcher
1000+ posts
Stack programming language
Stack 2.0 Status Update!
I have completed a working prototype compiler/interpreter for Stack 2.0. I still need to add some more built-in functions, but it should be done soon!
Here are some example programs and their output:
Here is another, more complicated example:
I have completed a working prototype compiler/interpreter for Stack 2.0. I still need to add some more built-in functions, but it should be done soon!
Here are some example programs and their output:
HelloWorld.stackThe output (User input is italic):'Hello, World!' print
'Nice to meet you, '
'Who are you? ' input
concat
Hello, World!Please note that my name is not Bob!
Who are you? Bob
Nice to meet you, Bob
Here is another, more complicated example:
factorial.stackThe output:'Factorial Calculater' print
{ 'Enter a number ' input num n set
{ dup 1 = not { dup 1 - fact call * } if } fact def
n get fact call
'The factorial of' print n get print 'is' print print prog call } prog def
prog call
Factorial CalculaterBoth of these programs actually run in the prototype interpreter.
Enter a number 5
The factorial of
5.0
is
120.0
Enter a number 20
The factorial of
20.0
is
2.43290200817664e+18
Enter a number done
<program exits>
- Discussion Forums
- » Advanced Topics
-
» Stack programming language