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:

  1. 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.
  2. 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
  1. GBNF Grammar constrains AI output to guarantee 100% valid syntax
  2. S-Expression Parsing converts Lisp-style code (def add ...) into an AST
  3. C++ Transpiler generates optimized, typed C++17 from the AST
  4. Native Compilation produces fast executables via MSVC/GCC

# Why Lisp?

  • Token-efficient: (+ a b) vs int 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 ...) β†’ chained std::cout statements

# 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++.

πŸ”’ This site's search assistant runs a local AI model in your browser β€” no cloud AI, no tracking. See the ℹ️ in the chat panel for details.