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.- Backported 'declarations inside conditionals' (e.g.
if (i32 x = a; x < 50) { ... }) from C29 - Supported types of integer constants: hexadecimal
0xDEADBEEF, octal0o34017, decimal9990999(leading zeroes not treated as octal), binary0b10100010. - Removed:
-=,|=, etc. except+= - Removed:
--,++ - Removed suffixes on constants
999L999U999F. Use999.0for floats.0x1000p3and1.0e4float notation is still available. - Anonymous structs/unions/enums not allowed, must define structs/unions/enums and give then a name using
type struct TypeName = { /*members*/ }; - Statically dispatched constant functions and variables associated to a struct type (accessed like if they were members, but they don't take up space) with
type struct TypeName = { /*members*/ } constdata { /*members with initializers*/ }; - Structurally typed tuples
tuple(i32 x, i32 y)replacing anonymous structs - Struct access auto-dereference in most cases.
- Method call syntax sugar
..and->.
See examples/informal_spec.prec 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. Use it like you wouldprecc.sh.