Skip to content

Commit

Permalink
fixed a couple of bugs, added code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Centrix14 committed Jan 1, 2020
1 parent ce5b3b4 commit 20c3430
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 10 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
+ `^` -- go to the item with the number (`^123` - now 123 is the current work item)
+ `>` / `<` -- move right / left in the array (`>>` - move the current work item pointer 2 items forward)
+ `_!` -- display the value of the current item (`:123(_!)` - displays the value of element 123 on the screen)
+ `~` -- a comment that continues until the next language command (`~ comment`)
+ `~ (text)` -- a comment whose text is placed in brackets (`~ (comment)`)
+ `|` -- fills the array from the current position with elements (`|6 8 2` - the numbers 6, 8, 2 will be added to the array)
+ `-!` -- displays the values of all array elements (`^0|6 8 12(-!)` - displays 6, 8, 12 if the array was initially empty)
+ `;` -- reports that the data entered is a number (`;:12` - writes 12 to the currently selected element, and reports that it is a number)
Expand All @@ -30,13 +30,13 @@
+ `!-` -- copies the inverted value from the current work item to the selected one (`:123(!-)2` - now element 2 stores 0)
+ `&` -- returns the conjunction of all array elements in element 2047 (`|1 2 3&` - in element 2047, 1 will be returned)
+ `\` -- returns the disjunction of all array elements in element 2047 (`|1 2 0\` - in element 2047, 1 will be returned)
+ `?~` -- predicative execution tool, if the result of the previous operation is true, then all subsequent commands will be executed, if it is not, then all subsequent operations will be skipped, analogous to "if" in other languages (`|1 2 3+(?~)^0|(true)@(-!)` - will display "true", since 1+2+3 not equal to 0)
+ `?!` -- inverts the result of the previous operation, similar to else in other languages (`|0 0 0+(?~)^0|(true)@(-!)(?!)|(false)@(-!)` - will output "false" as 0+0+0 early 0)
+ `?~` -- predicative execution tool, if the result of the previous operation is true, then all subsequent commands will be executed, if it is not, then all subsequent operations will be skipped, analogous to `if` in other languages (`|1 2 3+(?~)^0|(true)@(-!)` - will display "true", because 1+2+3 not equal to 0)
+ `?!` -- inverts the result of the previous operation, similar to `else` in other languages (`|0 0 0+(?~)^0|(true)@(-!)(?!)|(false)@(-!)` - will output "false" as 0+0+0 early 0)
+ `|~` -- iterator, performs some action on all elements of the array (`(|~)(_! )` - displays the values of all elements of the array, in fact analog ( -!), it is important that operations that must be performed iteratively are enclosed in brackets and end with a space)
+ `<->` -- exchanges values between the current work item and the selected one (`^2047(<->)2` - the values of elements 2047 and 2 will be reversed)

## Some remarks
+ some commands must be surrounded by parentheses, as follows: `(_!)`, `(-!)`, `(:-)`, `(!-)`, `(?~)`, `(?!)`, `(|~)`, `(<->)
+ some commands must be surrounded by parentheses, as follows: `(_!)`, `(-!)`, `(:-)`, `(!-)`, `(?~)`, `(?!)`, `(|~)`, `(<->)`
+ specifically for saol, I wrote a preprocessor called ssp (standard SAOL preprocessor), it runs separately from the main interpreter, and has the following features:
+ `.link <file_1> <file_2> ... <file_n>` -- connecting third-party files
+ `.macro <name> <expr>` -- creates a macro named name, the next time it is encountered, expr will be substituted for it
Expand All @@ -53,7 +53,17 @@

### Important notes
+ Macro names in the program must be surrounded by spaces
```
.macro foo bar
.prog
^ foo : bar
```
+ If the macro value contains spaces, use `{} `to combine expressions. Thanks to this, you can write a macro that will generate another macro.
```
.macro gen {.macro foo bar}
.prog
gen
```
## Installation and use
### Installation
Expand All @@ -73,7 +83,7 @@ to install, you will need:
### use
```
./saol my_programm.saol // for simple interpretation
./ssp my_programm.saol out.saol // for preprocessing my_programm.saol in out.saol
./saol my_programm.spf // for simple interpretation
./ssp my_programm.spf out.saol // for preprocessing my_programm.saol in out.saol
./isi // to call an interactive interpreter
```
6 changes: 2 additions & 4 deletions arr_lib.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Saol interpreter library v1.0 31/12/2019 by Centrix */
/* Saol interpreter library v1.2 31/12/2019 by Centrix */

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -97,10 +97,8 @@ void mult(char *arg) {

void idiv(char *arg) {
for (int i = start; i < end; i++) {
if (arr[i]) {
if (arr[i])
arr[MAX-1] /= arr[i];
puts("div");
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions examples/01_hello_world.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
~ (this is a comment)
~ (programm 'hello_world')

@|(Hello, World!)(-!) ~ (the `@` character indicates that the data being operated on is a character)
~ (the `|` character sequentially fills the array with characters in parentheses)
~ (command `-!` displays the contents of the array on the screen)
6 changes: 6 additions & 0 deletions examples/02_navigation.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
~ (saol is focused on array processing, so it has tools for navigating arrays)

:123 ~ (initially, the array element pointer is set to 0 element, so this string initializes the 0 cell with the value 123)
>:456 ~ (command `>` moves the pointer 1 forward)
< ~ (similarly, the command ` > ' moves the pointer back 1)
^45 ~ (the ` ^ ' command sets the pointer to a specific position, here in cell 45)
7 changes: 7 additions & 0 deletions examples/03_output.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
~ (here we will look at displaying values on the screen)
~ (only values from the array are displayed)
~ (for example let's display the following text: "The answer is: 42")

|(The answer is: 42) ~ (first, enter the text in the array using `|`)
@ ~ (now we will specify that it is necessary to output the text, but not the number)
(-!) ~ (actually output the values from the array)
6 changes: 6 additions & 0 deletions examples/04_math.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
~ (let's study the application of mathematics in saol, for this we calculate the value of the expression (2+5*6-4)/7)
~ (in saol, all mathematical operations have equal execution priority, so we will calculate (5*6+2-4)/7)

;:5^2047:6[0]1* ~ (in the zero element we write 5, and in the 2047 element we write 6, because all the numbers are added / subtracted / multiplied and divided by the value of the 2047 element)
^0:2+:4' ~ (write 2 in the zero cell produce addition, write 4 in the zero cell, subtract)
:7/^2047(_!) ~ (the result is divided by 7 and printed on the screen)
5 changes: 5 additions & 0 deletions examples/05_intervals.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ (in past lessons, you may have noticed constructions like `[0]2`, so let's talk about them)
~ (initially, the commands are applied to all 2048 elements of the array, but to limit the range of action, a construction of the form is used: [<from>]<to>)
~ (for example)

@|abcdefg [0]3 (-!) ~ (displays characters from 0 to 3)
5 changes: 5 additions & 0 deletions examples/06_fill.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~ (sometimes you need to fill an array, or part of it, with the same characters / numbers, using the `#`command)
~ (for example)

[0]3 @ #Q (-!) ~ (filling elements from 0 to 3 with `Q ' characters, output to the screen)
; #6 (-!) ~ (filling the same gap with numbers 6)
6 changes: 6 additions & 0 deletions examples/07_assigment.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
~ (if you want to copy a value from one cell to another, use the commands `:-` & `!-`)
~ (for example)

:789 (:-) 1 > (_!) ~ (copy the value 789 from the 0th element to the 1st element)
^3:10@(_!)^1; ~ (jump to a new line)
< (!-) 2 >> (_!) ~ (copying the inverted value 789 from element 0 to element 2)
6 changes: 6 additions & 0 deletions examples/08_logic.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
~ (in saol, logical operations are also available, namely, & - AND, \ - OR)
~ (for example)

|1 0 [0]2 & ^2047 (_!) ~ (calculating the conjunction 1 and 0)
^3:10@(_!);^2047 ~ (jump to a new line)
\ (_!) ~ (calculating disjunction 1 and 0)
8 changes: 8 additions & 0 deletions examples/09_if_else.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
~ (branches based on predicative execution are available in saol)
~ (it works like this: if the result of the previous operation (that is, the condition) is not zero, then the subsequent operations are executed, but they will not be executed if the result is 0)
~ (for example)

:6 ^2047 :12 [0]1 ' ~ (condition 12 - 6)
(?~) ^0 [0]2048 |(true) @ (-!) ~ (after the command `?~` is the code that must be executed if the condition is true)
(?!) ^0 [0]2048 |(false) @ (-!) ~ (after the command `?!'this is the code that must be executed if the condition is false)
~ (in this case, the condition is true and `true` is output, but if you replace 6 with 12, the condition becomes false and `false`is output)
6 changes: 6 additions & 0 deletions examples/10_iterator.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
~ (the iterator allows you to run the same code for each element of an array or span)
~ (the iterator command looks like this: ( | ~ ) after it, in brackets is the code that will have to be executed for each element sequentially, but most importantly at the end, before closing the bracket, put a space!)
~ (for example)

@|(i am text!) ~ (write the string `i am text`to the array)
(|~)(_! ) ~ (iteratively display the characters on the screen, by the way this is the implementation of the command `-!`)
4 changes: 4 additions & 0 deletions examples/11_swap.spf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
~ (if you need to swap the values of 2 elements, use the command `<->`)
~ (for example)

:678 >> : 123 (<->) 0 (_!) << (_!) ~ (write 678 in the 0-th element, 123 in the 2-th and change their places)
1 change: 1 addition & 0 deletions ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int main(int argc, char *argv[]) {

fclose(src);
fclose(dst);

return 0;
}

Expand Down

0 comments on commit 20c3430

Please sign in to comment.