Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

General Purpose Language to build a compiler for

Inspired by Eric Sink's interview on the stackoverflow podcast I would like to build a full compiler in my spare time for the learning experience. My initial thought was to build a C compiler but I'm not sure whether it would take too much time.

I am wondering if there is a smaller general purpose language that would be more appropriate to implement as a first compiler effort? Or is a C implementation doable on a reasonable timescale (200 hrs)?

It is my intention to target the CLR.

like image 896
Brownie Avatar asked Jan 20 '09 12:01

Brownie


2 Answers

You'll be happiest writing compilers for older, smaller languages. Pascal, for example, were designed as learning tools. The Pascal language is small and elegant; the compiler can be written fairly simply.

Even an Oberon or Modula-2 compiler is similar in complexity to Pascal; their design was driven by the same person, Niklaus Wirth.

Languages like C, which evolved organically, are too full of quirks to be good learning experiences.

like image 147
S.Lott Avatar answered Nov 10 '22 23:11

S.Lott


Write a Scheme compiler.

See: An incremental approach to compiler construction

like image 39
squadette Avatar answered Nov 11 '22 01:11

squadette