1

This is my first question so be nice lol...

Think of it this way. Python is written in C, which is written in an older C compiler, which is written in an even older C compiler, which is written in B, which is written in (I think) BCPL. I am not sure what BCPL is written in, but it seems that there must be an original language somewhere?

In other words, every programming language is written in an older programming language. So what came first, and what was that coded in?

fartgeek
  • 135
  • 1
  • 3
  • 3
    Does this answer your question? [How do I create my own programming language and a compiler for it](https://softwareengineering.stackexchange.com/questions/84278/how-do-i-create-my-own-programming-language-and-a-compiler-for-it) – whatsisname Oct 15 '20 at 01:07
  • 1
    [It's turtles all the way down.](https://en.wikipedia.org/wiki/Turtles_all_the_way_down) – davidbak Oct 15 '20 at 17:19
  • Wikipedia article: [History of compiler construction](https://en.wikipedia.org/wiki/History_of_compiler_construction) – rwong Nov 22 '20 at 06:02

3 Answers3

8

What are programming languages written in?

Programming language compilers and runtimes are written in programming languages — not necessarily languages that are older or are different than the one they take as input.  Some of the runtime code will drop into assembly to access certain hardware instructions or code sequences not easily obtained through the compiler.


Once bootstrapped, programming languages can self-host, so they are often written in the same language they compile.  For example, C compilers are written in C or C++ and C#'s Roselyn compiler is written in C#.

When the Roselyn compiler adds a new language feature, they won't use it in the source code for the compiler until it is debugged and working (e.g. released).  This akin to the bootstrapping exercise (limited to a new feature rather than the whole language).

But to be clear, there is the potential (and often realized) for the programming language to be written in the latest version of its input language.


So what came first, and what was that coded in?

Machine code came first, and the first assemblers were themselves very very simple (early assembly languages were very easy to parse and generate machine code for), they were written in machine code, until bootstrapped and self-hosted.

Erik Eidt
  • 33,282
  • 5
  • 57
  • 91
7

Each machine has an instruction set it natively executes.

That instruction set is the first language.

The first higher level language was assembly, literally allowing the programmer to write a long expression like mov ax bx instead of the corresponding binary word.

The first compiler was written in machine language, though more accurately it would have been called an assembler but today's standards. It would have taken the assembly language and translated it to the binary encoding.

This has happened many times over for many different machines until the first cross-compilers were developed that could rewrite a program into another machine language.

Even now though there are still languages who are first implemented in terms of a machine language.

Kain0_0
  • 15,888
  • 16
  • 37
  • All true, but worth pointing out that even before we had the actual machines we had the instruction sets. This all used to just be mathematics that ran in our heads. We've come a long way. – candied_orange Oct 15 '20 at 01:05
  • @candied_orange True, Lambda the Ultimate – Kain0_0 Oct 15 '20 at 02:42
7

Think of it this way. Python is written in C,

No, it is not.

You seem to be confusing a Programming Language like Python or C with a Programming Language Implementation (e.g. a Compiler or Interpreter) like PyPy or Clang.

A Programming Language is a set of semantic and syntactic rules and restrictions. It is just an idea. A piece of paper. It isn't "written in" anything (in the sense that e.g. Linux is "written in" C). At most, we can say it is written in English, or more precisely, in a specific jargon of English, a semi-format subset of English extended with logic notation.

Different specifications are written in different styles, here is an example of some specifications:

There are multiple Python implementations in common use today, and only one of them is written in C:

In other words, every programming language is written in an older programming language. So what came first, and what was that coded in?

Again, you are confusing Programming Languages and Programming Language Implementations.

Programming Languages are written in English. Programming Language Implementations are written in Programming Languages. They can be written in any Programming Language. For example, Jython is a Python implementation written in Java. GHC is a Haskell implementation written in Haskell. GCC is a C compiler written in C. tsc is a TypeScript compiler written in TypeScript. rustc is a Rust compiler written in Rust. NSC is a Scala compiler written in Scala. javac is a Java compiler written in Java. Roslyn is a C# compiler written in C#.

And so on and so forth, there really is no restriction on the language used to implement a compiler or interpreter. (There is a theoretical limitation in that an interpreter for a Turing-complete language must also be written in a Turing-complete language.)

Jörg W Mittag
  • 101,921
  • 24
  • 218
  • 318
  • *Programming Languages* can also be written in *Human Languages* other than English. – user253751 Oct 15 '20 at 10:51
  • Now that the difference between language and language implementation is clear, the question remains the same (or almost) _What are programming languages implementations written in? Not complaining about this answer (which I like!) but it does not fully respond to the "implicit" question. Otherwise would be the perfect answer – Laiv Oct 15 '20 at 11:41
  • As @Laiv says, although this highlights the difference between the languages and their implementations, the question still stands. All implementations are written in other languages, on and on and on... – fartgeek Oct 15 '20 at 16:19
  • @Laiv: I am answering that question in the last two paragraphs: language implementations are written in languages. Now, if you want to know *specifics*, then I cannot answer that. Programming language choice is often a subjective personal choice, so they are written in whatever language the author chooses to. – Jörg W Mittag Oct 15 '20 at 16:27
  • @fartgeek: Programming language choice is often a subjective personal choice, so a language implementation will typically be written in whatever language the author likes. I personally like Scala and Ruby, so if I had to implement a language, I would likely do it in Scala or Ruby, but that is a completely personal choice, and someone else may choose a different language. – Jörg W Mittag Oct 15 '20 at 16:28
  • `tsc` was written by the people who design TypeScript. Naturally, the people who design TypeScript like TypeScript, so they chose to write the compiler in TypeScript. GraalPython is developed by Oracle. Naturally, Oracle likes Java, so GraalPython is written in Java. Rubinius is developed by Ruby programmers. Naturally, Ruby programmers like Ruby, so they wrote it in Ruby (and C++). PyPy is a little bit more interesting: PyPy is created by Python programmers, so what they did is they designed a new language that makes it easy to implement languages, implemented this language in Python, then … – Jörg W Mittag Oct 15 '20 at 16:34
  • … implemented Python using this language. – Jörg W Mittag Oct 15 '20 at 16:35
  • @JörgWMittag that answer is also legit. On the other hand, what do you think about Kain0_0 answer? Would you say it's wrong or not acurate? – Laiv Oct 15 '20 at 16:35