A compiler for the SPL language. Useful for learning how to do compiler construction.
Haskell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
AST.hs
Combinators.hs
IR.hs
Intel.hs
Main.hs
MaybeCombinators.hs
Parser.hs
README.textile
SSM.hs
Scanner.hs
Typing.hs

README.textile

SPL Compiler

This project is a compiler for a small imperative language named SPL (Simple Programming Language). The compiler is written in Haskell and is fully working. It only makes use of the basic Haskell modules and contains as little hacks as possible.

This project is suited for developers interested in learning how a compiler is built. The code is clear and consise.

Compiler features:

  • Built-in parser
  • Type checking (and basic inference)
  • Intel x86 backend

Language features

  • C-style imperative language
  • Support for lists and tuples
  • Full support for generic types

Example SPL:

[t] reverse ([t] list)
{
	[t] accu = [];
	while(!empty(list))
	{
		accu = head(list) : accu;
		list = tail(list);
	}
	return accu;
}

Compilation

First, compile the compiler:

ghc -o splc --make Main.hs

Then, generate the Intel assembly of a .spl file with:

./splc hello_world.spl > hello_world.asm

Save the assembly code from the output to a .asm file. Finally, create the executable:

nasm -f elf hello_world.asm
gcc -m32 -o hello_world hello_world.o