PreC, short for Preprocessable C, is a simplified version of C99. The syntax and semantics are meant to play far nicer with the C preprocessor than C itself, hence allowing to write macros much easier.
Special thanks to my friend Linja for providing ideas and feedback in everything that relates to the language design!
Its major features include:
- Anonymous function literal syntax (no variable capture):
<return_type (&)(args)> ${ ... } - No function definition/declaration syntax: instead assign anonymous functions to global function pointer variables.
- Properly context free grammar, no lexer hack.
- Fully non-overloaded operators: unary minus
-areplaced with~a, dereference operator is now^, bitwise operations are nowbandborbxorbnot. - Postfix type syntax with no need for parentheses.
- Bitwise operator symbols.
- "Declaration reflects use" is gone, types must now appear fully before identifiers.
- Constness by default,
mutkeyword to declare variables as mutable. - No
typedef, use#define. typeof'backported' from C23.- Custom-named C types may still be referenced with
@TypeName. c_includedirective for direct usage of C headers, and hence perfect C library compatibility.
See examples/informal_spec.rs and the rest of examples for more details.
PreC currently has a four-stage translation process:
- The PreC source is preprocessed with the C preprocessor.
- The preprocessed source is compiled to C with any
c_includedirectives replaced with#includedirectives. - The C source is preprocessed with the C preprocessor.
- The preprocessed source is compiled with your system's C compiler.
- Run
maketo compile. You may now useprecc.shlike you would use any other C compiler. It will detect any.precand.prehfiles in the arguments, convert them to.c/.hversions, and pass them along to thecccommand.
make installwill install theprecccommand to your user binary directory. It will refer to the absolute path of theprec_internalbinary of the PreC source code directory, so don't get rid of it!