Berserk wrote:
Hey Hey,
hold on...i didn't say that i was going to jump in and start making a compiler while making an OS, NO WAY.]
I was just asking, what would it take to make one??
Here are what I would consider the rock-bottom requirements for compiler programming:
- Time
- Patience
- a lot of programming skill in the implementation language
- A good understanding of the assembly language (or p-code) that you are compiling into
- The ability to read and design BNF grammars and/or 'railroad' style syntax diagrams
- A clear idea of what language you want to implement, both the syntax and semantics
- A basic understanding of the four main stages of a compiler: lexical analysis, parsing, semantic analysis, and code generation.
It is entirely possible to write a passable compiler with just these things, using a hand-coded recursive-decent parser; see the
Small-C page for a[n in]famous example. The results are usually a bit crude, and far from optimal, but they do work.
Tools that could be useful include:
- A byte-code interpreter (which makes an easier target than a real processor, and is usually a bit more portable; the Java Virtual Machine and UCSD p-System are two classic examples of this)
- a lexical analyser generator such as
LEX or Flex
- a parser generator such as YACC,
Bison,
CUP,
ANTLR, etc. A google search on 'parser generator' will turn up dozens; you should have no trouble finding one you like.
That's about it; the hard part is learning how to do it. Expect to do a lot of study on it, and a lot of practice at toy languages and toy compiilers, before you can do anything serious. However, like many other things, it is worth the effort, in that it will help you understand other aspects of programming better.
As difficult as compiler programming is, language design is an order of magnitude harder - but that hasn't stopped people like Chuck Moore (the designer of FORTH) from coming up with interesting ones despite a total lack of experience. If you think you really know how to build a better mousetrap, don't feel shy about trying it out. YMMV.
HTH.