r/AskComputerScience • • Jul 11 '16

How do you program a programming language?

I.e. How do you get a computer to understand a language? How does it actually make the transition from that language into assembly language?

45 Upvotes

18 comments sorted by

View all comments

16

u/simonorono Jul 11 '16

First, you define your language. Define its syntax, its semantics, everything.

Then, it comes the hardest part: developing a compiler/interpreter for it.

A compiler is just a translator, it takes source code from the language you defined and pours the equivalent program in another programming language (generally, with a lower level).

For example, the C compilers, read C code and translate them to assembly, them an assembler converts this assembly code into an executable.

3

u/trenchgun Jul 12 '16

So C-compiler is written in assembly? And assembler is written in machine code?

12

u/Teslatronic Jul 12 '16

The first compilers/assemblers were. But once you write one C compiler in assembly, you can write another one in C itself, and use the assembly-based compiler to compile the C-based one, and then compile each new version of the compiler with the previous one. This is called bootstrapping.

Edit: see /u/bhrgunatha's comment for more detail.