Interpreter for Splax, A dynamic programming language I made while learning how compilers and interpreters work.
Splax supports text files with spx
file extension.
example: main.spx
A simple hello world program in splax:
print "Hello, World!";
Semi-colons at the end of every line is mandatory in Splax.
Splax has following datatypes
These can number literals which can be both integers and floating point numbers.
examples: 1
, 2.5
, 9
These are string literals defined inside "
examples: "Splax"
, "Strings are easy"
These are boolean literals which can be either true
or false
.
examples: true
, false
Splax has nulls, the trillion dollar mistale. It can be defined using the null
keyword. All uninitialized variables are given the value of null
.
examples: null
Splax has following operators:
=
- equals
-
- Unary negation
and
- logical AND
or
- logical OR
!
- logical NOT
+
- sum
-
- difference
*
- product
/
- division
%
- mod
==
- is equals
!=
- is not equals
>
- is less than
>=
- is less than or equals
>
- is greater than
>=
- is greater than or equals
Splax has only one type of comment, single line comments, which can be defined using //
at the beginning of a line.
// This is a comment.
// The Lexer completely ignores any line starting with //
// The Whole line is ignored.
Splax has variables which can be defined using the let
keyword without defining any data type, splax can automatically detect datatype at runtime.
syntax:
let variable_name;
let variable_name = initial_value;
example:
let a; // default value is null if nothing is assigned.
let b = 2; // numbers: both integers
let c = 2.5; // and floats
let d = "Strings are easy"; // strings
let e = true; // booleans
Splax variables have scope like any other modern programming language (the term modern
here can be understood as the same as modern in modern chess
)
let a = 1;
{
let a = 2;
print a; // 2
}
print a; // 1
Splax has if
else
conditionals. It can be defined using the following syntax:
if (condition) {
// todo
} else {
// else todo
}
example:
let a = 1;
if (a == 1) {
print "A is infact 1";
} else {
print "A is not 1";
}
while loops in splax can be defined using the following syntax:
while (condition) {
// todo
}
example:
let a = 10;
while (a > 1) {
print a;
a = a - 1;
}
Splax has syntactic sugar for for
loops.
syntax:
for(initialiser; condition; incrementer) {
// todo
}
example:
for(let i = 0; i < 10; i = i + 1) {
print i;
}
Splax have user defined functions, and ability to call them.
A function in splax can be defined using the following syntax:
fn function_name(parameters) {
// todo
}
example:
fn greet(name) {
print "Hello " + name;
}
A function can be called using the following syntax:
function_name(parameters);
example
greet("Splax");
splax run main.spx
splax repl
splax
A learning programming language.
Usage: splax <COMMAND>
Commands:
repl Interactive repl
run Run from a file
docs See docs
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-
Clone the repo and make sure you have installed rust compiler and cargo. Here's the official installation guide.
-
Build using cargo.
cargo build --release
You can test the interpreter on example present in /examples folder