Skip to content

Custom compiler for the Hades language as a learning experiment with modern compiler prototyping

Notifications You must be signed in to change notification settings

nenuadrian/hades-compiler

Repository files navigation

Hades Compiler

Java CI with Gradle

hades

Overview

Compiler for a custom language, Hades, to JVM byte-code using ANTLR for parsing as an opportunity to explore the inner-depth of compiler prototyping methodology.

The new language is not expected to beat any other in any meaningul way in terms of syntax or performance, but I might focus on bringing different capabilities from different languages experimentally.

I use ANTLR as it is quite commonly known and leveraged by production languages and we can find definition files for them such as:

Purpose

The primary goal is to create a basic compiler capable of solving simple LeetCode problems and scripting-level programs. This is an educational passion project to understand compiler construction, not intended for production use or to solve a direct problem with other languages.

Compiler Design

The compiler will follow a a fairly traditional structure:

  1. Tokenization: Breaking down the source code into tokens.
  2. Abstract Syntax Tree (AST): Converting tokens into an AST.
  3. Code Generation: Translating the AST into byte-code/assembly/executable code.

Syntax

Hello world example:

hero a = 2; # variable
hero b = 3; # variable
styx a; # prints a
bestow a; # returns a

Defined in src/main/antlr/Hades.g4.

Build & Run

Gradlew based. Use gradlew.bat for Windows.

Build

./gradlew build

Run

./gradlew run --args="--help"

Test

./gradlew test test

Disclaimer

Provided as is with no maintenance or guarantees.

About

Custom compiler for the Hades language as a learning experiment with modern compiler prototyping

Resources

Stars

Watchers

Forks