nikkehtine / hydrogen

Compiler in Go following a C++ tutorial

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hydrogen compiler

Hobby programming language compiler in Go

Compiler in Go following a live coding series by @orosmatthew - Creating a Compiler (originally in C++)

Link to Matthew's original project repo

Usage

Requirements:

  • Go >= 1.21
  • nasm
  • ld

Warning

Currently this program only works on Linux

  1. Clone the repo

    git clone https://github.com/nikkehtine/hydrogen.git
  2. Build and run the program

    You can just use the test.sh script for now, which should build and run the program

    ./test.sh

    This script also accepts certain commands for convenience:

    • compile: just compile the program, don't run it or remove generated files
    • clean: compile and run the program, but delete generated files
    • cleanup: just delete any generated output files that exist

What works and what doesn't

  • Compiling
  • Parsing
  • Tokenization
  • Variables
  • Expressions
  • PEMDAS
  • if statements and scopes

What I've learned and want to learn

I've learned:

  • how compilers work (things such as tokenizer, lexer, outputting to assembly, linking)
  • how to turn code into tokens, and then translate tokens into output
  • how programs operate on low level and communicate with the operating system
  • more advanced concepts about programming and the Go language, such as structs, buffers, enums, maps, unions, operations on files, accepting cli arguments, error handling

I want to:

  • learn the differences in the way OSes (Windows, macOS, Linux) communicate with programs
  • learn more on how certain operations and language features work on a lower level
  • learn more advanced concepts about programming
  • be able to brag about having written my own compiler :)

Useful resources

About

Compiler in Go following a C++ tutorial


Languages

Language:Go 87.6%Language:Shell 12.1%Language:Hy 0.3%