Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming language and compiler

I was having this discussion with my friend and realized this might be the best place to ask this question ?

How is a new language born ? This new language NEW must be written in some old language OLD (eg C++ was written in C in initial stages), or how is this created ?? And, how does this language NEW can work itself if there is no compiler for it ? So, there must be some compiler for it ? Who writes compiler for it ?

So, how does all this work together, new language and its compiler, relation of new language with its old base language ?

like image 636
seg.server.fault Avatar asked Jul 23 '09 18:07

seg.server.fault


4 Answers

You write the compiler in an implementation language until such time that the compiler can begin to compile enough of the new language to be used to implement the rest of the new language.

That's how it works.

Edit: Just to clarify, the commentors on this answer are also correct. The compiler doesn't HAVE to be written in the new language unless you want to. As said, some don't go that route and stay with the original implementation language.

like image 189
Robert Rouse Avatar answered Nov 03 '22 01:11

Robert Rouse


Bootstrapping is a term used in computer science to describe the techniques involved in writing a compiler (or assembler) in the target programming language which it is intended to compile. This technique is also called self-hosting.

like image 34
xian Avatar answered Nov 03 '22 00:11

xian


You may want to read up on programming language design and compiler design:

http://dragonbook.stanford.edu/
Bootstrapping (compilers)
http://en.wikipedia.org/wiki/Programming_language
http://www.paulgraham.com/langdes.html

Or, take a course or three at your local university.

like image 38
Ether Avatar answered Nov 03 '22 01:11

Ether


The heart of any language is the linker and compiler, the compiler which converts source code into intermediary, very close to machine code, code. From this point, linkers are used to attach it to other binaries such as libraries, etc. After the binaries are linked to all logical pieces, they become an executable file in machine code (or translatable intermediary code as it is with .NET/Java).

The most translating from "human" english happens in the compiler, and there are great articles on how this is done... but to most of this it is in the realm of the supernatural, as the organizational skills required to write a working compiler are immense.

You can see the surface level sorts of translations and get a closer look at how compilers work by looking at language definitions (Bjarne Stroustrup's "The C++ Programming Language", Microsoft Press's "The C# Programming Language"), where both the appendixes and peppered throughout are lexical pieces, or rules which the compiler will use to translate your words into machine code in a very logical way.

I highly recommend reading the language definition of your favorite programming language if you wish to understand more, also the wikipedia article on compilers will give you a broader understanding.

like image 45
Sprague Avatar answered Nov 03 '22 00:11

Sprague