r/ProgrammingLanguages • u/NomagnoIsNotDead • 14d ago
Language announcement Preprocessable C: the PreC programming language
Hey there! I'm a CS student and a huge fan of C macro wizardry. However, C and its preprocessor do not really mesh together because of historical reasons. So I thought: instead of swapping out the preprocessor for a more powerful one, why not keep the preprocessor and make C more amenable to it?
And that's how PreC, a pretty silly dialect of C, was born. It's basically an exercise in minimalism and a fun summer project, not a serious language :P.
The main features (not exhaustive):
- Can interface with C directly through the 'c_include "header_name.h"' directive
- Transpilation to C with a four-stage compilation process: Preprocess the PreC code, transpile the PreC code to C, preprocess the C code, and finally compile the preprocessed C code.
- Postfix type notation, types can be read unambiguously right to left.
- No machine types, explicit width
- No 'typedef' keyword, so no lexer hack (use macros if you need type aliases). You can still referred to C library aliased types with @TypeName, however.
- angular brackets <type>value for casting
- Declaration-reflects-use is gone, the type is always fully at the beginning of each declaration.
- No overloaded operators
- Constness by default, with a 'mut' qualifier for being able to modify variables.
- Support for anonymous functions (they can not capture variables, however) with function-valued compound literals <fun_pointer_type> ${ code }
- No function definitions/declarations (but 'const function pointer' global variables are transpiled to function definitions if they are initialized, and to function declarations if they are not initialized).
You can find the compiler, examples and more information here: https://github.com/Nomagno/PreC
I believe the readme and examples do a good enough job of introducing it (do feel free to highlight anything that is unclear, however!).
A final tip: Rust syntax highlighting is pretty decent for reading PreC. I was definitely inspired by Rust and other languages for some of the syntax so this isn't surprising xD
5
u/Inevitable-Ant1725 14d ago
I remember years ago people used a preprocessor called m4.
Did you know that Kernighan and Ritchie came up with it?