How arithy/packcc works
Project type and purpose
• This is PackCC, an open-source command-line parser generator tool written in C.
• You feed it a grammar in PEG format, and it spits out a C parser (a .c and .h file) that uses packrat parsing with left-recursion support.
File structure
• src/packcc.c: the single core source file implementing CLI, parsing the PEG, building an AST, and emitting C code.
• import/: reusable grammar fragments (e.g., Unicode rules, AST support).
• examples/: sample grammars and driver programs (calculator, tiny-C compiler).
• tests/: Bats scripts and helper files to verify correct parser behavior.
• benchmark/: scripts and sample inputs to measure performance.
• CMakeLists.txt and .github/workflows/: build system and CI.
README for insights
• Confirms the pipeline:
1. Read PEG grammar (+ %import files)
2. Parse grammar definitions with packrat algorithm
3. Build an AST of grammar rules
4. Generate C source and header files
• Build and test flow powered by CMake, Bats, and Uncrustify.
• CLI Front-End (packcc executable)
• Import Manager (handles %import directives and search paths)
• Grammar Parser Module (packrat parser engine, left-recursion support)
• Grammar AST (in-memory representation of rules and actions)
• Code Generator (walks the AST, emits .c & .h code, applies %header/%source sections)
• File I/O (reading .peg, writing output files)
• Build System & CI (CMake, GitHub Actions)
• Test Harness (Bats scripts, test inputs)
• Benchmark Suite (benchmark scripts & sample grammars)
• User invokes CLI Front-End → File I/O reads grammar file & %import files → hands text to Import Manager → combined grammar goes to Grammar Parser Module → produces Grammar AST → flows into Code Generator → uses File I/O to write .c/.h → exit.
• Build System orchestrates compilation of src/packcc.c into executable, runs Test Harness and Benchmark Suite.
c. Architectural patterns and principles
• Single-pass pipeline: text → import resolution → parsing → AST → code generation.
• Packrat parsing with memoization for linear-time grammar parsing.
• Modular import system for grammar reuse.
• Test-driven via Bats; CI automation via GitHub Actions.
d. Key technologies
• Language: C (single source file).
• Build: CMake, Make/Visual Studio.
• Tests: Bats-core + shell helper scripts, Uncrustify for code style.
• CI: GitHub Actions (.github/workflows/testing.yml).