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
Requirements:
- Go >= 1.21
nasm
ld
Warning
Currently this program only works on Linux
-
Clone the repo
git clone https://github.com/nikkehtine/hydrogen.git
-
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 filesclean
: compile and run the program, but delete generated filescleanup
: just delete any generated output files that exist
- Compiling
- Parsing
- Tokenization
- Variables
- Expressions
- PEMDAS
-
if
statements and scopes
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 :)