Ishihara
Ishihara

Reputation: 1117

Good languages to write a compiler for

I'm thinking of writing a compiler in haskell, and just to gain some knowledge and experience, I will try to implement compilers for existing languages. Could someone give me a list of languages which are suitable for this?

Thanks in advance

Upvotes: 4

Views: 4191

Answers (7)

Jörg W Mittag
Jörg W Mittag

Reputation: 369420

Scheme is often used for this. There's even a tutorial called Write Yourself a Scheme in 48 hours for Haskell.

Upvotes: 7

Phillip
Phillip

Reputation: 81

PL/0 is a simple language that was created to teach compiler construction. Samuel Williams wrote a compiler for it in Python (along with a virtual machine) for the benefit of students: http://www.oriontransfer.co.nz/learn/pl0-language-tools/index

Upvotes: 2

Wildcat
Wildcat

Reputation: 8870

Oberon-2. Like Lua has short context-free grammar.

P.S. Here you can find Oberon-2 compiler written in Objective Caml.

Upvotes: 3

SK-logic
SK-logic

Reputation: 9714

Pascal could be a good start - you can compile it in a single pass. A subset of Lisp might be useful in order to grasp the idea of the lambda lifting. ML or even a subset of Haskell might help you in understanding the type inference. Consider using LLVM as your back-end, it will save you some time on implementing boring stuff.

Upvotes: 8

EvilTeach
EvilTeach

Reputation: 28837

The world always needs another c compiler :)

Upvotes: 3

sheepez
sheepez

Reputation: 1012

As far as I know one of the easiest languages to compile is Forth. I think it's quite achievable to write a compiler for Forth in Forth even for a relative novice.

Upvotes: 1

Rafe Kettler
Rafe Kettler

Reputation: 76945

The simplest languages to write compilers for are existing "esoteric languages", like brainfuck, because they have the smallest instruction set and the simplest grammar. You can try your hand at a more complex language, but it's better to get the fundamentals down with something simple before moving any further.

Upvotes: 4

Related Questions