https://github.com/ashiven/chogopy
A ChocoPy compiler written in Go
https://github.com/ashiven/chogopy
chocopy compiler-design compilers golang lexers llvm llvm-ir parsers
Last synced: 17 days ago
JSON representation
A ChocoPy compiler written in Go
- Host: GitHub
- URL: https://github.com/ashiven/chogopy
- Owner: ashiven
- License: mit
- Created: 2025-08-15T08:42:52.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-31T06:38:12.000Z (9 months ago)
- Last Synced: 2025-08-31T07:13:08.259Z (9 months ago)
- Topics: chocopy, compiler-design, compilers, golang, lexers, llvm, llvm-ir, parsers
- Language: Go
- Homepage:
- Size: 338 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
chogopy
A ChocoPy compiler written in Go
[](https://opensource.org/licenses/MIT)
[](https://github.com/ashiven/chogopy/releases)
[](https://github.com/ashiven/chogopy/issues)
[](https://github.com/ashiven/chogopy/pulls)
## About
**chogopy** is a compiler for the [ChocoPy language](https://chocopy.org/) written purely in **Go** as a fun way to learn more about compilers and get better at **Go**.
It includes multiple analysis passes that perform type checking, variable scope analysis, and more, and compiles down to LLVM IR for flexibility and platform support.
## Setup
1. Clone the repository.
```bash
git clone https://github.com/ashiven/chogopy.git
```
2. Install LLVM according to [this guide](https://tinygo.org/docs/guides/build/bring-your-own-llvm/).
```bash
echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install clang-18 llvm-18-dev lld-18 libclang-18-dev
```
3. Compile the compiler.
```bash
go build -tags=llvm18 -o cgp
```
## Usage
By default **ChoGoPy** will run every analysis and transformation pass available to it. You are, however, able to specify the exact
stages that the compiler should go through by using the following command line flags:
- `-l` to emit only the tokens generated by the lexer.
- `-p` to parse the given source code and print the resulting AST.
- `-t` to parse the given source code and perform static type checking on it.
- `-n` to parse the given source code and perform name scope analysis on it.
- `-c` to generate LLVM IR from the given source code.
An exemplary command would look as follows:
```bash
./cgp -p test.choc
```
## Contributing
Please feel free to submit a [pull request](https://github.com/ashiven/chogopy/pulls) or open an [issue](https://github.com/ashiven/chogopy/issues).
1. Fork the repository
2. Create a new branch: `git checkout -b feature-name`.
3. Make your changes
4. Push your branch: `git push origin feature-name`.
5. Submit a PR
## License
This project is licensed under the [MIT License](./LICENSE).
---
> GitHub [@ashiven](https://github.com/ashiven) ·
> Twitter [ashiven\_](https://twitter.com/ashiven_)