2025-08-09 20:33:08 +10:00
## Ground Syntax Guide
2025-08-11 08:57:45 +10:00
## General syntax
2025-08-09 20:33:08 +10:00
Ground uses simple instructions and arguments to run code.
```
instruction arg1 arg2 arg3
```
As an example:
```
stdout "Hello, World!"
```
Reference a variable's value (a value reference) with a dollar sign:
```
stdout $myVar
```
Reference a variable itself (a direct reference) with an and sign:
```
stdin & myVar
```
Reference a line (a line reference) with a percent symbol before a line number:
```
jump %10
```
2025-08-10 15:42:52 +10:00
Alternatively, set a label:
```
2025-08-10 16:08:56 +10:00
@myLabel # The '@' symbol denotes setting a label
2025-08-10 15:42:52 +10:00
```
and jump to that (setting labels will be discussed below):
2025-08-10 13:31:28 +10:00
```
jump %myLabel
```
Reference a list (a list reference) with an asterisk:
```
setlist *myList $value1 $value2 # and so on
```
2025-08-21 11:05:32 +10:00
Add comments with a `#` :
```
# This is a comment
```
2025-08-11 08:57:45 +10:00
## Keywords
2025-08-09 20:33:08 +10:00
Note: & var can be replaced with any direct reference. $value can be replaced with a literal value or a value reference. %1 can be replaced with a line reference.
Note: In most of these functions, if a direct reference is used, the value outputted by that function will be avaliable at that variable. Any existing value inside that variable will be overwritten.
2025-08-11 08:57:45 +10:00
### Control Flow
2025-08-09 20:33:08 +10:00
#### if
Make a decision based on a boolean. If the boolean is true, jumps to the line referenced.
Usage: `if $value %1`
#### jump
Jumps to the line referenced.
Usage: `jump %1`
#### end
Ends the program. Requires an integer for a status code.
2025-08-10 13:31:28 +10:00
Usage: `end $intvalue`
2025-08-09 20:33:08 +10:00
2025-08-11 08:57:45 +10:00
### I/O
2025-08-09 20:33:08 +10:00
#### stdin
Allows input from the console.
Usage: `stdin &var`
#### stdout
Allows output to the console.
Usage: `stdout $value`
#### stdlnout
Allows output to the console, appending a new line at the end.
Usage: `stdlnout $value`
2025-08-11 08:57:45 +10:00
### Variables and Lists
2025-08-09 20:33:08 +10:00
#### set
Allows you to set a variable to a value.
Usage: `set &var $value`
2025-08-10 13:31:28 +10:00
#### setlist
Allows you to initialize a list.
Usage: `setlist *list $value1 $value2 $value3...`
2025-08-11 08:57:45 +10:00
#### setlistat
2025-08-10 13:31:28 +10:00
Sets a list item at an index. The item at the index must already exist. Lists are index 0.
Usage: `setlistat *list $intvalue $value`
#### getlistat
Gets a list item at an index, and puts it in the variable provided. The item at the index must already exist. Lists are index 0.
Usage: `getlistat *list $intvalue &var`
#### getlistsize
Gets the size of a list and puts it in the variable provided.
Usage: `getlistsize *list &var`
2025-08-11 08:57:45 +10:00
#### listappend
Appends an item to a list.
Usage: `listappend *list $var`
2025-08-11 10:07:05 +10:00
### String Operations
2025-08-11 08:57:45 +10:00
#### getstrsize
Gets the size of a string and puts it in the variable provided.
Usage: `getstrsize $stringvalue &var`
#### getstrcharat
Gets a character at a certain position in a string and saves it to a variable.
Usage: `getstrcharat $stringvalue $intvalue &var`
### Maths
2025-08-09 20:33:08 +10:00
#### add
Adds two numbers. Numbers mean an integer or a double. Outputs to a direct reference.
Usage: `add $value $value &var`
#### subtract
Subtracts two numbers. Numbers mean an integer or a double. Outputs to a direct reference.
Usage: `subtract $value $value &var`
#### multiply
Multiplies two numbers. Numbers mean an integer or a double. Outputs to a direct reference.
Usage: `multiply $value $value &var`
#### divide
Divides two numbers. Numbers mean an integer or a double. Outputs to a direct reference.
Usage: `divide $value $value &var`
2025-08-11 08:57:45 +10:00
### Comparisons
2025-08-09 20:33:08 +10:00
#### equal
Checks if two values are equal. Outputs a boolean to a direct reference.
Usage: `equal $value $value &var`
#### inequal
Checks if two values are not equal. Outputs a boolean to a direct reference.
Usage: `inequal $value $value &var`
2025-08-21 11:05:32 +10:00
#### not
Negates a boolean.
Usage: `not $value &var`
2025-08-09 20:33:08 +10:00
#### greater
Checks if the left value is greater than the right value. Outputs a boolean to a direct reference.
Usage: `greater $value $value &var`
#### lesser
Checks if the left value is lesser than the right value. Outputs a boolean to a direct reference.
2025-08-10 13:31:28 +10:00
Usage: `lesser $value $value &var`
2025-08-11 08:57:45 +10:00
2025-08-11 14:12:25 +10:00
### Type Conversions
2025-08-11 08:57:45 +10:00
#### stoi
Converts a string to an integer. Throws an error if the string cannot be turned into an integer.
Usage: `stoi $stringvalue &var`
#### stod
Converts a string to a double. Throws an error if the string cannot be turned into a double.
Usage: `stod $stringvalue &var`
#### tostring
Converts any type to a string.
Usage: `tostring $value &var`
2025-08-25 13:51:22 +10:00
### Functions and function specific features (Experimental, please report bugs!)
2025-08-11 08:57:45 +10:00
Some symbols specific to this category:
* `!function` : A function reference
* `-type` : A type reference. Can be one of the following: "-string", "-char", "-int", "-double", "-bool"
#### fun
Defines a function. All code between `fun` and `endfun` will be included in the function.
2025-08-11 14:57:45 +10:00
Usage: `fun -type !functionname -type &var -type &var -type &var # and so on...`
2025-08-15 11:35:58 +10:00
Usage note: The first type specified before the function name must be the return type. The type displayed before all vars shows what type that variable must be.
2025-08-11 14:57:45 +10:00
#### return
Returns back to the main program (or other function that called this function). Also returns a value, which must be of the type defined when defining the function.
Usage: `return $value`
2025-08-11 08:57:45 +10:00
#### endfun
Ends a function definition. When a function reaches the end the argument list will be cleared.
Usage: `endfun`
#### pusharg
Adds a value to the argument list which will be passed to the function when it is called.
Usage: `pusharg $value`
#### call
2025-08-11 10:07:05 +10:00
Calls a function, with all the arguments in the argument list. The return value will be put in the specified variable.
2025-08-11 08:57:45 +10:00
2025-08-11 10:07:05 +10:00
Usage: `call !function & var
2025-08-25 13:51:22 +10:00
### Interacting with Libraries
2025-08-11 10:07:05 +10:00
2025-08-25 13:51:22 +10:00
#### use (Experimental, please report bugs!)
2025-08-11 10:07:05 +10:00
Attempts to import another Ground program. Gets inserted wherever the use statement is. Any code (including code outside function declarations) will be executed.
2025-08-25 13:51:22 +10:00
Note: Ground will check the directory where the program is being run from when trying to find imported programs. If that fails, it will check the directory set in the $GROUND_LIBS environment variable set by your system. The '.grnd' extension is appended automatically.
2025-08-11 10:07:05 +10:00
Usage: `use $stringvalue`
2025-08-25 13:51:22 +10:00
#### extern (WORK IN PROGRESS)
2025-08-11 10:07:05 +10:00
Attempts to import a shared object library written for Ground. All functions in the external library will be usable with `call` .
2025-08-25 13:51:22 +10:00
Note: Ground will check the directory where the program is being run from when trying to find external programs. If that fails, it will check the directory set in the $GROUND_LIBS environment variable set by your system. The '.so', '.dll', etc extension is appended automatically.
2025-08-11 10:07:05 +10:00
2025-08-21 11:05:32 +10:00
Usage: `extern $stringvalue`