Tox is a small programming language that has been inspired by the Jlox programming language from https://craftinginterpreters.com/
The scanner, parser & interpreter have all been built by hand, no external library has been involved
- Clone this project
- Run
npm install
andnpm run build
- Open a new terminal and run
node lib/tox.js file test.tox
to run a file (test.tox
is in the root) - To run the repl run
node lib/tox.js repl
The syntax is similar to Javascript for the most part.
let number = 12;
let name = "hundred";
for(let i = 0; i < 5; i = i + 1) {
log i;
}
let num = 0
while(num < 5) {
log "Running";
num = num + 1;
}
fn greetings(name) {
return "Hello " + name;
}
log greetings("World");
let answer = "work";
if(answer == "work") {
log "correct";
} else {
log "try again";
}
log nil or "twelve"; // prints "twelve"
I took inspiration from the do expression
that's currently an Ecmascript expression
let a = 12;
do {
if(a == 111) {
log("true");
} else {
log("false"); //logs false here
}
}