A stack-based bytecode compiled programming language implemented in Go.
- Stack-based bytecode compilation
- Dynamic typing with optional type annotations
- Functions with default parameters
- Control flow constructs (if/else, while, for-in loops)
- Built-in data structures (lists and tables)
- Basic module system
# Variables and types
name = "Alice"
age = 25
scores = [95, 87, 92]
person = { name = "Bob", age = 30 }
# Functions
function greet(name, title = "Hello") {
return title + ", " + name + "!"
}
print(greet("Alice"))
function check_grade(score) {
if score >= 90 {
return "A"
} else if score >= 80 {
return "B"
} else {
return "C"
}
}
# While loop with break/continue
count = 0
while count < 10 {
count += 1
if count % 2 == 0 {
continue
}
print("Odd:", count)
}
# Process a list of students
students = [
{ name = "Alice", grade = 85 },
{ name = "Bob", grade = 92 },
{ name = "Charlie", grade = 78 }
]
function calculate_class_average(student_list) {
total = 0
for student in student_list {
total += student.grade
}
return total / len(student_list)
}
average = calculate_class_average(students)
print("Class average:", average)
function factorial(n) {
if n <= 1 {
return 1
}
return n * factorial(n - 1)
}
function fibonacci(n) {
if n <= 1 {
return n
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
print("5! =", factorial(5))
print("fib(8) =", fibonacci(8))
function calculate_area(radius: number) -> number {
return 3.14159 * radius ^^ 2
}
function format_name(first: string, last: string) -> string {
return first + " " + last
}
- Numbers (integers and floats)
- Strings (single, double, or triple-quoted)
- Booleans (
true
,false
) - Lists (
[1, 2, 3]
) - Tables/Maps (
{ key = value }
) nil
(null value)
- Arithmetic:
+
,-
,*
,/
,//
(integer division),%
,^^
(power) - Comparison:
==
,!=
,<
,<=
,>
,>=
- Logical:
and
,or
,not
- Assignment:
=
,+=
,-=
,*=
,/=
,^^=
if
/else
statementswhile
loopsfor
/in
loopsbreak
andcontinue
return
statements
The compiler pipeline is:
- Lexing with ANTLR4
- Parsing to AST
- Symbol table construction for scoping and parameters
- Bytecode generation for a stack-based opcodesz
- Execution on a custom virtual machine
# Run a program
./inscript program.ins