jang

A experimental scripting engine made in haxe.
https://github.com/JonkIsKindaCool/Jang

To install, run:

haxelib install jang 1.3.1 

See using Haxelib in Haxelib documentation for more information.

README.md

Jang

Jang is a small interpreted programming language written in Haxe, designed for learning language implementation, scripting, and experimentation. It features a hand-written lexer, parser, AST walker, runtime interpreter, and a growing standard library.

The language focuses on clarity, simplicity, and explicit runtime behavior rather than heavy abstractions.


✨ Features

  • Interpreted, AST-walker based execution
  • Static-like type annotations (checked at runtime)
  • Custom standard library (STD)
  • Clear error reporting with source locations
  • Written entirely in Haxe (multi-target friendly)

🧠 Language Overview

Variables

let x = 10;
const y = 5;

Optional type annotations:

let count: int = 3;
let name: string = "Jang";

Types

Built-in types:

  • int
  • float
  • string
  • boolean
  • array
  • object
  • any
  • callable

Example:

let nums: array = [1, 2, 3];
let user: object = { name: "Alex", age: 16 };

Functions

Functions are first-class values and support closures.

func add(a: int, b: int): int {
    return a + b;
}

print(add(2, 3));

Anonymous functions:

let mul = func(a, b) {
    return a * b;
};

Control Flow

If / Else

if (x > 10) {
    print("big");
} else {
    print("small");
}

While Loop

let i = 0;

while (i < 5) {
    print(i);
    i += 1;
}

Supports break and continue.


Arrays

let arr = [1, 2, 3];
print(arr[0]);

arr[1] = 10;

Arrays support index access through runtime methods.


Objects

let obj = {
    name: "Jang",
    version: 1
};

print(obj.name);
obj.version = 2;

Objects are dynamic key–value maps.


Classes and new

Primitive types are backed by classes in the STD:

let s = new String("hello");
print(s.length);

You can create a new class using the class keyword! (duh)

//src/entity.jn
class Entity {
    let xPos: float = 0;
    let yPos: float = 0;

    public func new (x: float, y: float){
        xPos = x;
        yPos = y;
    }

    public func getPos(): array {
        return [xPos, yPos]
    }
}

class Person extends Entity{
    let name: string = "template";

    public func new(x: float, name: string){
        super(x, 0);
        this.name = name;

    }

    public func getName(): string {
        return name
    }

    public func setName(n: string) {
        this.name = n
    }

    public func getPos(): array {
        let val: array = super.getPos()
        val[0] += 70;
        return val
    }
}

//main.js
import {Person} from "scripts.person";

let guy: Person = new Person(111, "Joao");
print(guy.getName())

guy.setName("Pong")

print(guy.getName())
print(guy.getPos())

➕ Operators

Supported operators:

Arithmetic

  • + - * / %

Comparison

  • == != < <= > >=

Logical

  • && ||

Assignment

  • = += -= *= /=
  • ++ -- (postfix)

Operator behavior is type-aware and validated at runtime.


📦 Standard Library (STD)

Available globally:

IO

IO.print("Hello");
IO.println("World");

print("Shortcut println");

Math

print(Math.PI);

(Designed to be expanded with more math functions.)


String

let s = new String("hello world");

print(s.length);
print(s.split(" "));
print(s.toString());

Int

let n = new Int(10);
print(n.toString());
print(n.toBool());

Array

let a = new Array([1, 2, 3]);
print(a.toString());

Supports index access and mutation.


Object

let o = new Object();
o.name = "Jang";
print(o.toString());

⚙️ Runtime Architecture

  • Lexer → Tokenizes source code
  • Parser → Produces an AST (Expr)
  • Interpreter → Walks AST and executes nodes
  • Scope → Lexical scoping with closures
  • JangValue → Unified runtime value system
  • JangClass / JangInstance → Custom classes / instances

The interpreter is fully deterministic and explicit—no hidden magic.


❌ Error Handling

Jang provides structured runtime and syntax errors with:

  • Source code reference
  • Line and position info
  • Error type (SYNTAX_ERROR, RUNTIME_ERROR)
  • Optional hints

🎯 Project Goals

  • Learn how real interpreters work
  • Keep the language small but expressive
  • Avoid unnecessary complexity
  • Make behavior explicit and debuggable
  • Grow the STD organically

🚧 Status

Jang is actively evolving.

Contributors
JonkIsKindaCool
Version
1.3.1
Published
10 months ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂