A compiler for the simple programming language that I've been working on.
I wanted to learn about compilers and ended up reading Crafting Interpreters and writing this compiler and a virtual machine.
It supports
- ints, booleans
- strings
- addition, multiplication, division, subtraction, concatenation
- logical operations
- local and global variables
- if, if-else, while loops
- functions
- build-in functions:
input
,readLine
,int
,fact
- objects and
object()
function - linked lists with normal API
- closures
To run Jex code you need to run
- Download JexCompiler-<version>.jar from the latest release
- Run
java -jar JexCompiler-<version>.jar path/to/code.txt path/to/output.bytecode
- Run
path/to/output.bytecode
with jex_vm.
WARNING: Be very careful with newline characters, the parser is not finished yet 😎.
1 + 2 * 5 - (10 / 2);
true && false;
true || false;
"a" + "b";
var globalVariable = 1;
{
var localVariable = 2;
}
var readFromTerminal = readLine();
println("Hello World");
var readInt = int(readLine());
if (readInt == null) {
println("Failed to parse int");
} else {
println("Success");
}
var name = readLine();
if (name == "Emir") {
println("Hehe");
} else {
println("Hey");
}
if (name == "emir") {
println("You should capitalize your name, emir");
}
while(true) {
println("Working");
}
fn greet(name) {
println("Hello, " + name);
}
println("Whats your name?");
greet(readLine());
Functions are just regular values
var a = println;
println(a);
Firstly, you have to create an empty object and then add some properties.
var person = object();
person.name = "Emir";
println(person.name);
Linked list example.
You can find some examples of Jex code in the resources directory.