Thank you for your interest in contributing to TinyCompiler! We welcome contributions from everyone. This document provides guidelines and instructions for contributing.
Repository: https://github.com/ovishkh/TinyCompiler
Live Demo: https://TinyCompiler.ovishekh.com/
Author: Ovi Shekh (ovishekh.com)
Special Thanks:
- Md. Rashedul Alam
- James Kyle
- Gates Smasher
- Corrado Böhm
- Be respectful and inclusive
- Provide constructive feedback
- Focus on the code, not the person
- Help others learn and grow
- Check existing issues - Search to see if the bug has already been reported
- Create a detailed report including:
- Clear description of the bug
- Steps to reproduce
- Expected behavior vs. actual behavior
- Environment details (Node.js version, OS)
- Code examples if applicable
- Check existing issues - Verify the feature hasn't been suggested
- Describe the feature including:
- Clear use case
- Expected behavior
- How it benefits users
- Any alternative approaches you've considered
# Clone the repository
git clone https://github.com/ovishkh/TinyCompiler.git
cd TinyCompiler
# Install dependencies
npm install-
Create a branch for your changes:
git checkout -b feature/your-feature-name # or for bug fixes: git checkout -b fix/bug-description -
Follow the code style:
- Use
'use strict';at the top of files - Use consistent indentation (2 spaces)
- Add comments explaining complex logic
- Keep functions focused and readable
- Use
-
Make incremental commits:
git add . git commit -m "Descriptive commit message"
-
Run tests before submitting:
npm test # or make test
-
Push your branch:
git push origin feature/your-feature-name
-
Open a Pull Request with:
- Clear title describing the change
- Detailed description of what changed and why
- Reference to any related issues (e.g., "Fixes #123")
- Test results showing all tests pass
-
Respond to review feedback promptly and professionally
TinyCompiler/
├── TinyCompiler.js # Main compiler implementation
├── test.js # Test suite
├── package.json # Project metadata
├── LICENSE # MIT License
├── README.md # Documentation
├── CONTRIBUTING.md # This file
└── Makefile # Build automation
-
TinyCompiler.js - Contains all compiler phases:
tokenizer()- Lexical analysisparser()- Syntactic analysistraverser()- AST traversaltransformer()- AST transformationcodeGenerator()- Code generationcompiler()- Main orchestration
-
test.js - Test cases for each compiler phase
# Run all tests
npm test
make test
# Run specific test
node test.js# Run with example using make
make run
# Or manually
node -e "const { compiler } = require('./TinyCompiler'); console.log(compiler('(add 2 (subtract 4 2))');"When adding new features:
- Add support in tokenizer - If introducing new syntax
- Update parser - To recognize new tokens
- Update traverser - If new node types needed
- Update transformer - To handle transformations
- Update code generator - To output target code
- Add tests - Ensure your changes are tested
Example: Adding operator support
// 1. Tokenizer - recognize +, -, *, /
let OPERATORS = /[+\-*/]/;
if (OPERATORS.test(char)) {
tokens.push({ type: 'operator', value: char });
current++;
continue;
}
// 2. Parser - handle operators in expressions
// 3. Transformer - convert operator expressions
// 4. Code Generator - output operator syntax
// 5. test.js - add test casesUse clear, descriptive commit messages:
# Good
git commit -m "Add support for string literals in tokenizer"
git commit -m "Fix parser handling of nested expressions"
git commit -m "Improve error messages for unknown tokens"
# Avoid
git commit -m "fix stuff"
git commit -m "update"
git commit -m "wip"
When contributing code:
- Add inline comments explaining complex logic
- Update README.md if adding user-facing features
- Document breaking changes clearly
- Add code examples for new features
- Write tests for new features
- Ensure all existing tests pass
- Aim for clear, maintainable test code
- Test edge cases and error conditions
Example test structure:
assert.deepStrictEqual(
compiler('(add 1 2)'),
'add(1, 2);',
'Should compile add expression'
);- Keep the compiler lightweight
- Avoid unnecessary iterations
- Consider memory usage for large inputs
- Profile before optimizing
- Questions? Open an issue with the
questionlabel - Need guidance? Comment on relevant issues
- Want to discuss? Start a discussion or conversation
Contributors will be recognized in:
- GitHub repository contributors section
- Project documentation updates
- Commit history
By contributing to TinyCompiler, you agree that your contributions will be licensed under the MIT License.
Before submitting a PR, ensure:
- Tests pass (
npm test) - Code follows project style
- Comments added for complex logic
- Commit messages are clear
- Documentation updated if needed
- No breaking changes without discussion
- Related issues referenced
Happy Contributing! 🎉
If you have questions, feel free to open an issue or reach out to the maintainers.