owned this note
owned this note
Published
Linked with GitHub
# Nairb
A Brainfuck derivate.
## Regular Commands
There are 7 commands that have a numeric argument.
|Command|Action |
|:-----:|:----------|
|`+` |Add _x_ to current cell.
|`-` |Decrement by _x_ current cell.
|`=` |Set current cell's value to _x_.
|`<` |Move the pointer _x_ steps to the left.
|`>` |Move the pointer _x_ steps to the right.
|`.` |Print _x_ (ASCII value)
|`:` |Print _x_ (Numeric value)
So `:5` will print 5.
Anyway, the numeric argument is optional. In `+`, `-`, `<` and `>` the default is 1, so they'll work like BF. In `=` default argument value is 0. In `.` it's current cell value.
:::success
**Examples:**
`+++` = [3]
`++>+` = [2, 1]
`+3=+6` = [6]
`+>5+++` = [1, 0, 0, 0, 0, 3]
`.72` = H
`+++++=` = [0]
:::
These numeric values are expressions, we'll see them later.
There's also a command that doesn't have a numeric argument: `,`. This makes user input and stores it in the current cell.
:::warning
**Tip:** `'` is commonly referred as the current cell value.
**Tip 2:** Use `/this/` syntax to make comments.
:::
----
### Regular commands
|Command|Action |Default _x_ value
|:-----:|:----------|---------------
|`+` |Add _x_ to current cell.|`1`
|`-` |Decrease by _x_ current cell.|`1`
|`=` |Set current cell's value to _x_.|`0`
|`<` |Move the pointer _x_ steps to the left.|`1`
|`>` |Move the pointer _x_ steps to the right.|`1`
|`.` |Print _x_ as a ASCII character|`'`
|`:` |Print _x_ as a numeric value.|`'`
|`,` |Set current cell to user's input.|<small>None</small>
## Variables
You can make a variable using the `&` command.
```
&"(name)"(value)
```
If name is only one character, you can discard the quotes.
```
&a2 /set a to 2/
```
You can let a variable's value be the current cell's value like this:
```
&a /set a to '/
```
Use a variable putting its name instead of the number.
```
$a5 /set a to 5/
+3 /add 3 to current cell/
+a /add a to current cell/
: /print current cell/
/This will print 8 (5+3)/
```
Put the quotes if necessary, too.
```
&"variable" > ="variable":
```
## Expressions
When doing `+5`, `5` is an expression.
As we recently seen, variables are available too in expressions (`+a`).
But there are more things you can do with expressions.
### Variables
Write variable's names with quotes to get them.
> `&"hello"5 :"hello"` = 5[color=green]
Quotes are unnecessary if variable's name has only one character.
> `&a5 :a` = 5[color=green]
Final quotes are explicit in expressions.
> `&"hello"a :"hello` = 5[color=green]
### Special variables
There are more variables to use. These are called special variables.
The `'` variable means the current cell's value.
You can multiply by 2 with this.
>`+25 +' :` = 50 [color=green]
The `#` variable means (zero-indexed) the position of the pointer.
>`>6 <1 :#` = 5 [color=green]
### Negating numbers
You can negate numbers preceding them with `_`.
> [color=green]`+_5:` = -5
This also works for variables:
> [color=green] `&a5 :_a` = -5
> [color=green] `+9 :_'` = -9
### Add values directly
You can add values directly putting them in the same expression.
> [color=green] `&2a :a3` = 5
You can mix negating and adding to make subtraction:
> [color=green] `:7_2` = (7 + -2) 5
## Conditionals
Conditionals are used in if (`()`) and while (`[]`) commands. We'll see them now.
_if_ runs commands if a condition is true.
_while_ runs command until a condition is not true.
### Syntax of _if_
Imagine you want to print "89" if variable _a_ is equal to 89. You have to use an if command. The syntax is:
(<exp1><operator><exp2><commands>)
* **Exp1** = The first number to compare.
* **Operator** = The operator. It can be `<`, `>`, `=`, `!`, `+`, `-`.
* Operators will be more detailedly explained later.
* **Exp2** = The second number to compare.
* **Commands** = The commands to execute if comparation is true.
So, to do that, you'll have to do:
(a=89 /conditional/
:89 /commands/
)
<small>Which is the same as `(a=89:89)`</small>
### Operators
|Operator|Action
|:------:|:-----
|`=` |_x_ equal to _y_
|`!` |_x_ not equal to _y_
|`<` |_x_ less than _y_
|`+` |_x_ equal or greater than _y_
|`>` |_x_ more than _y_
|`-` |_x_ equal or less than _y_
### Default arguments
First expression default argument is `'`.
Second expression default argument is `0`.
So, if you do `(= :5)` it will be the same as `('=0 :5)`.
### Optional else
You can add an else to an _if_ command with `;;`.
('=0 .110.111 ;; :')
<small>Print "no" if `'` is 0, print the number else.</small>
### Syntax of _while_
There's also a while command. It's the same as _if_ command but with brackets (`[]`) instead.
## Repetition
The last command is the repetition command. It works like this:
{<exp><commands>}
* **Exp:** times to repeat _\<commands\>_. (default: 2)
* **Commands:** Commands.
::: success
Examples:
`{3:1}` = 111
`{3 +:}` = 123
`{.72}` = HH
:::
## Hello World
.72.101{.108}.111.44.32.87.111.114.108.100.33