/Alpha-Compiler

This Repository contains the source code for compiler of a language called Alpha!

Primary LanguageCMIT LicenseMIT

Alpha-Compiler

Welcome to the Alpha-Compiler Project! This Repository contains the source code for compiler of a language called Alpha!

Overview

Alpha-Compiler was written specifically for educational purposes. It serves as a stepping stone for understanding the fundamental components that constitute a modern-day compiler and should not be regarded as a fully-fledged one.

Introduction

The Alpha-Compiler reads source files written in the Alpha programming language, and compiles them into Alpha-Binary files. The Alpha Language Specification (ALS) are defined by the Alpha Virtual Machine (AVM) used to run the binary files produced. You may find some example Alpha programs inside the tests folder.

The compiler is a CLI tool writen in C without making any system calls.

Installation

Clone the repository to your local machine using either the GitHub Desktop app or by using the following command:

git clone https://github.com/gthe0/Alpha-Compiler

Compilation

For compiling the project, you need to have installed

  • flex
  • bison
  • A C compiler

For *nix platform, a Makefile is being provided, so simply run:

make

For Windows, first generate the c code from the lex.l file, then do the same for the parser.y file. Afterwards, compile and link all the object files, forming the executable.

Usage

As mentioned previously, the Alpha-Compiler is a CLI tool, so to use it you can run the executable and pass an Alpha Source Code file to it.

You can also pass the flags given below:

Flags

  • -s Produces a file called sym_table.txt containing the symbol talbe entries
  • -q Produces a file called quads.txt containing the Intermediate Represantation (IR) or the quads produced
  • -i Produces a file called tcg_instructions.txt containing the target code/instructions and the buffers generated by the Compiler in a Human Readable form
  • -o Changes the name of the binary file outputed by the Compiler
  • -Ox Flag used to pass various optimization options. Use O1 for peephole optimizations and code transformations (deprecated), O2 for bypassing chained jumps, O3 to apply both.

Contributing

Contributions to this project are welcome! If you would like to contribute, please follow these steps:

  • Fork the repository.
  • Create a new branch for your feature or bug fix.
  • Make your changes and commit them.
  • Push your changes to your forked repository.
  • Submit a pull request, explaining the changes you have made.