An Expression Language (AXL) is an expression based programming language that can be used for scripting.
Everything in AXL (except for the instructions for input and output) returns a value of some sort, meaning that all of the different operations (which are themselves expressions) can be concatenated.
ListsFile reading/writingmodules- Embedding inside other languages
Anything enclosed bewteen ( and ) is treated as an expression.
An expression can return either an integer, a floating point number (both integers and floats can be either positive or negative), a boolean, a string, a list or a function and returns the last value inserted.
For example the following expression will return 2:
( 1 2 )
It is important to notice that an empty expression (e.g. ()) will return nothing as there isn't nothing to return.
AXL provides a series of operations (which are by definition expressions too) to perform arithmetic or boolean operations, written in polish notation:
add <expr1> <expr2>: returns the addition between two expressionssub <expr1> <expr2>: returns the subtraction between the first and the second expressionmul <expr1> <expr2>: returns the multiplication between two expressionsdiv <expr1> <expr2>: returns the division between the first and the second expressionmod <expr1> <expr2>: returns the modulo between the first and the second expressionpow <expr1> <expr2>: returns the result of the first expression to the power of the second expressionand <expr1> <expr2>: returnstrueif both the expressions return trueor <expr1> <expr2>: returnstrueif either one of the two expressions return truenot <expr1>: returns the opposite boolean of whatever boolean the expression returnseq <expr1> <expr2>: returnstrueif the two expressions return the same resultneq <expr1> <expr2>: returnstrueif the two expression don't return the same resultgt <expr1> <expr2>: returnstrueif the first expression is greater than the secondlt <expr1> <expr2>: returnstrueif the first expression is less than the secondgte <expr1> <expr2>: returnstrueif the first expression is greater than or equals to the secondlte <expr1> <expr2>: returnstrueif the first expression is less than or equal to the second
Branching can be performed through the if, loop and times expressions.
These can either return a value conditionally or iterate the same expression, either a determined or undetermined amouunt of times.
if <cond> <expr>: returns a value if the condition returns trueelse <expr>: returns a value if the previous condition is falsetimes <n_iterations> <expr>: returns a value a definite amount of timesloop <expr>: returns indefinately a value; the loop can be broke with thebreakexpression.
A variable is a scoped region of memory that stores a value.
A variable can be defined/redefined with the set expression, which requires an identifier and an expression or a function:
set <id> <expr | function>
You can print to the standard output a value with the puts keyword (e.g. puts 3) or get user input with the gets keyword (which could be actually an expression as it returns a value, but since it deals with I/O it technically isn't, but it can be used as the value of a variable):
puts <expr>
gets
You can also read from files using the readf expression, which returns a list containing all the lines of the file as strings:
readf <string path to file>
In a similar way you can also overwrite the contents of the file with writef and appendf that, like puts, aren't expressions:
writef <string path to file> <string to write>
appendf <string path to file> <string to write>
Functions can be defined as follows:
fn ( ... )
Functions can take arguments, which can be taken by using the arg expression; then they get substituted with the positional arguments you pass in your function.
To demonstrate how a function works, here's a quick example:
set foo fn(
set a arg
set b arg
add a b
)
puts (foo 1 1)
Here the function foo takes in two arguments that are stored in the variables a and b.
Then we return the result of the sum of the two variables, which in this case is 2.
Normally a function returns the last expression it's written inside, but you can explicitally tell the function to return with the
return expression.
To call a function, wrap in parethesis the name of the variable binded to that function along with any possible argument:
(<function name> <optional args>)
Any text enclosed between " is treated as a string literal.
You can concatenate strings with the concat expression, which returns a string:
concat <string_1> <string_2>
Lists are a data structure that can contain any number of expressions.
Strings are considered as a list of characters, therefore all the operations related to lists are also valid for strings
We can define a list with the list keyword:
list(...)
When defining a list be sure to separate each element in the list with a whitespace:
set nums list(1 2 3 4)
It is possible to manipulate and operate with lists with the following operations:
len <list>: returns the length of the given listelement <list> <num>: given a list and a number index, returns the value stored at that index.concat <list> <list>: it is possible to useconcatalso to concatenate two stringsmap <function> <list>: applies a given function to each element of a given list
It's possible to convert a value to another type using these expressions:
tostr <expr>: converts a given expression to a stringtonum <expr>: converts a given expression to a numbertolist <expr>: converts a given expression to a list
One can import other AXL files using the import expression, which returns the content of the file and evaluates them accordingly:
import <string path to an other AXL file>
