Add 'Reference'

~karx 2021-04-07 22:49:33 +00:00
parent 7ca2ec622b
commit 4b52f7b5b8
1 changed files with 47 additions and 0 deletions

47
Reference.md Normal file

@ -0,0 +1,47 @@
This is the reference for sandwich's language features.
# Opcodes
`sandwich` is comprised of *opcodes*. The syntax looks like this:
```
oArguments
```
The currently available opcodes are as follows:
- `p` - print out the arguments
- `pHello World!` will print out `Hello World!`.
- `a`, `s`, `m`, `d` - add, subtract, multiply, and divide, respectively
- the arguments look like the following:
- `<num1>-<num2>`
- For example: `a10-10` will print out `20`.
- the dash in the middle is a separator between the two input numbers.
- These opcodes will error out if either of the arguments is not a number.
- `l` - declare a variable
- `<variable name><variable value>`
- the name of the variable must be only 1 character
- the value can be any length.
- if the first character of the value is a `<`, sandwich will grab input from the user, using everything after the `<` as a prompt.
- For example, if your code says `ln<Enter your name: `, sandwich will prompt the user with `Enter your name: ` and wait for the user to input.
- Then, it will assign the inputted text to the variable `n`.
- Note:
- To use a variable, use the $ character.
- For example, `p$v` will print out the value of variable `v`.
- If `w` is set to `World`, `pHello, $w!` will print out `Hello, World!`
- Two variables cannot share the same name. If you try to redeclare a variable, the old value will be overwritten.
- `f` - declare a function
- The arguments are the same as declaring a variable.
- the body of the function has to be one of the math operators.
- Note:
- To use a variable, use the * character.
- For example, `p*f` will print out the result of function `f`.
- Functions will only get evaluated *when they're called*.
- This means, if you use variable `v` in a function, but `v` gets redefined between the function declaration and when you use it, the function will use the *new* value of `v`, and not the value from when the function was defined.
- Also, functions are re-evaluated *for each call*.
- This means that if the function depend on an outside variable and the variable changes frequently, the result of the function will also change frequently.
- Like variables, two functions cannot share the same name. If you try to redeclare a function, the old function will get overwritten.
- `i` - import variables and functions from another file
- The arguments look like the following:
- `<filename>[-optional-list-of-functions-or-variables-to-import]`
- the list of values should be separated by a `-`. Each value should have the following syntax:
- `<f or v, function or variable, respectively><name of function/variable>`