Skip to content

Latest commit

 

History

73 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TSL — Small Language for JavaScript

TSL (Time Script Language) is a small, simple programming language that compiles to JavaScript. Designed for learning, game prototyping, and writing clean, readable code with minimal syntax.

Version: 1.0.0  |  Status: Stable  |  Backend: JavaScript  |  Website: tsl.timeandtime.online


Features

  • Simple syntax — colon (:) and indentation for blocks, no braces or keywords
  • Full compiler pipeline — Lexer → Parser → AST → Validator → Generator
  • JavaScript backend — generates clean, readable, valid JavaScript
  • Deterministic output — same source always produces the same JavaScript
  • Rich type support — numbers, strings, booleans, null, arrays, objects
  • Control flow — if/else, for, while, break, continue
  • Functions — declarations, parameters, return, recursion, closures
  • Error reporting — clear errors with filename, line, column, and source context
  • CLI tool — build, check, and run from the command line
  • 100+ examples — algorithms, data structures, and game patterns

Quick Start

Install

git clone https://github.com/TimeAndTimeStudio/TSL.git
cd TSL

No dependencies required. TSL runs on Node.js.

Compile a TSL file

node src/cli.js hello.tsl

Build to JavaScript

# Output to stdout
node src/cli.js build hello.tsl

# Write to file
node src/cli.js build hello.tsl -o hello.js

Run the generated JavaScript

node hello.js

CLI Commands

node src/cli.js <file.tsl>          # Compile and show generated JS
node src/cli.js build <file.tsl>    # Build to stdout
node src/cli.js build <file.tsl> -o <output.js>  # Build to file
node src/cli.js check <file.tsl>    # Validate only
node src/cli.js --version           # Show version

Example

# Fibonacci
function fib(n):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

for i in range(10):
    print(fib(i))

Compiles to:

function fib(n) {
  if (n <= 1) {
    return n;
  }
  return fib(n - 1) + fib(n - 2);
}

for (let i of range(10)) {
  console.log(fib(i));
}

Compiler Pipeline

TSL Source
    ↓
  Lexer        → Tokens
    ↓
  Parser       → AST
    ↓
  Validator    → Valid AST
    ↓
  Generator    → JavaScript
    ↓
  JavaScript   → Runtime

Documentation

Topic File
Project overview docs/en/README.md
Getting started docs/en/getting-started.md
Language reference docs/en/language.md
Syntax reference docs/en/syntax.md
Variables docs/en/variables.md
Data types docs/en/data-types.md
Operators docs/en/operators.md
Control flow docs/en/control-flow.md
Functions docs/en/functions.md
Arrays docs/en/arrays.md
Objects docs/en/objects.md
CLI docs/en/cli.md
Errors docs/en/errors.md
Compiler architecture docs/en/compiler.md
Project architecture docs/en/architecture.md
Examples docs/en/examples.md

Examples

Basic

Example Description
hello.tsl Hello World
variables.tsl Variables and assignment
math.tsl Arithmetic operations
if.tsl If statement
while.tsl While loop
for.tsl For loop
functions.tsl Function declaration
arrays.tsl Arrays
objects.tsl Objects

Algorithms

Example Description
fibonacci.tsl Recursive Fibonacci
bubble_sort.tsl Bubble sort
quick_sort.tsl Quick sort
merge_sort.tsl Merge sort
binary_search.tsl Binary search
factorial_loop.tsl Factorial
gcd.tsl Greatest common divisor
prime.tsl Prime check

Data Structures

Example Description
stack.tsl Stack
queue.tsl Queue
linked_list.tsl Linked list
binary_tree.tsl Binary tree
hash_table.tsl Hash table
graph.tsl Graph

Dynamic Programming

Example Description
knapsack.tsl 0/1 Knapsack
lcs.tsl Longest common subsequence
coin_change.tsl Coin change
edit_distance.tsl Edit distance
dijkstra.tsl Dijkstra's algorithm

Traversal

Example Description
dfs.tsl Depth-first search
bfs.tsl Breadth-first search

Tests

# Run all unit tests
npm test

# Run release test suite
cd release-test && node run-all-tests.js

Test results:

Suite Status
AST ✓ Pass
Lexer ✓ Pass
Parser (expressions + statements) ✓ Pass
Validator ✓ Pass
Generator ✓ Pass
Variable Semantics ✓ Pass
Integration ✓ Pass
CLI ✓ Pass

Project Structure

tsl/
├── src/
│   ├── cli.js        # Command-line interface
│   ├── compiler.js   # Main compiler orchestrator
│   ├── lexer.js      # Tokenizer
│   ├── parser.js     # Expression & statement parser
│   ├── ast.js        # AST node definitions
│   ├── validator.js  # Semantic validation
│   ├── generator.js  # JavaScript code generation
│   └── errors.js     # Error types
├── examples/         # 100+ TSL examples
├── tests/            # Unit & integration tests
│   ├── ast/
│   ├── cli/
│   ├── generator/
│   ├── integration/
│   ├── lexer/
│   ├── parser/
│   └── validator/
├── docs/             # Documentation
├── release-test/     # Standalone release verification
└── README.md         # This file

License

GPL-3.0

Releases

Packages

Contributors

Languages