Re: how to write a new programming language? (Torben Ęgidius Mogensen)
31 Mar 2003 13:37:59 -0500

          From comp.compilers

Related articles
how to write a new programming language? (2003-03-30)
Re: how to write a new programming language? Nonahin@yaHoo.coM (LeeB) (2003-03-30)
Re: how to write a new programming language? (2003-03-31)
Re: how to write a new programming language? (Joachim Durchholz) (2003-04-05)
| List of all articles for this month |

From: (Torben Ęgidius Mogensen)
Newsgroups: comp.compilers
Date: 31 Mar 2003 13:37:59 -0500
Organization: Department of Computer Science, University of Copenhagen
References: 03-03-175
Keywords: design
Posted-Date: 31 Mar 2003 13:37:59 EST (scratch) writes:

> If I would like to create a new language from scartch. What should I
> do? which tools would help me?

You should first ask yourself why you want a new language, i.e., which
problems the language is going to solve that can't easily be solved
using existing languages. A domain-specific language is a good
candidate for such. If you just want to do this for the exercise,
i.e., don't care if anyone (including yourself) will ever use the
language, this of course doesn't matter at all.

You should then think of a few examples of problems in the intended
domain and try to figure out what kind of features and notation you
would like to solve these. Make a few program sketches to settle on a
notation (but be prepared to change details later).

Once you have a good idea of the syntax and semantic of the language,
you can strat to implement it. The easiest is probably using a lexer
and parser generator for the syntax part. Such exist for virtually
all languages. To implement the semantics, you have several choices:

  1) Write an interpreter

  2) Write a compiler to an existing programming language.

  3) Write a compiler to assembly language.

The first of these options is usually the simplest, especially if you
use an expressive language (e.g. a functional language) to write the

The second options isn't very much more difficult and you have the
option of using different languages for the compiler and the
implementation language, e.g., SML or Haskell for the compiler and C
for the target language. Also, it makes it easy for your language to
call functions in the target language.

The third option is much more difficult and should only be attempted
if you really want to extract the last ounce of performance from the
machine, or if you want to learn about "real" code generation.

Torben Mogensen

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.