Skip to content

Nomagno/PreC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The PreC programming language

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 -a replaced with ~a, dereference operator is now ^, bitwise operations are now band bor bxor bnot.
  • 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, mut keyword to declare variables as mutable.
  • No typedef, use #define.
  • typeof 'backported' from C23.
  • Custom-named C types may still be referenced with @TypeName.
  • c_include directive 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, octal 0o34017, decimal 999 0999 (leading zeroes not treated as octal), binary 0b10100010.
  • Removed: +=, -=, |=, etc.
  • Removed: --, ++
  • Removed suffixes on constants 999L 999U 999F. Use 999.0 for floats. 0x1000p3 and 1.0e4 float notation is still available.

See examples/informal_spec.prec and the rest of examples for more details.

PreC currently has a four-stage translation process:

  1. The PreC source is preprocessed with the C preprocessor.
  2. The preprocessed source is compiled to C with any c_include directives replaced with #include directives.
  3. The C source is preprocessed with the C preprocessor.
  4. The preprocessed source is compiled with your system's C compiler.

Usage (Unix-like systems):

  • Run make to compile. You may now use precc.sh like you would use any other C compiler. It will detect any .prec and .preh files in the arguments, convert them to .c/.h versions, and pass them along to the cc command.

Installation (Unix-like systems):

  • make install will install the precc command to your user binary directory. Use it like you would precc.sh.

About

The PreC programming language, a slimmed down and redesigned version of C99

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages