https://github.com/ppmpreetham/pilox
Implementation of the Lox Interpreter written in Python
https://github.com/ppmpreetham/pilox
programming-language programming-language-development
Last synced: 19 days ago
JSON representation
Implementation of the Lox Interpreter written in Python
- Host: GitHub
- URL: https://github.com/ppmpreetham/pilox
- Owner: ppmpreetham
- License: mit
- Created: 2025-05-05T20:07:26.000Z (28 days ago)
- Default Branch: main
- Last Pushed: 2025-05-09T20:52:10.000Z (24 days ago)
- Last Synced: 2025-05-09T21:40:51.632Z (24 days ago)
- Topics: programming-language, programming-language-development
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pilox
A simple programming language implementation for understanding interpreters and compilers
[](https://opensource.org/licenses/MIT)
[](https://github.com/yourusername/Pilox)## Overview
Pilox is an interpreted programming language built from scratch as a learning project. It's inspired by the Crafting Interpreters approach but with some unique additions. This project aims to demystify how programming languages work under the hood.
> [!NOTE]
> This project is currently under active development. Many features are incomplete or may change.## Features
- C-like syntax with modern language features
- Support for variables, functions, and control structures
- First-class functions
- Object-oriented programming capabilities
- Dynamic typing
- Interactive REPL mode for quick testing
- File execution mode for running scripts## Installation
```bash
# Clone the repository
git clone https://github.com/ppmpreetham/pilox.git
cd pilox# No installation required - pure Python implementation
```## Usage
```bash
python language/main.py
```### REPL Mode
For interactive use, simply run:
```bash
pilox
```This will start the Pilox REPL where you can write and execute code line by line.
```bash
pilox> var greeting = "Hello, world!";
pilox> print greeting;
Hello, world!
pilox> exit
```### Running Scripts
To execute a Pilox script file:
```bash
pilox ./path/to/script.plx
```## Examples
### Hello World
```pilox
print "Hello, World!";
```### Variables
> [!NOTE]
> *Coming soon* and will look like:```c
var name = "Pilox";
var version = 0.1;
print "Running " + name + " version " + version;
```### Control Flow
> [!NOTE]
> *Coming soon* and will look like:```c
var max = 10;
var i = 0;while (i < max) {
print i;
i = i + 1;
}
```### Functions
> [!NOTE]
> *Coming soon* and will look like:```c
fun factorial(n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}print factorial(5); // Outputs: 120
```
## Project Structure
```python
pilox/
├── language/
│ ├── main.py # Entry point for the interpreter
│ ├── scanner.py # Lexical analyzer
│ └── TokenType.py # Token definitions
├── examples/ # Example pilox programs
└── README.md
```## Implementation Details
Pilox is built following a classic compiler pipeline:
1. **Scanning/Lexing** (Implemented): Converting source text into tokens
2. **Parsing** (In progress): Building an abstract syntax tree
3. **Static Analysis** (Planned): Scope resolution and type checking
4. **Interpretation/Compilation** (Planned): Executing or translating the code## Contributing
Contributions are welcome! If you'd like to help develop Pilox:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request## License
Distributed under the MIT License. See `LICENSE` for more information.
## Acknowledgments
- [Crafting Interpreters](https://craftinginterpreters.com/) by Robert Nystrom
- The Python programming language## Roadmap
- [x] Lexical analysis (Scanner)
- [ ] Parser implementation
- [ ] AST interpreter
- [ ] Variable declarations and scopes
- [ ] Control flow statements
- [ ] Functions and closures
- [ ] Classes and instances
- [ ] Standard library