code-lang

command module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 5 Imported by: 0

README ΒΆ

Code-Lang πŸš€

Code-Lang is a modern, interpreted programming language written in Go. It began as an implementation following the excellent book "Writing An Interpreter In Go" by Thorsten Ball, and has since evolved with additional features and custom extensions.

[!IMPORTANT] Status: Code-Lang is a passion project and is currently under active development. While the core language is functional, it is not production-ready. If you intend to use this in a production environment, significant work, security audits, and optimizations are required.


✨ Features

  • Rich Type System:
    • Integers and Floats
    • Strings and Characters
    • Booleans
    • Arrays (e.g., [1, 2, 3])
    • Hashes/Dictionaries (e.g., {"name": "Code-Lang"})
  • First-Class Functions: Function literals, closures, and higher-order functions.
  • Control Flow:
    • if-elseif-else expressions (everything is an expression!).
    • while loops for simple iteration.
    • for loops for structured iteration.
  • Support for Comments: Single-line (#) and multi-line (/* */).
  • Standard Operators:
    • Arithmetic: +, -, *, /, % (Modulo)
    • Advanced: ** (Power), // (Floor Division), = (Assignment)
    • Comparison: ==, !=, <, >, <=, >=
    • Logical: ! (Negation)
  • Built-in Functions: print, printf, typeof, len, push, and more.
  • Module System: Import other .cl files using import "module".
  • Member Access: Dot notation (obj.prop) for Hashes and Modules.
  • Compound Assignment: Supports +=, -=, *=, /=, etc.
  • REPL: Interactive shell with precise line/column error tracking.
  • File Execution: Run scripts with the .cl extension.

πŸš€ Getting Started

Prerequisites
  • Go (version 1.25.3 or higher recommended)
Installation

You can install the code-lang binary directly to your $GOPATH/bin:

go install github.com/walonCode/code-lang@latest
Option 2: Pre-built Binaries

Head over to the Releases section to download path-ready binaries for Windows, macOS, and Linux.

Option 3: From Source

Clone and build manually:

git clone https://github.com/walonCode/code-lang.git
cd code-lang
go build -o code-lang main.go
Running the REPL

Start the interactive shell by running:

go run main.go
Running a Script

You can execute a Code-Lang script by passing the filename as an argument:

go run main.go hello.cl

πŸ“– Language Syntax at a Glance

Variables & Functions
let age = 25;
let name = "Developer";
let isLearning = true;

let add = fn(a, b) {
    return a + b;
};

print(add(10, 15)); // Output: 25
Arrays and Indexing
let fibonacci = [0, 1, 1, 2, 3, 5, 8];


let person = {"name": "Alice", "age": 30};

Conditionals
let x = 10;
let result = if (x > 10) {
    "Greater"
} elseif (x == 10) {
    "Equal"
} else {
    "Smaller"
};
Loops
// While loop
let i = 0;
while (i < 5) {
    print(i);
    i = i + 1;
};

// For loop
for (let j = 0; j < 5; j += 1) {
    print(j);
};
Modules & Member Access
// math_lib.cl
let PI = 3.14159;
let square = fn(x) { x * x; };

// main.cl
import "math_lib";
print(math_lib.PI);
print(math_lib.square(10));

// Hashes
let user = {"name": "Thorsten", "active": true};
user.name = "Walon";
user.score = 100;
user.score += 50;
print(user.name); // Walon
print(user.score); // 150
Advanced Features
// Comments
# This is a single line comment
/* 
   This is a 
   multi-line comment 
*/

// Formatted print
let name = "Alice";
printf("Hello, %s!", name);

// Type checking
print(typeof(10)); // Output: INTEGER
print(typeof("hi")); // Output: STRING

πŸ—Ί Roadmap

We are constantly working to make Code-Lang better. Here is what's coming next:

  • Better Error Reporting: Line and column tracking for precise debugging.
  • Comments: Support for single and multi-line comments.
  • Loops: Implementing while and for loops.
  • Logical Operators: Adding && (AND) and || (OR) with short-circuiting.
  • Standard Library (Internal): Dedicated Go-backed modules for math, fs, and http.
  • Import System: Ability to include other .cl files.
  • Member Access: Dot notation for objects and modules.
  • Compound Assignment: Support for +=, -=, etc.

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ™ Acknowledgments

  • Thorsten Ball for the foundational guide Writing An Interpreter In Go.
  • The Go community for providing an incredible ecosystem for language development.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
std

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL