{"id":47819132,"url":"https://github.com/solomonkassa/mini-c-compiler","last_synced_at":"2026-04-03T19:01:44.519Z","repository":{"id":334205903,"uuid":"1140492687","full_name":"Solomonkassa/Mini-C-Compiler","owner":"Solomonkassa","description":"Mini-C Compiler A complete, educational C compiler written in C that compiles a subset of C to x86-64 assembly. This project demonstrates the full compilation pipeline from source code to executable.","archived":false,"fork":false,"pushed_at":"2026-01-23T11:47:42.000Z","size":90,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-24T03:21:25.596Z","etag":null,"topics":["assets","c","compiler"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Solomonkassa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-23T10:55:52.000Z","updated_at":"2026-01-23T22:21:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Solomonkassa/Mini-C-Compiler","commit_stats":null,"previous_names":["solomonkassa/mini-c-compiler"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Solomonkassa/Mini-C-Compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solomonkassa%2FMini-C-Compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solomonkassa%2FMini-C-Compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solomonkassa%2FMini-C-Compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solomonkassa%2FMini-C-Compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Solomonkassa","download_url":"https://codeload.github.com/Solomonkassa/Mini-C-Compiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solomonkassa%2FMini-C-Compiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31371639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assets","c","compiler"],"created_at":"2026-04-03T19:01:32.278Z","updated_at":"2026-04-03T19:01:44.505Z","avatar_url":"https://github.com/Solomonkassa.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mini-C Compiler\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![C Language](https://img.shields.io/badge/Language-C-blue.svg)](https://en.wikipedia.org/wiki/C_(programming_language))\n[![Platform: Linux](https://img.shields.io/badge/Platform-Linux-lightgrey.svg)](https://www.linux.org/)\n[![Educational](https://img.shields.io/badge/Project-Educational-green.svg)](https://en.wikipedia.org/wiki/Compiler)\n\nA feature-rich, modular C compiler written entirely in C that implements a complete compilation pipeline from source code to x86-64 assembly. This educational project demonstrates modern compiler design with clean architecture and comprehensive tooling.\n\n## 📋 Table of Contents\n\n- [Features](#-features)\n- [Architecture](#🏗️-architecture)\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Project Structure](#-project-structure)\n- [Modules Overview](#-modules-overview)\n- [Examples](#-examples)\n- [Development](#-development)\n- [Testing](#-testing)\n- [Contributing](#-contributing)\n- [License](#-license)\n- [Acknowledgments](#-acknowledgments)\n\n## ✨ Features\n\n### 🚀 Core Compiler Features\n- **Complete Compilation Pipeline**: Full implementation from lexing to code generation\n- **x86-64 Assembly**: Generates optimized Linux assembly code\n- **Modular Design**: Clean separation of concerns with reusable components\n- **Self-Hosting**: Compiler can compile its own source code\n- **Error Recovery**: Robust error handling and reporting\n\n### 📚 Language Support\n- **Variables and Types**: `int` type with type checking\n- **Control Flow**: `if/else`, `while`, `for` loops\n- **Functions**: Multiple functions with parameters\n- **Expressions**: Full arithmetic, relational, and logical operators\n- **Arrays**: One-dimensional arrays\n- **Pointers**: Basic pointer operations\n- **Structures**: Simple struct support\n\n### 🔧 Development Features\n- **Comprehensive Test Suite**: Unit tests for all modules\n- **Build System**: GNU Make with multiple build configurations\n- **Development Tools**: Debug utilities and visualizers\n- **Documentation**: API documentation and usage examples\n- **Performance Profiling**: Built-in profiling support\n\n## 🏗️ Architecture\n\nThe compiler follows a classic multi-pass architecture:\n\n```\nSource Code → Lexer → Tokens → Parser → AST → Semantic Analyzer → IR → Code Generator → Assembly\n```\n\n### Key Components:\n\n1. **Interfaces** (`interfaces/`): Abstract interfaces for compiler phases\n2. **Modules** (`modules/`): Core implementation of compiler stages\n3. **Utils** (`utils/`): Supporting utilities and data structures\n4. **Tests** (`tests/`): Comprehensive test suite\n\n## 📦 Installation\n\n### Prerequisites\n```bash\n# Required tools\nsudo apt-get update\nsudo apt-get install build-essential gcc nasm git make\n```\n\n### Building from Source\n```bash\n# Clone the repository\ngit clone https://github.com/solomonkassa/Mini-C-Compiler.git\ncd mini-c-compiler\n\n# Build the compiler\nmake\n\n# Run tests to verify installation\nmake test\n\n# Build with optimizations\nmake release\n```\n\n### Quick Start\n```bash\n# One-line setup and test\nmake \u0026\u0026 ./minic examples/hello.c\n```\n\n## 🚀 Usage\n\n### Basic Compilation\n```bash\n# Compile a C source file\n./minic source.c\n\n# Specify output file\n./minic source.c -o output.s\n\n# Compile and assemble directly\n./minic source.c --executable program\n\n# Show AST (for debugging)\n./minic source.c --show-ast\n```\n\n### Advanced Options\n```bash\n# Enable optimizations\n./minic source.c -O2\n\n# Generate intermediate representation\n./minic source.c --emit-ir\n\n# Show symbol table\n./minic source.c --show-symbols\n\n# Verbose compilation output\n./minic source.c -v\n```\n\n## 📁 Project Structure\n\n```\nmini-c-compiler/\n├── interfaces/           # Abstract interfaces\n│   ├── lexer.h          # Lexer interface\n│   ├── parser.h         # Parser interface\n│   ├── codegen.h        # Code generator interface\n│   └── ast.h           # AST node interfaces\n├── modules/             # Implementation modules\n│   ├── lexer.c          # Tokenizer implementation\n│   ├── parser.c         # Recursive descent parser\n│   ├── ast.c           # AST construction and manipulation\n│   ├── semantic.c       # Semantic analysis\n│   ├── codegen.c        # x86-64 code generation\n│   └── optimizer.c      # Code optimization passes\n├── tests/               # Test suite\n│   ├── unit/           # Unit tests\n│   ├── integration/     # Integration tests\n│   ├── benchmarks/      # Performance tests\n│   └── test_runner.c   # Test runner\n├── utils/              # Utility modules\n│   ├── hashmap.c       # Hash table implementation\n│   ├── vector.c        # Dynamic array\n│   ├── stringbuf.c     # String buffer\n│   ├── error.c         # Error reporting\n│   └── debug.c         # Debug utilities\n├── examples/           # Example programs\n│   ├── hello.c        # Hello world\n│   ├── fibonacci.c    # Fibonacci sequence\n│   ├── calculator.c   # Expression calculator\n│   └── structs.c      # Structure example\n├── docs/               # Documentation\n│   ├── API.md         # API reference\n│   ├── ARCHITECTURE.md # Design documentation\n│   └── CONTRIBUTING.md # Contribution guide\n├── Makefile           # Build system\n├── minic.c           # Main compiler driver\n└── README.md         # This file\n```\n\n## 📚 Modules Overview\n\n### Interfaces (`interfaces/`)\n- **lexer.h**: Tokenization interface with Unicode support\n- **parser.h**: Parser interface with error recovery\n- **ast.h**: Abstract Syntax Tree node definitions and visitors\n- **codegen.h**: Backend interface for multiple targets\n\n### Core Modules (`modules/`)\n- **Lexer Module**: Converts source code to tokens with location tracking\n- **Parser Module**: Recursive descent parser with precedence climbing\n- **AST Module**: Immutable AST with visitor pattern\n- **Semantic Module**: Type checking and symbol resolution\n- **CodeGen Module**: x86-64 assembly generator with register allocation\n- **Optimizer Module**: Constant folding, dead code elimination\n\n### Utilities (`utils/`)\n- **Memory Management**: Arena allocator for fast allocation\n- **Collections**: Generic vector, hashmap, and stack\n- **String Handling**: Safe string operations and formatting\n- **Error System**: Rich error messages with source locations\n- **Debug Tools**: AST visualizer and IR dumper\n\n## 💡 Examples\n\n### Example 1: Hello World\n```c\n// examples/hello.c\n#include \"minic_std.h\"\n\nint main() {\n    print_string(\"Hello, World!\\n\");\n    return 0;\n}\n```\n\n### Example 2: Fibonacci Sequence\n```c\n// examples/fibonacci.c\nint fibonacci(int n) {\n    if (n \u003c= 1) return n;\n    return fibonacci(n-1) + fibonacci(n-2);\n}\n\nint main() {\n    return fibonacci(10);  // Returns 55\n}\n```\n\n### Example 3: Array Operations\n```c\n// examples/array.c\nint sum_array(int arr[], int size) {\n    int total = 0;\n    for (int i = 0; i \u003c size; i++) {\n        total += arr[i];\n    }\n    return total;\n}\n\nint main() {\n    int numbers[5] = {1, 2, 3, 4, 5};\n    return sum_array(numbers, 5);  // Returns 15\n}\n```\n\n## 🔬 Development\n\n### Building for Development\n```bash\n# Debug build with symbols\nmake debug\n\n# Release build with optimizations\nmake release\n\n# Build with sanitizers\nmake sanitize\n\n# Generate documentation\nmake docs\n```\n\n### Code Style\nThe project follows a consistent coding style:\n- ANSI C99 with GNU extensions\n- 4-space indentation\n- K\u0026R brace style\n- Descriptive variable names\n- Doxygen-style comments\n\n### Debugging\n```bash\n# Run with debug output\n./minic source.c --debug\n\n# Generate AST visualization (requires Graphviz)\n./minic source.c --visualize-ast\n\n# Profile compilation\n./minic source.c --profile\n```\n\n## 🧪 Testing\n\n### Running Tests\n```bash\n# Run all tests\nmake test\n\n# Run specific test categories\nmake test-unit\nmake test-integration\nmake test-benchmarks\n\n# Run tests with valgrind\nmake test-memory\n\n# Generate test coverage report\nmake coverage\n```\n\n### Test Structure\n- **Unit Tests**: Test individual modules in isolation\n- **Integration Tests**: Test complete compilation pipelines\n- **Regression Tests**: Ensure previously fixed bugs stay fixed\n- **Performance Tests**: Benchmark compiler performance\n- **Fuzz Tests**: Randomized input testing\n\n### Adding Tests\n```bash\n# Create a new test\ncp tests/template.c tests/unit/test_new_feature.c\n# Implement test, then run:\nmake test-unit\n```\n\n## 🤝 Contributing\n\nWe welcome contributions! Here's how to get started:\n\n1. **Fork** the repository\n2. **Create a feature branch**: `git checkout -b feature/amazing-feature`\n3. **Make your changes** following the code style\n4. **Add tests** for new functionality\n5. **Run the test suite**: `make test`\n6. **Commit your changes**: `git commit -m 'Add amazing feature'`\n7. **Push to the branch**: `git push origin feature/amazing-feature`\n8. **Open a Pull Request**\n\n### Contribution Areas\n- **Language Features**: Add new C constructs\n- **Optimizations**: Improve generated code quality\n- **Error Messages**: Better diagnostics\n- **Documentation**: Improve guides and examples\n- **Tools**: Developer utilities and debugging aids\n\n### Code Review Process\n1. Automated CI checks run on PR\n2. Maintainers review for correctness and style\n3. Changes requested if needed\n4. Once approved, PR is merged\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n```\nMIT License\n\nCopyright (c) 2023 Mini-C Compiler Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n```\n\n## 🙏 Acknowledgments\n\n### Educational Resources\n- **Dragon Book**: Compilers: Principles, Techniques, and Tools\n- **Crafting Interpreters**: Robert Nystrom's excellent book\n- **LLVM Documentation**: Inspiration for modern compiler design\n- **NASM Manual**: x86-64 assembly reference\n\n### Tools Used\n- **GCC**: Compiler toolchain\n- **NASM**: Assembler\n- **Make**: Build automation\n- **Valgrind**: Memory debugging\n- **GDB**: Debugger\n\n### Contributors\nThanks to all the contributors who have helped make this compiler better!\n\n---\n\n## 📊 Project Status\n\n| Component | Status | Notes |\n|-----------|--------|-------|\n| Lexer | ✅ Complete | Full C tokenization |\n| Parser | ✅ Complete | Recursive descent |\n| AST | ✅ Complete | Visitor pattern |\n| Semantic | ✅ Complete | Type checking |\n| CodeGen | ✅ Complete | x86-64 assembly |\n| Optimizer | 🔄 In Progress | Basic optimizations |\n| Standard Library | 🔄 In Progress | Minimal implementation |\n\n**✅ = Complete** | **🔄 = In Progress** | **📋 = Planned**\n\n---\n\n## 🌟 Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=solomonkassa/Mini-C-Compiler\u0026type=Date)](https://star-history.com/#yourusername/mini-c-compiler\u0026Date)\n\n---\n\n## 📞 Contact \u0026 Support\n\n- **Issues**: [GitHub Issues](https://github.com/solomonkassa/mini-c-compiler/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/solomonkassa/mini-c-compiler/discussions)\n- **Email**: solomonmulu000@gmail.com\n\n---\n\n*\"The only way to learn a new programming language is by writing programs in it.\" - Dennis Ritchie*\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003eBuilt with ❤️ by Solomon Kassa\u003c/sub\u003e\u003cbr\u003e\n  \u003csub\u003eIf you find this project useful, please consider giving it a ⭐\u003c/sub\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolomonkassa%2Fmini-c-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolomonkassa%2Fmini-c-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolomonkassa%2Fmini-c-compiler/lists"}