Skip to content

Commit

Permalink
Documentation update (arrays) (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonovk authored Jan 31, 2024
1 parent 3f01a66 commit 01110c9
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
47 changes: 46 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

Minicode executes the code line by line, first compiling it into a certain set of commands. Which makes it a classic interpreted programming language. Each line of code in minicode begins with a command, followed by an expression.

At the moment, the minicode has 9 commands and 2 data types, integers and strings.
At the moment, the minicode has 11 commands and 3 data types, integers, strings and arrays.
Integers behave exactly the same as in Lua. If you don't use decimal characters they will be integers, otherwise not integers. In any case, both will be stored in memory as non-integers.

Minicode is a Turing complete language and in theory allows you to implement any function.

| command | description |
|----------|----------|
| > | Assigns a value to the specified variable. Meaning, if the value can be parsed into an integer, it will do so. |
| [] | Initializing an empty array |
| []< | Add a new element to the end of the array |
| p | Displays the value from the specified variable |
| f | Tries to find a file at the specified path, and puts all its contents into the specified variable |
| $> | Asks the user for a value, if it can be represented as an integer, it will be represented as such |
Expand All @@ -20,6 +22,7 @@ Minicode is a Turing complete language and in theory allows you to implement any
| >> | Write data to file |
| & | Run operating system command |
| -> | Include code file |
| -_- | Stop the code thread |

Each line begins with one of these commands and is separated from the expressions by a space.

Expand Down Expand Up @@ -67,6 +70,48 @@ Here the variable b will contain the string - "e"
> b a 1
```

You can also select elements from an array.

Arrays are created as follows:

```mc
# here in variable 'a' we initialize an empty array.
[] a
# here we put a new value at the end of the array.
[]< a 43
```

An example of how to fill an array with characters from the word 'hello'

```mc
# First we fill the array
[] a
> empty_line
> word hello
> i 0
> char word i
[]< a char
= i + 1
? char ! empty_line 7
# Then we select the necessary elements from it and put them in variables
# and print to the screen
> h a 0
> e a 1
> l a 2
> ll a 3
> o a 4
p h
p e
p l
p ll
p o
```

In such cases, the value of other variables can also act as an index. If nothing is found at the address of the variable 'a', then a new line will simply be created - "a 1".

## Console output
Expand Down
47 changes: 46 additions & 1 deletion docs/ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

Миникод выполняет код построчно, предварительно компилируя его в некий набор команд. Что делает его классическим интерпретируемым языком программирования. Каждая строка кода в миникоде начинается с команды, затем идет выражение.

На данный момент в миникоде есть 9 команд и 2 типа данных, целые числа и строки.
На данный момент в миникоде есть 12 команд и 3 типа данных, целые числа, строки и массивы.
Целые числа видут себя точно также как в Lua. Если вы не используете символы после запятой, они будут целыми, в противном случае не целыми. В любом случае и те и другие в памяти будут храниться как не целые.

Миникод является тьюринг полным языком и в теории позволяет реализовать любую функцию.

| команда | описание |
|----------|----------|
| > | Создание новой переменной |
| [] | Инициализация пустого массива |
| []< | Добавить новый элемент в конец массива |
| p | Вывести на экран содержимое переменной |
| f | Чтение из файла и запись его содержимого в переменную |
| $> | Запросить значение у пользователя |
Expand All @@ -18,6 +20,7 @@
| >> | Записать данные в файл |
| & | Выполнить команду ОС |
| -> | Подключить файл с кодом |
| -_- | Остановить поток выполнения кода |

Каждая строка начинается с одной из эти команд и отделяется от выражений пробелом.

Expand Down Expand Up @@ -65,6 +68,48 @@
> b a 1
```

Также можно выбирать элементы из массива.

Создаются массивы следующим образом:

```mc
# тут в переменной а инициалиризуем пустой массив.
[] a
# тут кладем в конец массива новое значение
[]< a 43
```

Пример, как заполнить массив символами из слова 'hello'

```mc
# Сначало заполняем массив
[] a
> empty_line
> word hello
> i 0
> char word i
[]< a char
= i + 1
? char ! empty_line 7
# Затем выбираем из него нужные элементы, кладем их в переменные
# и печатаем на экран
> h a 0
> e a 1
> l a 2
> ll a 3
> o a 4
p h
p e
p l
p ll
p o
```

В качестве индекса в таких случаях также может выступать значение других переменных. Если по адресу переменной 'a' ничего не будет найдено, то будет просто создана новая строка - "a 1".

## Вывод значений в консоль
Expand Down

0 comments on commit 01110c9

Please sign in to comment.