Warning
Post-Mortem: Project Archived This project was a fun experiment, but it turns out to be a dead end. Iβm archiving it to focus on other tools.
The Realization:
- C++ is complex for a reason: Trying to hide C++ complexity behind Lisp syntax just created a new set of problems without solving the old ones.
- Training Data matters: AI models are surprisingly good at C++ because theyβve read the internet. They are bad at Zweek because I invented it yesterday.
# Zweek
A Lisp-Dialect Intermediate Representation for AI β C++ Compilation
Enabling small local LLMs (0.5B-3B params) to generate native code through constrained S-expressions.
# The Problem
Small local LLMs struggle with C++ syntax. They hallucinate, forget semicolons, and waste tokens on verbose boilerplate.
# The Solution
Zweek is a minimal Lisp dialect that acts as an AI-friendly bridge to C++:
AI Model β Zweek S-Expressions β C++ β Native Binary
- GBNF Grammar constrains AI output to guarantee 100% valid syntax
- S-Expression Parsing converts Lisp-style code
(def add ...)into an AST - C++ Transpiler generates optimized, typed C++17 from the AST
- Native Compilation produces fast executables via MSVC/GCC
# Why Lisp?
- Token-efficient:
(+ a b)vsint result = a + b; - Grammar-constrained: S-expressions are trivial to validate with GBNF
- AST-ready: Parentheses define the tree structure explicitly
# Example
Zweek S-Expression Input:
(def factorial ((n :int)) :int
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(def main () :int
(print "Factorial of 5:")
(print (factorial 5))
0)
Generated C++:
#include <iostream>
#include <vector>
#include <string>
#include <memory>
int factorial(int n) {
if ((n <= 1)) {
return 1;
} else {
return (n * factorial((n - 1)));
}
}
int main() {
std::cout << "Factorial of 5:" << std::endl;
std::cout << factorial(5) << std::endl;
return 0;
}
Output: 120
# Current Features (v0.1)
- β
Typed Functions:
(def name ((arg :type)...) :return-type body) - β
Variables:
(let x 10)βauto x = 10; - β
Conditionals:
(if cond then else)with implicit returns - β Recursion: Full support for recursive function calls
- β
Operators: Math
(+ - * /), Comparisons(< > <= >= ==) - β
I/O:
(print ...)β chainedstd::coutstatements
# Architecture
βββββββββββββββββββ
β llama.cpp β Qwen-0.5B generates Zweek code
β + GBNF Grammar β (constrained to valid syntax)
ββββββββββ¬βββββββββ
β .zw file
βΌ
βββββββββββββββββββ
β Lexer β Tokenize S-expressions
β (lexer.cpp) β β LPAREN, RPAREN, SYMBOL, NUMBER, STRING
ββββββββββ¬βββββββββ
β Tokens
βΌ
βββββββββββββββββββ
β Parser β Build Abstract Syntax Tree
β (parser.cpp) β β FUNCTION_DEF, CALL, LITERAL, etc.
ββββββββββ¬βββββββββ
β AST
βΌ
βββββββββββββββββββ
β Code Generator β Emit C++17 code
β (codegen.cpp) β β Type mapping, operator handling, etc.
ββββββββββ¬βββββββββ
β .cpp file
βΌ
βββββββββββββββββββ
β MSVC / GCC β Compile to native binary
β (cl.exe/g++) β
βββββββββββββββββββ
# Usage
# Transpile only
zweek.exe program.zw
# Compile and run
zweek.exe program.zw --run
Built for the edge. Powered by C++.