Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ashiven/chogopy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChoGoPy

A ChocoPy compiler written in Go

License: MIT GitHub Release GitHub Issues or Pull Requests GitHub Issues or Pull Requests

About

ChoGoPy is a compiler for the ChocoPy language 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.
git clone https://github.com/ashiven/chogopy.git
  1. Install LLVM according to this guide.
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
  1. Compile the compiler.
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:

./cgp -p test.choc

Contributing

Please feel free to submit a pull request or open an issue.

  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.


GitHub @ashiven  ·  Twitter ashiven_