Interprete programming language, working by Python
. Syntax similar to SQL
+ Assembler
All files with code written in this language have the extension .sai
.
Code in main.py
from compiler import Compiler
compiler = Compiler(
True, # True - is file path, False - is code witten on Saify
'main.sai' # file with our code written on Saify
# if you change first parameter to False then
# you can insert code written on Saify instead file path
)
compiler.run()
Code in main.sai
include "Lib/random.sai"
def print __Object
output __Object endl
enddef
print 'For help insert -> help'
set anchor1 __line__
input line 'Insert command -> '
set statement line
use statement
== 'help'
if statement goto 20
goto 27
output """Commands list:
help - commamds list
random - generate random number from 1 to 100
exit - close program
"""
goto anchor1
set statement line
== 'random'
if statement goto 33
goto 38
use line
randint 1 100
print line
goto anchor1
set statement line
== 'exit'
if statement goto 44
goto 46
exit 'Finishing -> Successful'
output 'Command \''
output line
output '\' is doesn\'t exists!' endl
goto anchor1
True
False
'Hello World!'
"Hello World!"
Also multiline string
'''Hello World!'''
"""Hello World!"""
123
123.4
...
None
Structure
set <name> <value>
Example
set variable 123
set variable 456
or
use variable
456
enduse
__line__
- get current line number
__file__
- get file path
__name__
- get compilation file name
endl
- '\n'
This construction allows you to interact with the value of a variable (only one variable can be interacted with at a time). Structure
use <variable>
<code>
enduse
Example
set val 1
use val
+ 1
* 2
** 2
- 4
/ 3
enduse
output val endl # output: 4
Operator | Description |
---|---|
+ |
Add |
- |
Minus |
** |
Exponentiation |
* |
Multiplication |
/ |
Division |
// |
Integer division |
% |
Mod |
== |
Equals |
!= |
Not equals |
< |
Less than |
> |
Greater than |
<= |
Less than or equal to |
>= |
Greater than or equal to |
and |
... |
or |
... |
not |
... |
in |
... |
is |
... |
Structure
def <name> <argument>*
<code>
enddef
Example
def print arg
output arg endl
enddef
or
def show arg1 arg2
output arg1 " " arg2 endl
enddef
Structure
<name> <argument>*
Example
print "Hello World!"
or
show "Hello" "World!" # Output: Hello World!
Structure
return <value>
Example
def add left right
use left
+ right
enduse
return left
enddef
set num 0
use num
add 1 1
enduse
output num endl # Output: 2
output
- print the specified values (structure output <value>*
(any number of arguments))
input
- enter a value from the keyboard (structure input <variable-name> <value (to print)>?
)
exit
- exiting the program with an indication of the reason (structure exit <value (reason)>?
)
eval
- execute the Saify
code passed as a string value (structure eval <value (Saify code)>
)
pyeval
- execute the Python
code passed as a string value (structure eval <value (Python code)>
)
Structure
if <value> <code>
Example
set val 2
use val
+ 2
== 4
if val output "2 + 2 = 4" endl
2
+ 2
== 5
if val output "2 + 2 = 5" endl
or
set name ''
input name 'What is your name? '
set statement False
use statement
!= ''
enduse
set IF __line__
use IF
+ 15
enduse
if statement goto IF
# ELSE
output "Hi!" endl
set ELSE __line__
use ELSE
+ 9
enduse
goto ELSE
# IF
output "Hi, " name " !" endl
# END
Allows you to connect modules written in Saify
or Python
.
Structure
include <str>
Example
include "Lib/math.sai"
This keyword allows the program to proceed to code execution, starting from the specified line. Structure
goto <value>
Example
goto 23
Allows you to delete variable. Structure
del <variable>
Example
set val 12
del val
output val endl # error
9 January 2021