-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the Abs wiki!
This is a short reference of Abs language.
Data types
There are only 3 data types: 1. Strings. For example, "Hello world" or "Hello\r\nWorld" 2. Integer numbers, for example: 10 3. Float numbers, for example, 10.0
There are no other types and there is no object-oriented programming support.
To set a variable use set(x,10) To get value of a variable simply use x
All functions have the following format: add(argument,1,argument2) For example, add(2,3) will add 2 and 3 and returns 5.
To execute several commands in sequence simply separate the commands my space chars or new lines, for example: print("Addition of two numbers") print(add(2,3),"\r\n") print("End of test")
Comments are only possible with # char.
How to use Abs?
Abacre Script may execute file given as argument, for example: abs.exe test1.abs Or it may run in interactive mode. For this purpose start Abacre Script: abs.exe Then you will see the prompt: abs> It's possible to execute any commands, for example, abs>set(x,"hello") print(x) To exit interactive mode use exit command like this: abs>exit On Linux the first line of script's file may be: #!/usr/local/bin/abs In this way it's possible to start script files the same way as Python or Perl files - simply by running it from the shell, for example: >test.abs On Windows you may use MSYS2 or Cygwin and there it's also possible to start script files using the similar way. Custom functions
Right now Abs supports 118 built-in functions but it’s also possible to implement custom functions.
It’s possible to define custom functions and even call it with recursion. For example, fun(myadd,a,b, add(a,b) ) Then call it as a usual function: myadd(2,2)
The complete function reference
Math functions
add(number,number,…) - add two or more numbers. mult(number,number,…) - multiply two or more numbers. sub(number,number) - sub two numbers. div(number,number) - integer division. mod(number,number) - reminder of division. inc(variable) - increment variable by one. dec(variable) - decrement variable by one. max(number,number) - max of two numbers. min(number,number) - min of two numbers.
Functions on variables
set(name,value) - set/assign a value to variable. get(variablename) - get value of variable. unset(variablename) - unset a variable. fun(funname,param1,param2,...,body) - declare a new function. var(varname,varvalue) - declare a local variable. Conditions
False is defined as 0. Thus anything that is not 0 is considered as True. Logical conditions like or() return 1 in case of True and 0 in case of False.
eq(string/number,string/number) - compare if two parameters are equal. and(param1, param2, …) - logical AND on two or more parameters. or(param1, param2, …) - logical OR on two or more parameters. not(param) noteq(param1, param2) - not equal. less(param1, param2) lesseq(param1, param2) gr(param1, param2) greq(param1, param2) if(condition,action-true,action-false) switch(value,case1,action1,case2,action2,…,def-action)
Loops
while(condition,body) do(body,condition) Input/output functions
print(argument1,argument2,…) - print the arguments to console. printf(format,argument) - print formatted argument. input(prompt) cmd(command1,command2) - execute commands in a sequence. exit(integer) - exit program with status sys(command) - execute system’s shell command. puts(string1,string2,…) - print to internal string buffer.
Functions on strings
cat(string1,string2) - concatenate strings append(s,s1,s2,s3...) – append to string s several strings. len(string1) - returns length of a string. pos - find position of given substring in a string. copy(string,index,count) - copy part of a string. erase(s,position,count) - delete/remove part of a string. the function does not modify s variable. it returns the result as a string where is needed substring is removed. insert - insert substring into string. replace() - replace all occurrences of substring in given string. treplace(template,searchfor,replacewith) - replace all occurrences of searchfor with replacewith and return number of replacements made. upper(string) - returns upper case string. lower(string) - return lowercase string. tok(string,sep) - get token. rtok - get token in reverse sense (from the end of the string). trim(string) - trim to from right and left. trimleft(string) - trim space chars from left only. trimright(string) - trim space chars from right only. format(formatstring,argument) Functions on lists ---------------------------------------------------------------------- list listsize listget listset listappend listremove listinsert listcreate listcopy System functions
run(string) - run command from system shell. env(string) - get environment variable. argc() - get arguments count. argv(i) - get i’th argument. the the first argument is zero. include(filename) - include file. includeonce(filename) - include file only once. eval(string) - evaluate string.
Advanced math and trigonometry functions
pow(number,number) sqrt(number) - returns square root of a number. sqr(number) - returns square of a number. sign() - get sign of a number. abs(number) - absolute of a number. round(number) floor(number) ceil(number) trunc(number) frac(number) - returns fractional part of a number. sin(number) cos(number) tan(number) asin(number) acos(number) atan(number) sinh(number) cosh(number) tanh(number) asinh(number) acosh(number) atanh(number) exp(number) log(number) log10(number) char() rand - returns a random number. pi() - returns Pi number. e() - return E number. Conversion functions
str(number) - convert argument to string. int(string) - convert argument to integer. float(string) - convert argument to float.
Functions on files
fileexists(filename) - check if the file is exists. fileread(filename) - read whole file and return file's body. filewrite(filename,filebody) - write filebody to file. fileappend(filename,filebody) - append filebody to file. Date/time functions
now() - returns a date as a Unix time. strdate date year month day hour minute second week dayofweek dayofyear difftime isleapyear daysinyear daysinmonth