-
Notifications
You must be signed in to change notification settings - Fork 0
Syntax
And other stuff, like examples.
A literal pushes that literal value to the stack. Simple.
A digit followed by 0 or more digits (0-9), optionally preceded by a negative sign (-).
1
3
-2
A digit followed by 0 or more digits (0-9), followed by a period (.), followed by 1 or more digits (0-9), optionally preceded by a negative sign (-).
1.0
-2.9
3.1415927
A double-quote (") followed by text, followed by another double-quote ("). Don't forget to end it!
"this is a string"
"also a string"
"third example text"
true (true) or false (false). Capitalization matters.
true
false
To store state, or something.
Makes the variable usable. Undeclared variables throw a runtime error if anything else is done with them.
A variable name (not a keyword or a literal, can include _ ) followed by two periods (..). Capitalization still matters.
var..
other_variable..
example_text..
Makes the variable not usable, as if it had not been declared.
A variable name (not a keyword or a literal, can include _ ) followed by two tildes (~~). Capitalization still matters. The language you're writing in hasn't changed.
var~~
other_variable~~
example_text~~
Pops the top value of the stack and stores the value in the variable for later use. Make sure to declare the variable before doing this!
-> followed by a variable name.
->var
->other_variable
->example_text
Pushes the value stored in the variable onto the stack. Make sure to assign something to the variable before doing this!
<- followed by a variable name.
<-var
<-other_variable
<-example_text
A special type of variable declaration that makes a loop from low number to high number by increment of one. Stores the current value in the declared variable.
Expression resulting in the high number; Expression resulting in the low number; var..; do
<code>
loop
-
5 0 i.. do <code> loop
loops from i=0 to i=4, running<code>
5 times. -
0 10 i.. do <code> loop
doesn't loop. high value first, running<code>
no times. -
10 5 i.. do <code> loop
loops from i=5 to i=9, running<code>
5 times.
More cool stuff, like recursion.
Loops while a statement grouping results in true on the top of the stack.
while <while loop condition>
do
<code>
loop
-
while true do <code> loop
runs forever. true is a literal. -
while false do <code> loop
doesn't run. false isn't true. -
while 0 0 eq do <code> loop
runs forever because 0 is always equal to 0. This example is just to demonstrate multiple statements in the condition.
Ends the main program definition or the previous function definition and starts defining the new function.
: followed by a valid identifier.
:foo
:bar
Calls a function.
@ followed by a valid identifier. Make sure to actually define it though!
@foo
@bar
Conditionally runs code.
bool value on stack; if;
<code>
else
<code>
endif
<val> if "value is true" else "value is false" endif println