myPreCompiler is an educational preprocessor written in C. It expands local includes,
removes comments without corrupting strings and character literals, validates names in
supported declarations, and produces optional statistics.
It requires a C11 compiler and make.
make
make test
make sanitizemake test runs automated regression tests; make sanitize rebuilds the project with
AddressSanitizer and UndefinedBehaviorSanitizer. GitHub CI runs both on every push and
pull request.
Every push to main creates a GitHub Release after all checks pass. The workflow
automatically creates a version tag in the v0.0.<run-number> format and attaches the
Linux x86-64 executable and the PDF report generated from report/report.tex.
./myPreCompiler.out [-v] [-o output.c] -i input.c
./myPreCompiler.out [-v] [-o output.c] input.c
-i file: input C file;-o file: output destination, orstdoutif omitted;-v: statistics and detailed diagnostics onstderr.
The program rejects identical input and output paths, preventing accidental truncation of the source file.
Quoted includes are expanded recursively. Relative paths are resolved against the
directory of the file containing the directive, as is normally done for
#include "file.h". System includes enclosed in angle brackets are preserved.
A stack of canonical paths detects cycles and prints the chain that caused them. A defensive limit of 64 levels is also enforced.
A state machine distinguishes code, // and /* ... */ comments, strings, character
literals, and escape sequences. Newlines within comments are preserved to keep line
numbers unchanged. An unterminated block comment is treated as an error.
Lines are read using getline, so there is no fixed 4096-character limit.
The validator checks simple declarations, qualifiers, pointers, arrays, initializers, and multiple comma-separated declarators. A name must comply with C lexical syntax and cannot be a reserved word.
This project is not a replacement for a complete C parser: particularly complex declarators, macros that generate declarations, and user-defined types may require a real frontend, such as Clang.
include/myPreCompiler.h interface and statistics structures
src/main.c CLI and stream management
src/preprocessor.c includes, comment lexer, and declarations
src/utils.c statistics, memory, and lexical validation
tests/ automated suite and demonstration sources
report/ LaTeX source and report Makefile
The suite checks strings containing comment-like sequences, character literals and escape sequences, block comments, identifiers and initializers, lines longer than 4096 bytes, a slash at the end of a file, nested includes independent of the working directory, cyclic includes, system includes, unterminated comments, and input/output protection.
make reportThis command generates report.pdf in the repository root from report/report.tex.