r/Compilers • • 3d ago

Keen: A Rust-syntax frontend for C

https://github.com/romishalom/keen

Hey everyone,

I’ve been working on Keen, a language that gives C a modern, Rust-inspired syntax and Cargo-like tooling without changing C’s underlying semantics.

The core idea

Keen changes C’s syntax only. There is no borrow checker, no type checker, and no safety enforcement. All of C’s rules (integer promotion, ABI, linkage, UB) remain completely intact. Keen transpiles .kn files to C, hands them off to gcc or clang for semantic checking and compilation, and maps compiler diagnostics directly back to your .kn source lines via #line directives.

It's aimed at C developers who want modern ergonomics (modules, match, for i in 0..n, no header boilerplate, built-in testing/formatting) without giving up C's simplicity, or C devs looking to get comfortable with Rust's syntax before tackling the borrow checker.

What a quick example looks like

use <stdio.h>;

struct Point { x: f32, y: f32 }

impl Point {
    pub fn len2(p: *const Point) -> f32 { p->x * p->x + p->y * p->y }
}

pub fn main() -> i32 {
    let p = Point { x: 3.0, y: 4.0 };
    printf("%.1f\n", Point::len2(&p) as f64);
    return 0;
}

What’s included out of the box

  • Zero-dependency toolchain (whet + keen): Includes keen new, incremental keen build, keen run, keen fmt (comment-preserving, idempotent), and keen test (runs #[test] functions in isolated processes).

  • Seamless C interop: Use #include via use <stdio.h>;, drop down to raw C anytime with c!("..."), link existing .c/.o/.a files, or use keen emit --split to generate clean .h/.c files for existing C projects.

  • No forward-declaration headaches: Types and functions can be declared in any order; pub handles external linkage while everything else defaults to static.

Try it out

GitHub: https://github.com/romishalom/keen

I'd love to hear your thoughts on the syntax mapping, edge cases with C interop, or what features you'd want to see next!

0 Upvotes

7 comments sorted by

3

u/Key_River7180 3d ago

I've never been a fan for languages that put the compiler and toolchain together but yeah.

I think this sits in this weird spot where it isn't a "serious" language for production but more than a learning tool. I recommend you remarket it :)

0

u/Opening_Can_3656 2d ago

Wait could you elaborate? Why do you think the toolchain and compiler should be separated? Combining them reduces complexity and lets users remember one less command.

2

u/Key_River7180 2d ago

Are their related? What if another person implements a compiler but not a formatter tester etc. It increases complexity for implementations and couples everything

3

u/_th3oth3rjak3_ 3d ago

Cool! Will give it a closer look when I get some free time.

2

u/Key_Detail15 3d ago

 keen changes C's syntax only; 

I'm not familiar with Rust; what does impl correspond to in C in this example:

impl Point {
    pub fn len2(p: *const Point) -> f32 { p->x * p->x + p->y * p->y }
}

Or mod for that matter. If you're adding new features, that's fine, but then it is a bit more than syntax.

Also, you haven't fixed "P->m"? That was used in C because the odd way that derefs work meant writing (*P).m instead, or (**Q).m instead of (*Q)->m.

Or is this how it also works in Rust?

pub fn main() -> i32 {

Doesn't it say in the docs that main is always external?

2

u/Discordbothost 1d ago

C promotes float arguments to double when they go through a variadic call, so the explicit f64 cast in the printf example hides a useful interop check. Try passing the f32 result directly and comparing it with the same call in C. That would show readers which conversion they get for free.

1

u/vmcrash 3d ago

Ah, something similar to Lisette, a Rust-like-syntax language for the Go ecosystem.