Show HN: A toy compiler I built in high school (runs in browser)

  • Posted 11 hours ago by xeouz
  • 3 points
https://vire-lang.web.app
Hey HN,

Indian high schooler here, currently prepping for JEE, thought itd be nice to share here.

Three years ago in 9th/10th grade I got a knack for coding, I taught myself and made a custom compiler with LLVM to try to learn C++. So I spent a lot of time learning LLVM from the docs and also C++. It's not some marvelous piece of engineering,

I designed the syntax to be a mix of C and what I wished C looked like back in 9th grade.

It has:

  - Basic types like bool, int, double, float, char etc. with type casting
  - Variables, Arrays, Assign operators & Shorthands
  - Conditionals (if/else-if/else), Operators (and/or), arithmetics (parenthesis etc)
  - Arrays and indexing stuff
  - C style Loops (for/while) and break/continue
  - Structs and dot accessing
  - extern C interop with the "extern" keyword
Some challenges I faced:

  - Emscripten and WASM, as I also had to make it run on my demo website
  - Learning typescript and all for the website (lol)
  - Custom parser with basic error reporting and Semantic analysis was a PITA for my undeveloped brain (I was 15)
  - Learning LLVM from the docs
Important Learnings:

  - Testing is a very important aspect of making software, I skipped it - big regret
  - Learning how computers interpret text
  - Programming in general was a new tour for me
  - I appreciate unique_ptrs and ownership
Github: https://github.com/xeouz/virec

Its on my github and there's a link to my web demo (https://vire-lang.web.app/), it might take some time to load the binary from firebase.

Very monolithic, ~7500 lines of code, I’d really appreciate any feedback, criticism, or pointers on how I could’ve done this better.

1 comments

    Loading..