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.
🚀 Note: This project is actively evolving and will soon be moved to the Walon-Foundation!
- Rich Type System:
- Integers and Floats
- Strings and Characters
- Booleans
- Arrays (e.g.,
[1, 2, 3]) - Hashes/Dictionaries (e.g.,
{"name": "Code-Lang"}) - Structs: Custom data structures with default values and member access.
- First-Class Functions: Function literals, closures, and higher-order functions.
- Control Flow:
if-elseif-elseexpressions (everything is an expression!).whileloops for simple iteration.forloops for structured iteration.breakandcontinueinside loops.
- Static Analysis:
- Symbol Table: Tracks variable scopes, identifier resolution, and constant enforcement.
- Pre-execution Checks: Catches undefined variables and illegal reassignments before running code.
- Support for Comments: Single-line (
#) and multi-line (/* */). - Standard Operators:
- Arithmetic:
+,-,*,/,%(Modulo) - Advanced:
**(Power),//(Floor Division) - Comparison:
==,!=,<,>,<=,>= - Logical:
&&(AND),||(OR) — with short-circuit evaluation — and!(Negation) - Compound Assignment:
+=,-=,*=,/=,%=,**=,//=
- Arithmetic:
- Built-in Functions:
print,printf,typeof,len,push, and more. - Module System: Import other
.clfiles or built-in modules usingimport "module". - Member Access: Dot notation (
obj.prop) for Hashes, Modules, Structs, and Servers. - Networking: Built-in
httpclient (GET, POST, etc.) andnet.serverfor creating web servers. - JSON Support: Built-in
json.parse()andjson.stringify(). - Standard Library: Go-backed modules for
math,strings,time,hash,os,json, andnet. - REPL: Interactive shell with persistent history and precise line/column error tracking.
- File Execution: Run scripts with the
.clextension. - Bytecode VM (WIP): A compiler + VM backend now powers the REPL and file execution.
- Supports arithmetic,
%,**,//, comparisons (==,!=,>,<,>=,<=) with float support. - Supports assignment and updates:
=,+=,-=,*=,/=,%=,**=,//=,++,--. - Current limitation: VM uses a global-only store (locals/scopes are still WIP in the VM).
- Supports arithmetic,
- Language Server Protocol (LSP): Built-in Language Server providing IDE-like features:
- Auto-completion, Hover previews, and live Diagnostics.
- Go to Definition / Declaration / Implementation.
- Find References, Rename variables, and Document Symbols.
- Quickfix Code Actions (e.g., fixing undefined variables).
- Go (version 1.21 or higher recommended)
You can install the code-lang binary directly to your $GOPATH/bin:
go install github.com/walonCode/code-lang@latestHead over to the Releases section to download path-ready binaries for Windows, macOS, and Linux.
Clone and build manually:
git clone https://github.com/walonCode/code-lang.git
cd code-lang
go build -o code-lang main.goStart the interactive shell by running:
go run main.goYou can execute a Code-Lang script by passing the filename as an argument:
go run main.go hello.clThe project now includes an LSP server executable that provides robust IDE features for Code-Lang! You can build the Language Server using the provided build script:
# Build the LSP using the script
./build_lsp
# Run the LSP (operates over stdin / stdout for editors like VS Code)
./lspA dedicated VS Code extension is currently in the works to provide syntax highlighting and deep integration with the Code-Lang Language Server! You can find the repository and follow its development here:
👉 Walon-Foundation/vscode_code-lang
let age = 25;
let name = "Developer";
let isLearning = true;
let add = fn(a, b) {
return a + b;
};
const PI = 3.14159;
# PI = 3.14; # Error: cannot reassign to const
print(add(10, 15)); # Output: 25let fibonacci = [0, 1, 1, 2, 3, 5, 8];
print(fibonacci[3]); # 2
let person = {"name": "Alice", "age": 30};
print(person.name); # Alicestruct User {
name: "Guest",
role: "User",
}
let u = User { name: "Walon", role: "Admin" };
let guest = User {}; # Uses default values
print(u.name); # Walon
print(guest.name); # Guestlet x = 10;
let result = if (x > 10) {
"Greater"
} elseif (x == 10) {
"Equal"
} else {
"Smaller"
};&& and || use short-circuit evaluation — the right side is only evaluated when necessary.
let a = true;
let b = false;
print(a && b); # false
print(a || b); # true
print(!a); # false
# Short-circuit: the right side is never evaluated when
# the result is already known from the left side.
let x = false && someUndefinedFn(); # safe — right side skipped
let y = true || someUndefinedFn(); # safe — right side skipped
# Combine with comparisons
let age = 20;
let hasId = true;
if (age >= 18 && hasId) {
print("Access granted");
};# While loop
let i = 0;
while (i < 5) {
print(i);
i += 1;
};
# For loop with break and continue
for (let j = 0; j < 10; j += 1) {
if (j == 2) { continue; };
if (j == 6) { break; };
print(j);
};import "http";
import "json";
let res = http.get("https://jsonplaceholder.typicode.com/todos/1");
let data = json.parse(res.body);
print(data.title);import "math";
import "time";
let radius = 10;
let area = math.PI * math.pow(radius, 2);
print("Area:", math.round(area));
let start = time.now();
time.sleep(100);
print("Elapsed (ms):", time.since(start));import "strings";
import "hash";
let s = " hello world ";
print(strings.trim(strings.to_upper(s))); # HELLO WORLD
let user = {"name": "walon", "age": 25};
if (hash.has_key(user, "name")) {
print("User keys:", hash.keys(user));
};import "os";
print("Platform:", os.platform);
print("API Key:", os.get_env("API_KEY"));
os.exit(0);# Single-line comment
/*
Multi-line comment
*/
# Formatted print
let name = "Alice";
printf("Hello, %s!\n", name);
# Type checking
print(typeof(10)); # INTEGER
print(typeof("hi")); # STRING
print(typeof([])); # ARRAY| Feature | Status |
|---|---|
| Better Error Reporting (line & column tracking) | ✅ Done |
| Comments (single & multi-line) | ✅ Done |
while and for loops with break/continue |
✅ Done |
Logical Operators && / ` |
|
Standard Library (math, strings, time, hash, os, json, net) |
✅ Done |
Import System (.cl files) |
✅ Done |
| Member Access (dot notation) | ✅ Done |
Compound Assignment (+=, -=, etc.) |
✅ Done |
| Structs (define custom types & create instances) | ✅ Done |
Constants (const) |
✅ Done |
| Static Analysis (Symbol Table & Scope Awareness) | ✅ Done |
| Web Server (request/response handling) | 🚧 WIP |
| Struct Methods | 🔜 Planned |
fs module (file system access) |
🔜 Planned |
| REPL Multi-line Support | 🔜 Planned |
| VSCode Extension (syntax highlighting) | 🚧 WIP |
| LSP (Language Server Protocol) | 🚧 WIP |
This project is licensed under the MIT License. See the LICENSE file for details.
- Thorsten Ball for the foundational guide Writing An Interpreter In Go.
- The Go community for providing an incredible ecosystem for language development.