2.9 KiB
Operation reference
This is a reference of all the possible operations in the Granite programming language. This may be useful for those who have read through both the guidebook and all the further concepts who just need a refresher or those who have read the syntax introduction and prefer to learn by reading references.
Set variable
Operation: :>(value),(variable)
Stores (value)
into (variable)
.
Increment
Operation: :^(variable)
Adds 1 to (variable)
if it is a number. Panics if not.
Decrement
Operation: :v(variable)
Removes 1 from (variable)
if it is a number. Panics if not.
Operation: :!(variable)
Outputs the value in (variable)
.
New label
Operation: :@(label)
Defines a new label at this location called (label)
.
Unconditional jump
Operation: :<(label)
Jumps to (label)
without any condition.
Jump if less than
Operation: :-(label),(variable),(check)
Jumps to (label)
if (variable)
is less than (check)
which can be an integer or a variable.
Jump if greater than
Operation: :+(label),(variable),(check)
Jumps to (label)
if (variable)
is greater than (check)
which can be an integer or a variable.
Jump if equal to
Operation: :=(label),(variable),(check)
Jumps to (label)
if (variable)
is equal to (check)
which can be an integer or a variable.
Arithmetic add
Operation: :a(left),(right),(output)
Performs (left) + (right)
and stores the result into (output)
Arithmetic subtract
Operation: :s(left),(right),(output)
Performs (left) - (right)
and stores the result into (output)
Arithmetic multiply
Operation: :m(left),(right),(output)
Performs (left) * (right)
and stores the result into (output)
Arithmetic divide
Operation: :d(left),(right),(output)
Performs (left) / (right)
and stores the result into (output)
Take input
Operation: :?(variable)
Prompts the user for input and stores it in (variable)
. If (variable)
is not initialised then prompt the user with a ?
prompt otherwise prompt the user with the value of (variable)
.
Comment
Operation: :0(comment)
Does nothing but leaves a useful comment for programmers.
String concatenation
Operation: :*(left),(right),(output)
Concatenates (left)
and (right)
into one string and places the result into (output)
.
Explicit exit
Operation: :~
Terminates the program at this point.
Type check
Operation: :&(variable),(output)
Sets (output)
to 1 if (variable)
is an integer, otherwise sets (output)
to 0.
Stack push
Operation: :#
Pushes the current location to the stack, allowing the programmer to return out of a subroutine.
Return
Operation: :|
Returns back to previously pushed location, panics if no location previously pushed.
Variable clone
Operation: :%(source),(target)
Stores the value of (source)
in (target)
.
Variable drop
Operation: :$(variable)
Deletes (variable)
, effectively un-initialising it.