Mamba is a simple dynamic typed programming language. Thanks to maldoinc for a great code base to start with and modify!
Sadly, he's no longer working on it, so I made this fork and will continue updating it.
I am working on this right now and there are lots of features to add, e.g. modules and limitation on loops and HTTP operations or modules.
- Python 3.x
- ply
Install Mamba using pip3 install git+https://github.com/Gelbpunkt/mamba-lang
.
It ships with a command line tool to execute files, the recommended ending is .mb
.
mamba my-script.mb
The tool features -h
for help and -l
or --limited
for a safe mode that limits memory usage, execution time and I/O.
-v (--verbose)
toggles the verbose mode and it will send the AST.
--version
will show the mamba version.
- Variables
- Functions
- Flow control statements
- Loops (for in, for, inf loop, while)
- Loop exit statement
- Compound operators
- Pythonic sequence (array, string) slicing
- Integer
- Float
- String
- Boolean
- Arrays
Variables are dynamically typed, and immediately declared. The syntax is foo = "bar";
Logic: and
or
not
in
not in
>
>=
<
<=
==
!=
Arithmetic: +
-
*
/
**
Binary: ~
^
|
&
>>
<<
Ternary: test ? true_value : false_value
Doing nothing can be accomplished by leaving it simply out.
function do_nothing() {
}
Functions are declared via the following grammar:
function func_name( [<arguments>,] ){
< statements >
}
function random(){
return 4;
}
The return value is specified with the return
keyword which, as expected, immediately halts function execution upon being called. Functions can have their private functions which are inaccessible to the outer scope.
Mamba supports if
statements for flow control via the following syntax
if < expression > {
< statements >
}
NB: Brackets are mandatory, while parentheses on the expression are optional.
Mamba supports for
and while
loops.
for syntax
for variable in sequence {
< statements >
}
NB: The sequence field accepts arrays and strings:
for variable in low -> high {
< statements >
}
Down to loops are constructed as:
for variable in high <- low {
< statements >
}
NB: Loop indexes are inclusive (0-3 is 0, 1, 2, and 3)
while syntax
while < expression > {
< statements >
}
There is also the alternative for
syntax:
for {
< statements >
}
Which acts as an infinite loop (internally expressed as a while true {}
statement).
All loops can be prematurely exited via the exit
statement when necessary
Arrays have dynamic length and can be declared via the [ ... ]
expression
Printing is supported via the say
keyword which accepts a list of values to print.
e
pi
argv
ask(prompt)
shows the prompt and returns the result as a stringint(x [, base])
float(x)
round(value, precision)
abs(x)
log(x)
rand
randrange(lo, hi)
randint(lo, hi)
range(lo, hi, inc)
behaves like the python 2.x range()sin(x)
cos(x)
tan(x)
atan(x)
str(x)
substr(str, start, length)
len(str)
pos(substr, str)
upper(str)
lower(str)
replace(str, find, replace)
format(string [, ... ])
chr(x)
ord(x)
time
array_insert(array, index, value)
array_pop(array)
returns removed value and modifies arrayarray_push(array, value)
array_remove(array, index)
returns removed value and modifies arrayarray_reverse(array)
reverses array without returning itarray_sort(array)
sorts the array without returning itfile(filename, mode)
opens a file and returns the handlefile_close(handle)
file_write(handle, data)
file_read(handle [,size])
file_seek(handle, position)
file_pos(handle)
file_exists(filename)