Written with StackEdit.
A bytecode interpreter and virtual machine for my Lua/Python-inspired programming language that targets custom-made bytecode. Implements a Pratt-styled Precedence parser, explicit types, control flow, and more, alongside bytecode IR generation from a source file. Written in C.
Taro is originally based on the Lox language specification and implementation of Bob Nystrom's "Crafting Interpreters", with intent to continue implementing my own desired features/tools within the taro language.
let name = "taro";
let age = 400;
// variable assignment with 'let' keyword
let Games = enum{
VALORANT,
TEKKEN,
SF6
};
let currentlyPlaying = Games::VALORANT;
// native support of enum types!
print "my name is " + name;
// print keyword. taro also features string concatenation
let drinks = ["tea", "coffee", "boba"];
print drinks;
// taro also features native list types and operations!
push(drinks, "lemonade");
let fav = drinks[3];
print "my name is " + name + " and i love " + fav;
if (fav is "lemonade") print "when life gives you lemons...";
else print "awkward..";
print fav == "lemonade";
// yes, we love lemonade :)
- Python style dictionaries
- String subscripting
- Unary negation for pure boolean arrays, similar to R
-[true, false] == [false, true]
- Rust-style array initialization
let a = [1..10];
- module system, possibly designing a package manager
- more native functions allowing access to system operations
- Rust-style match statements
Taro is designed to utilize the ease of readability of scripting languages similar to JavaScript, Lua, and Python while maintaining other traditional syntax considerations such as curly braces for scoping, and semicolons.
let cat = "meow";
let dog = "woof";
// string declarations
let pets = 3;
// number declaration
Similarly to its predecessor, taro utilizes floating point numbers to represent digital values.
let smol = 0.01;
let big = 1000;
// numbers are internally stored as floats, and support decimal numbers.
let bigMinus = -big;
// numeric negation is also supported
let name = "taro";
// string declaration
let name = name + " is my name!";
// string concatenation is supported
let a = "a";
let b = "b";
print a == b;
// string equality comparison is also included natively
let books = ["chainsaw man", "berserk", "one piece"];
let nums = [1, 2, 3];
let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
// storage of lists within lists allows for matrix structures
print matrix[2][2];
let mix = [1, "1"];
// lists allow for multiple types to be stored in the same list
let Genres = enum {
ROCK,
INDIE,
CLASSICAL
};
// native enum structures allow for custom data types and pattern matching!
let mostPlayed = Genres::ROCK;
let a = 123;
{
let a = 321;
print a;
// outputs 321. variable shadowing is allowed here!
}
print a;
let Games = enum {
MELEE,
MARIOKART,
BG3
};
let name = "Shravan";
let bloodthirsty = true;
let sleepy = true;
// boolean values take on values of either [true, false, nil]
let favorite;
// you can also instantiate a variable without declaring a value
if (name is "Shravan" and bloodthirsty is true) {
// you can use python style `is` for equality, or good old `==`
favorite = Games::MELEE;
}
else if (name is "Mark" or sleepy is false) {
favorite = Games::MARIOKART;
}
else {
favorite = Games::BG3;
}
let count = 0;
let homies = [];
while (count < 10) {
count = count + 1;
push(homies, count);
print count;
}
// the usual C-style while loops
count = 0;
while (count < 10) {
print homies[count];
count = count + 1;
}
print homies;
let nums = [];
for (let i = 0; i < 10; i = i + 1) {
push(nums, i);
}
print nums;
let a = [
[951, 626, 909],
[323, 301, 805],
[505, 999, 911]
];
for (let i = 0; i < 3; i = i + 1) {
for (let j = 0; j < 3; j = j + 1) {
print a[j][i];
// column wise iteration
}
}
print a;
let first = 0;
let second = 1;
let length = 7;
let count = 0;
let fibs = [];
while (count < length) {
push(fibs, first);
let temp = second;
print first + second;
second = first + second;
first = temp;
count = count + 1;
}
print fibs;
let res = [];
for (let i = 1; i < 20; i = i + 1) {
if (i % 3 == 0 and i % 5 == 0) push(res, "fizzbuzz");
else if (i % 3 == 0) push(res, "fizz");
else if (i % 5 == 0) push(res, "buzz");
else push(res, i);
}
print res;