ZeLang is a compiled programming language for building database-driven CRUD applications with web interfaces. Define your data structures with decorators, declare your UI components, and compile to C or Go native binaries. Get automatic database operations, CRUD APIs, and Bootstrap-styled web pages.
Phase 1 Working - Structs, CRUD operations, HTTP server, and Bootstrap UI generation fully functional! Multi-Language Support - Compile to both C and Go targets!
For the compiler itself:
- Go 1.19+ (for building the ZeLang compiler)
For C target (optional):
- GCC or Clang (for compiling generated C code)
- SQLite3 library
- libmicrohttpd (for web server features)
For Go target:
- Go 1.19+ (same as compiler requirement)
- No additional dependencies! (uses pure Go SQLite driver, no CGo)
Install on macOS:
# Minimal (compiler + Go target support)
brew install go
# Full (compiler + C target support)
brew install go sqlite3 libmicrohttpd
xcode-select --install# Clone the repository
cd zelang
# Build the compiler
make
# Or manually:
cd cmd/zelang && go build -o ../../zelang# Build to C (default)
./zelang build examples/student.zl
./student
# Build to Go (recommended - faster, no C dependencies)
./zelang build -lang go examples/student.zl
./student
# Build the web todo app (Go target)
./zelang build -lang go examples/go-todo.zl
./go-todo
# Open http://localhost:8080 in your browser
# Build the web todo app (C target)
./zelang build examples/todo.zl
./todo
# Open http://localhost:8080 in your browserZeLang can compile your code to either C or Go:
# Compile to C (default)
./zelang build myapp.zl
# Compile to Go (explicit)
./zelang build -lang go myapp.zl
# Compile to C (explicit)
./zelang build -lang c myapp.zl✅ No C dependencies - No need for GCC, SQLite3, or libmicrohttpd
✅ Pure Go SQLite - Uses modernc.org/sqlite (no CGo required)
✅ Faster builds - Go compilation is typically faster
✅ Cross-platform - Easier to cross-compile for different OS/architectures
✅ Better tooling - Access to Go's excellent debugging and profiling tools
✅ Smaller binaries - C binaries are typically 10-20x smaller ✅ Lower memory usage - C has a smaller runtime footprint ✅ Maximum performance - Direct system calls, no GC overhead ✅ Embedded systems - Better for resource-constrained environments
| Feature | C Target | Go Target |
|---|---|---|
| Binary Size | ~50-100KB | ~8-12MB |
| Build Dependencies | GCC, SQLite3, libmicrohttpd | Go compiler only |
| Runtime Dependencies | SQLite3, libmicrohttpd | None (static binary) |
| Build Speed | Fast (1-2s) | Very Fast (<1s) |
| Cross-Compilation | Complex | Simple (GOOS=linux go build) |
| Memory Safety | Manual | Automatic (bounds checking) |
| Error Handling | Return codes | Go errors with stack traces |
| SQLite Driver | Native C library | Pure Go (no CGo) |
| HTTP Server | libmicrohttpd | Go net/http |
| Debugging | GDB, Valgrind | Go debugger (delve) |
| Best For | Embedded, minimal footprint | Development, deployment, cross-platform |
ZeLang supports the following primitive types:
| Type | Description | Maps to C | Maps to Go | Maps to SQL |
|---|---|---|---|---|
int |
64-bit integer | int64_t |
int64 |
INTEGER |
float |
Double precision | double |
float64 |
REAL |
string |
Text string | char* |
string |
TEXT |
bool |
Boolean | int |
bool |
INTEGER |
date |
Date string | char* |
string |
TEXT |
datetime |
Datetime string | char* |
string |
TEXT |
Define data structures that map to database tables:
@storage(sqlite)
@table("products")
struct Product {
@primary
@autoincrement
int id;
@required
@length(max: 200)
string name;
@required
float price;
int quantity;
}| Decorator | Arguments | Purpose | Example |
|---|---|---|---|
@storage |
Backend name | Specify storage backend | @storage(sqlite) |
@table |
Table name | Custom table name | @table("products") |
| Decorator | Arguments | Purpose | SQL Effect |
|---|---|---|---|
@primary |
None | Mark as primary key | PRIMARY KEY |
@autoincrement |
None | Auto-increment field | AUTOINCREMENT |
@required |
None | NOT NULL constraint | NOT NULL |
@unique |
None | Unique constraint | UNIQUE |
@length |
max: n |
Max length validation | (validation only) |
Define a web page with route and UI components:
@route("/")
Page TodoApp {
title: "Todo Manager";
DataList {
source: Todo.all();
columns: ["id", "title", "completed"];
actions: ["edit", "delete"];
}
Form {
action: "/todo/create";
fields: {
title: { type: "text", required: true },
description: { type: "textarea", required: true },
completed: { type: "checkbox" }
};
submit: "Add Todo";
}
}Displays database records in a Bootstrap table:
DataList {
source: Model.all(); // Data source
columns: ["field1", "field2"]; // Columns to show
actions: ["edit", "delete"]; // Action buttons
}Generates Bootstrap forms for data entry:
Form {
action: "/path/create"; // Form submit URL
fields: {
fieldName: {
type: "text", // text, textarea, checkbox, number
required: true, // Validation
placeholder: "..." // Placeholder text
}
};
submit: "Button Text"; // Submit button text
}Define custom request handlers:
@route("/todo/create")
@method(POST)
handler createTodo(Request req, Response res) {
Todo* todo = Todo_create(
req.form["title"],
req.form["description"],
req.form["completed"] == "on"
);
res.redirect("/");
}
@route("/todo/delete/:id")
handler deleteTodo(Request req, Response res) {
int id = req.params["id"];
Todo_delete(id);
res.redirect("/");
}| Decorator | Purpose | Example |
|---|---|---|
@route |
URL path | @route("/users") |
@method |
HTTP method | @method(POST), @method(GET) |
For each struct, ZeLang generates CRUD operations in the target language:
C Target:
// Create a new record
Model* Model_create(field1, field2, ...);
// Find record by ID
Model* Model_find(int64_t id);
// Get all records
Model** Model_all(int* count);
// Delete record by ID
int Model_delete(int64_t id);
// Initialize table (called automatically)
void Model_init_table();Go Target:
// Create a new record
func CreateModel(field1, field2, ...) (*Model, error)
// Find record by ID
func FindModel(id int64) (*Model, error)
// Get all records
func AllModels() ([]*Model, error)
// Delete record by ID
func DeleteModel(id int64) error
// Initialize table (called automatically)
func initModelTable() error# Build to C (default)
./zelang build myapp.zl
# Generates: myapp.c → myapp binary (~50KB)
# Build to Go
./zelang build -lang go myapp.zl
# Generates: myapp.go → myapp binary (~8MB, includes Go runtime)For CLI applications (no web UI):
./myapp
# Creates database and tables
# Runs demo CRUD operationsFor web applications (with Page/Form components):
./myapp
# Server running on http://localhost:8080
# Press ENTER to stop the server...The binary automatically:
- Creates
app.dbSQLite database - Creates tables from struct definitions
- Initializes schema with constraints
- For web apps: Starts HTTP server on port 8080
- For web apps: Serves Bootstrap-styled pages
- For web apps: Handles form submissions and CRUD operations
zelang/
├── cmd/zelang/ # Compiler CLI
├── pkg/
│ ├── lexer/ # Tokenizer
│ ├── parser/ # Parser
│ ├── ast/ # AST definitions
│ └── codegen/ # Code generators
│ ├── generator.go # C code generator
│ ├── go_generator.go # Go code generator
│ └── templates/
│ ├── go/*.tmpl # Go templates
│ └── (C uses inline generation)
├── examples/ # Example applications (.zl files)
├── Makefile # Build system
└── README.md
// todo.zl - Complete web application in 50 lines
@storage(sqlite)
@table("todos")
struct Todo {
@primary
@autoincrement
int id;
@required
@length(max: 200)
string title;
@required
string description;
bool completed;
}
@route("/")
Page TodoApp {
title: "Todo Manager";
DataList {
source: Todo.all();
columns: ["id", "title", "completed"];
actions: ["edit", "delete"];
}
Form {
action: "/todo/create";
fields: {
title: { type: "text", required: true },
description: { type: "textarea", required: true },
completed: { type: "checkbox" }
};
submit: "Add Todo";
}
}
@route("/todo/create")
@method(POST)
handler createTodo(Request req, Response res) {
Todo_create(
req.form["title"],
req.form["description"],
req.form["completed"] == "on"
);
res.redirect("/");
}
@route("/todo/delete/:id")
handler deleteTodo(Request req, Response res) {
Todo_delete(req.params["id"]);
res.redirect("/");
}Compile and run:
# Option 1: Build to Go (recommended - no C dependencies)
./zelang build -lang go todo.zl
./todo
# Open http://localhost:8080
# Option 2: Build to C (smaller binary)
./zelang build todo.zl
./todo
# Open http://localhost:8080Screenshot:
You get:
- ✅ SQLite database with
todostable - ✅ Full CRUD operations (Create, Read, Delete)
- ✅ Bootstrap-styled web interface
- ✅ Responsive table showing all todos
- ✅ Form for adding new todos
- ✅ Delete buttons for each item
- ✅ Native binary (~60KB)
- ✅ Zero dependencies at runtime (SQLite embedded)
- ✅ Full lexer with all tokens
- ✅ Parser for structs, pages, handlers
- ✅ AST generation
- ✅ Multi-target code generation:
- ✅ C code generation
- ✅ Go code generation
- ✅ Decorator parsing and validation
- ✅ Automatic compilation (GCC for C, Go compiler for Go)
- ✅ SQLite integration:
- ✅ C: Native SQLite3 library
- ✅ Go: Pure Go SQLite (
modernc.org/sqlite, no CGo!)
- ✅ Automatic table creation
- ✅ Primary keys and auto-increment
- ✅ NOT NULL and UNIQUE constraints
- ✅ Complete CRUD operations:
- ✅
Model_create()/CreateModel()- INSERT with prepared statements - ✅
Model_find()/FindModel()- SELECT by ID - ✅
Model_all()/AllModels()- SELECT all with dynamic arrays - ✅
Model_delete()/DeleteModel()- DELETE by ID
- ✅
- ✅ Type mapping (int→INTEGER, string→TEXT, bool→INTEGER)
- ✅ HTTP server:
- ✅ C: libmicrohttpd
- ✅ Go: net/http (standard library)
- ✅ Route handling (GET, POST)
- ✅ Form data parsing (URL-encoded)
- ✅ Request parameters
- ✅ HTTP redirects
- ✅ Static and dynamic routing
- ✅ Graceful shutdown (Go target with signal handling)
- ✅ Bootstrap 5 integration (CDN)
- ✅ Responsive HTML generation
- ✅ DataList component (tables)
- ✅ Form component with validation
- ✅ Input types: text, textarea, checkbox, number
- ✅ CRUD action buttons
- ✅ Automatic field type detection
- Lexer and parser
- Struct parsing with decorators
- C code generation
- Go code generation ⭐ NEW!
- SQLite table creation
- Complete CRUD implementation (C & Go)
- HTTP server (libmicrohttpd for C, net/http for Go)
- Page and Form UI components
- DataList component
- Bootstrap UI generation
- Route handlers
- Pure Go SQLite driver (no CGo) ⭐ NEW!
- UPDATE operations
- Edit forms and pages
- Field validation implementation
- Foreign keys (@foreign_key decorator)
- Relationships (one-to-many, many-to-many)
- Query filters and search
- Pagination for DataList
- File upload support
- Authentication decorators
- Custom CSS/themes
- MySQL backend support
- PostgreSQL backend support
- Session management
- Cookie handling
- JSON API endpoints
- WebSocket support
- Template inheritance
- Multi-page applications
- Admin panel generation
- Migration system
makemake testmake cleanThis is an early prototype. Contributions welcome!
MIT License
Gunesh - Building the future of database-first development
