hasanbly basic scripting language
current version 1.5
[version 0.0, made on 05.10.2022]
if you want developing this project you can compile like this:
g++ main.cpp -o hsnc -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread
You can get it with the command
git clone https://github.com/HasanEfeAksoy/hasanbly.git
Or get it as zip. Download hsnc.exe and create your .hsn file. (main.hsn)
Run with
hsnc main.hsncommand.
(note: Example main.hsn file may be do not run on MacOS and Linux. Please delete file and create again.)
Hasanbly is open source, not used parser basic scripting language.
Created with C++.
First, you may want to print Hello, World! to the console 🙃
<<Hello, World!;
EXIT;
------------------------------------------------------
-
Comment line. The // operator only makes one line completely uninterpretable. So it cannot be used on a used line.
// This is comment line
// These lines will be ignored by the interpreter.
EXIT;
output:
-
Ends the program. At the end of the program, you have to put EXIT command otherwise the program does not run.
<Bye;
EXIT;
<Bye;
EXIT;
output: Bye
-
Create a new variable and assign the entered value to the value of the variable. You have to define int or string or double (int-str-dbl).
[Camel case variables are preferred]
DEF:str:name=empty;
<<$:str:name_;
DEF:int:number=15;
<<$:int:number_;
DEF:dbl:myDouble=4.5;
<<$:dbl:myDouble_;
EXIT;
output: empty
15
4.500000 -
Prints the written values to the console.
<Hello;
EXIT;
output: Hello
-
Prints the written values to the console with next line.
<<Hello;
EXIT;
output: Hello
-
Assigns the entered value to the value of the written variable.
DEF:str:text=noname;
// entered 'hasanbly'
>$:str:text_;
<<$:str:text_;
EXIT;
output: hasanbly
-
You can using math operators like = + - * / %, trigonometric processes ex.(M.SIN $:dbl:myNum1_ $:dbl:myNum2_;) [note : just for radians double variables], M.ABS, M.POW, M.SQRT, M.ROUND, etc.
But you have to using variables. You can convert type of variables with use M= command.
DEF:int:first=0;
DEF:int:second=1;
// $:int:first_ = $:int:second_
M= $:int:first_ $:int:second_;
<<$:int:first_;
EXIT;
output: 1
-
Going to line. You can using with line number or line number variable value.
<Hi;
GOTO 1;
// or
//DEF:int:line:2;
//<Hi;
//GOTO $:int:line_;
EXIT;
output: HiHiHiHiHiHiHiHiHiHiHiHiHiHiHiHiHiHi........
-
Like box office checkpoint. If true: can pass, else: go to a line.
You have to use == != << >> <= >= and must use variable (not pure values) and use ELSE:<pure number>
IMPORTANT: you have to string-string or int-int or double-double when using == or !=. but if using << >> <= >= you have to input parameters just int-int/double or double-double/int.
DEF:int:num1=0;
DEF:int:num2=0;
// if 0 == 0
// it returns true. so the interpreter does not go to line 8. it does not anything right now.
// but if you put != the interpreter goes to line 8.
IF== $:int:num1_ $:int:num2_ ELSE:8;
<<Hello everyone;
EXIT;
output: Hello everyone
-
Increase the variable. You can use for int and double.
DEF:int:number=0;
<<$:int:number_;
INC $:int:number_;
<<$:int:number_;
EXIT;
output: 0
1 -
Decrease the variable. You can use for int and double.
DEF:int:number=1;
<<$:int:number_;
DEC $:int:number_;
<<$:int:number_;
EXIT;
output: 1
0 -
Set value of null to variable.
if variable is string, new value is ''. (nothing)
if variable is int, new value is 0.
if variable is double, new value is 0.0.
DEF:int:number=1;
<<$:int:number_;
NULL $:int:number_;
<<$:int:number_;
EXIT;
output: 1
0 -
Delete the variable and set value of memory to null.
DEF:int:myAwasomeNumber=5;
<<$:int:myAwesomeNumber_;
FREE $:int:myAwesomeNumber_;
<<$:int:myAwesomeNumber_;
EXIT;
output: 5
ERROR -
Copy n'th index of first parameter and set value to second parameter. Just using with strings
DEF:str:name=hasanbly;
DEF:str:myIndex=nullForNow;
<<$:str:myIndex_;
INDEX[2] $:str:name_ $:str:myIndex;
<<$:str:myIndex_;
EXIT;
output: nullForNow
s -
Sleep main process. Just one parameter and it can be pure integer number or integer variable. Time type is millisecond.
DEF:str:name=hasanbly;
SLEEP 1000;
// sleeping 1000 millisecond (1 second)
<<$:str:name_;
EXIT;
output: hasanbly
-
Random integer number generator. Have to using integer variables. 3 parameter (destination, min, max)
DEF:int:dest=0;
DEF:int:min=3;
DEF:int:max=8;
// random int number between 3-8 (3,4,5,6,7,8)
RAND $:int:dest_ $:int:min_ $:int:max_;
<<$:int:dest_;
EXIT;
output: 6
-
Returns string's length. Have to using 2 (str, int) variables. 2 parameters are (source, destination)
DEF:str:text=hello;
DEF:int:length=0;
STRLEN $:str:text_ $:int:length_;
<<$:int:length_;
EXIT;
output: 5
-
Takes no parameters and clears the console.
<<^$^$Hello World!^$^$;
CLEAR;
<<^$^$Hello World!^$^$;
EXIT;
output: $$Hello World!$$
-
Assigns your current OS name to a string variable.
DEF:str:myOSname=;
OSNAME $:str:myOSname_;
<<$:str:myOSname_;
EXIT;
output: Windows
-
Copy all of second parameter and change n'th index of first parameter. Just using with strings
DEF:str:name=hasanbly;
DEF:str:newWord=HAHAHA;
<<$:str:name_;
REPLACE[3] $:str:name_ $:str:newWord_;
<<$:str:name_;
EXIT;
output: hasanbly
hasHAHAHAnbly -
Runs bash and batch codes. Just one parameter and it can be string variable. But be carefull because you may get some errors and program will stop if you write wrong command.
// example for Windows
DEF:str:myAwesomeCommand=dir;
// example for UNIX types
// DEF:str:myAwesomeCommand=ls;
TERMINAL $:str:myAwesomeCommand_;
EXIT;
output: [< your current folder contents >]
-
Returns current time. Just one parameter and it can be integer variable. There is 3 commands of TIME (.SECONDS .MINUTES .HOURS).
DEF:int:time=0;
TIME.MINUTES $:int:time_;
<<$:int:time_;
EXIT;
output: 26
-
Clamp value from first and second parameters to last 2 parameters range. Need 5 parameters and have to be double variables. 1) value 2) first min range 3) first max range 4) second min range 5) second max range.
DEF:dbl:value=2;
DEF:dbl:a=0;
DEF:dbl:b=10;
DEF:dbl:c=0;
DEF:dbl:d=100;
CLAMP $:dbl:value_ $:dbl:a_ $:dbl:b_ $:dbl:c_ $:dbl:d_;
<<$:dbl:value_;
EXIT;
output: 20