Page 1 of 1

Compilers

Posted: Wed Feb 11, 2004 5:37 pm
by Guest
Hello :) ,
How to create my own compiler and which language is good for that ?

Re:Compilers

Posted: Wed Feb 11, 2004 9:31 pm
by Schol-R-LEA
You don't ask for much, do you? ;)

While there are several ways to write a compiler, there are really only two practical approaches: either write it using a LL(1) pattern-matching recursive-descent parser that emits code more or less directly, or use compiler-generator tools for the lexer and parser (i.e., LEX and YACC) and write a semantic analyser and code generator that uses their output.

Either way, you waill want to have as complete a BNF grammar for the language you'll be compiling as you can, and as specific a description of the semantics as possible. The grammar is particularly important, as you'll be building your parser directly from it; but an unambigous semantics is also important, otherwise the language may not always do what you expect.

You can in principle use any language you wish to. However, there are some languages which are better suited than others; the ones I would most strongly recommend are Java, Scheme, Icon, or (believe it or not) Prolog. That having been said, most compilers today are written in C, and most compiler-generators are designed to work with C preferentially.

You may want to read a few of the following threads for more information:

Making a Compiler?
OS Dev Compiler
Finding Simple Codes of Compiler
Making your own programming language?

Re:Compilers

Posted: Mon Feb 23, 2004 7:52 am
by sdkub
it might be a lot easier a (lisp) interpreter instead ..

Re:Compilers

Posted: Tue Feb 24, 2004 2:20 am
by Schol-R-LEA
sdkub wrote: it might be a lot easier a (lisp) interpreter instead ..
Certainly true. However, not everyone has seen the light yet. 8)