/haskell-c-compiler

Learning Haskell for the first time and using it to write a simple C compiler

Primary LanguageHaskellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Haskell C Compiler

About

Writing a (very simple) C compiler in Haskell based on these tutorials and other resources:

First time writing Haskell or a compiler.

(Planned) Features

  • Lexer -> Parser -> Semantic Analyzer -> x86 assembly generator
    • Assembly will be fed into GCC to produce machine code
  • Operators: =, ==, >=, <=, >, <, !, +, -, \*, /
    • Maybe some bitwise operators too
  • Control flow: if, while
    • Wanna keep this simple, might add else as well
  • Types: int, int*, int[], char, char*, char[]
    • Probably will support & for getting variable addresses too
  • Basic inline asm support, so we can do syscalls and such
    • Might just do a syscall() keyword instead..hmm

(Planned) Limitations

  • No global variables planned. A program is just a list of functions
    • Might change my mind on this
    • Might support function declaration ahead of definition
  • No operator precedence planned...everything is currently right-associative. Use ()!
  • No preprocessor planned (no #defines, #includes etc
  • No program arguments (no char**)
  • No comments! These would be easy to add (only requires changes to lexer) but it's just more time
  • No function pointers
  • No structs
  • No casts
  • No array {} initialization