A HEAR (C-like) compiler written in Haskell
This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
Go to file
Ethan Reece d64ad9aeda
Parse printInt instead of print
2023-10-08 00:23:13 -05:00
.vscode Generate LLVM code and print to console 2023-09-28 23:42:59 -05:00
example Parse printInt instead of print 2023-10-08 00:23:13 -05:00
src Parse printInt instead of print 2023-10-08 00:23:13 -05:00
.gitignore Write llvm to file 2023-09-29 02:29:05 -05:00
CHANGELOG.md Cabal init 2023-09-07 17:24:45 -05:00
README.md Parse expressions into different types 2023-10-07 22:46:37 -05:00
package.yaml Add command line argument parsing 2023-10-06 23:55:57 -05:00
really-bad-compiler-in-haskell.cabal Parse expressions into different types 2023-10-07 22:46:37 -05:00
stack.yaml Fix haskell language server broken 2023-10-06 00:29:36 -05:00
stack.yaml.lock Remove llvm-hs-pretty since it was generating broken code 2023-09-29 05:19:11 -05:00

README.md

HEAR Compiler in Haskell

A compiler for HEAR, a language for when you cannot C.

Written in Haskell, and currently using the megaparsec and llvm-hs-* libraries, but I plan to eventually rewrite the lexar/parser from scratch. Built for the Introduction to Compiler Design class at The University of Texas at Dallas.

Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell

Setup Instructions

  • Install ghcup (for managing Haskell tools) and nix (for managing external dependencies).
  • Clone the repo.
  • Use ghcup to install stack 2.11.1, HLS 2.3.0.0, and cabal 3.8.1.0.

Run Instructions

  • Use stack run <file> to run the program (for example, stack run example/1.hear).
  • The LLVM will be generated as a.out.ll, and the executable will be generated as a.out.

Currently Supported functionality

  • Arithmetic
  • Parenthesis
  • print() statement

To edit

I recommend using VSCodium, which is preconfigured to have syntax highlighting and (currently broken) debugging features and will automatically suggest the Haskell extensions to install.

Known bugs

Building

  • If llvm_16 is in the nix store, stack will use it for some reason and the build will fail. Currently, you may need to run nix-store --delete /nix/store/<llvm16devdirectory> to build it.

File structure

  • app - contains the compiler program
  • example - contains example programs that can be compiled

Credits

Learning Resources Used

Tools

  • Language: Haskell
  • Haskell/management tools: GHCup, Stack, Cabal, GHC 9.2, Nix
  • Libraries: See package.yaml
  • Dependencies: llvm 15, clang 15
  • IDE: VSCodium
  • Git platform: Forgejo
  • AI: Phind (GPT-4), ollama (codellama)
  • Search: Kagi, Stack Overflow