An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          


chogopy


A ChocoPy compiler written in Go

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![GitHub Release](https://img.shields.io/github/v/release/ashiven/chogopy)](https://github.com/ashiven/chogopy/releases)
[![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/ashiven/chogopy)](https://github.com/ashiven/chogopy/issues)
[![GitHub Issues or Pull Requests](https://img.shields.io/github/issues-pr/ashiven/chogopy)](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_)