What does the code that makes up programming languages look like?

1.05K views

Take a language like Java. How was it originally created? I can’t wrap my head around how someone invented a computer language to run without having some “prior” language that it allows the first lines to function. Is it just Java all the way down, like someone wrote a single line of Java and then every other line was built on that?

What about the first computer language? What was the basis that that functioned on?

Thanks for any help, I hope that was phrased in a mildly intelligible way.

Edit; I’m trying to think of it like human language: at some point there was a first “word” spoken by someone and understood by another and from there the structure started to be born. What were the first “words” on a computer that led to where we are now?

In: Technology

36 Answers

Anonymous 0 Comments

One way to think about it:

You have to build the first hammer by scratch. But after that, you can use that hammer to help build the rest

Anonymous 0 Comments

TLDR:

You use older programming languages to teach the computer to understand newer programming languages. The first programming languages were taught directly to the computer by writing their machine code (the thing the computer actually understands itself) directly.

Longer answer.

You use programming languages to make programming languages. Programming languages come in two varieties (generally). Compiled and interpreted.

Compiled languages are translated down to assembly or machine code, something the computer understands by virtue of it’s design. Here you “create a language” by writing a program in a different language that takes code written in your new language and turns it in to machine language. You can later rewrite that compiler in your new language to detach it from the old language.

Interpreted languages are translated on the go. Here you have a program that takes the code written in your new language, looks at it, and tells the computer directly what to do.

Java is interpreted. The JVM that runs Java code has a few versions but the most common are written in C or C++.

the “First” programming languages were taught to computers by directly writing the machine code for them by hand in to memory of the computer. Depending on how old you want to go this can be applied with literal switches on the side of the computer, punch cards, or a keyboard that you can type in to the computer’s memory.

Anonymous 0 Comments

Here, I wrote a JavaScript compiler in JavaScript:

“`
Function(prompt())()
“`

(This is actually a joke, lol)

Anonymous 0 Comments

Fyi: there are plenty of videos on youtube where people make new languages for shots and giggles. There are also core operating system development videos too.

Anonymous 0 Comments

TL;DR: To make a brand new language for your computer, you will need to write a Parser so that the computer can “read” the code in your new language. And then you will need to write a Compiler so that those instructions can be completed.

Code is just instructions that computers can understand and follow. For example, if you say, in Java, System.out.println(“Hey, Good morning!”) the text “Hey, Good morning” will appear on the screen.

So let’s imagine you wanted to make your own programming language. Your first step might be to plan out the rules that a human programmer would use to write code in your language. The rules a programming language uses to express ideas and instructions is called the language’s “syntax”. A language can be extremely simple. But the most popular languages have a complicated syntax so that they can do a lot of different things.

For example, valid HTML syntax allows you to put images and text on a web page. CSS might not be considered a real language because it is so limited in what you can do. All it can do is change the colors and positioning of things on a web page. But for the purposes of what you’re asking about, it is a language. It gives the programmer a way to tell the computer what to do. Valid Python syntax, or C++ syntax, or Java syntax, or JavaScript syntax allows you to do pretty much anything a computer can do. Not just because the syntax is so expressive and complicated, but also because there are tons of libraries that people have built that allow code written in those languages to do a bunch of different things.

So now the programmer has written some code in your new language. How does the computer run it? Well the code gets sent to a program in charge of running code in that language. For example, your computer has Java and Python installed so that it can run Java and Python code.

The first step to running the code is to Parse the code with a Parser. This looks at the programmer’s code one character at a time to try to understand what the programmer is doing. If you have a new language you have to write a new Parser. The code you write for the Parser will be based on the syntax you came up with for your language. If the programmer wrote code incorrectly it may result in a Syntax error. For example, maybe your Syntax says you can comment out text that appears after a double forward slash. In that case, your parser would have code that recognizes the double forward slash and ignores the text until the end of the line.

The next step to running the code is to compile the code. The computer does stuff by sending bytes (1s and 0s) to the CPU. The CPU will come with instructions on how to use it. This is called an instruction set. For example, “x86” or “ARM”. Before the computer can start executing your code, it needs to converted to the correct order of 1s and 0s called “Bytecode”. This is what a Compiler does, it takes the ideas that were parsed by the Parser and converts them to Bytecode. You will have to create a Compiler for your new language yourself. And the resulting Bytecode should be different for each different type of Instruction Set you want to support. For high level languages, the compiler might be written in C or C++ and then compiled to Bytecode before being run to compile your code. For lower level languages, the compiler might be written in Bytecode by hand.

The CPU can run the bytecode because of how the circuits are designed and how electrons react traveling through the circuits. Originally computers used wires to create circuits. But nowadays we can print teeny tiny circuits called microchips.

Anonymous 0 Comments

Like you’re 5?

You first learn to make letters. Then you learn how to make words out of those letters. Then sentences, and paragraphs, and …. eventually you’re at Wikipedia.

Computer chips do simple things. If you put enough simple things together, you can do something complicated. If you put enough complicated things together, you can do something REALLY complicated.

Anonymous 0 Comments

> Take a language like Java. How was it originally created?

In some other language, most probably C. I am sure some parts of JVM would still be just plain old C, which is almost a direct translation to Assembly.

> What about the first computer language? What was the basis that that functioned on?

It would have been a simple AND/OR gate someone made using diodes (not semiconductor diodes – those big old ones). Then, perhaps a simple circuit using it, trying to create something like a calculator. The basis for its functioning was diodes – assymetrical behavior in two directions.

> I’m trying to think of it like human language: at some point there was a first “word” spoken by someone and understood by another and from there the structure started to be born. What were the first “words” on a computer that led to where we are now?

Think of it as a heap. Do two grains of wheat make a heap? Do a million grains of wheat make a heap? At what number will you say grains of wheat make a heap?

Similarly, you wouldn’t call a pulley a computer, but a modern PC definitely is one. Where you start calling stuff to be a computer is where you define the first word.

Anonymous 0 Comments

This is a pretty good video explaining how machine code works:

I’ll try to ELI5:

When you build a computer chip it can perform some very elementary set of tasks. In order to make that chip useful, it is programmed with “microcode”. That microscope exposes to the user a VERY simple set of machine instructions. We call this “machine language” This machine language is extremely abstract with everything being represented by numeric codes. For example a 2 byte sequence AB 04 might mean “load the number 4 into the X register of the CPU”. CD 06 might mean add 6 to the value in the X register and store the result in the X register. 4C 5A 44 might mean store the value in the X register in memory location 5A44, etc. Machine code is EXTREMELY tedious to use, as you might imagine.

So, what kinds of programs might one write in machine code? Well, technically anything. If you’re a masochists. But among the first machine programs written was probably an Assembly Language compiler. What does a compiler do? It reads in some data and outputs computer code. To write a compiler you might define an “Assembly language” that allows users to write code that looks like this and store it in a text file.

LDX 4
ADX 6
STX 5A44

An assembly compiler could then read that file and create machine code from it, converting our text file into code the computer can actually run:

AB 04 CD 06 4C 5A 44

What kinds of programs can you write in Assembly? Well, technically anything but among the early assembly language programs written was a compiler for an even higher level language, like “c”. This compiler might let me write a program that looks like this:

counter := 4;
counter := counter + 6;
store_mem(5A44, counter);

We call these 3rd generation languages. But what if you want to write a coding game for kids where they write programs just by dragging icons around? What do you think that coding game does? It turns those squares and arrows in the kids programming game into C or assembler or some other language which in turn gets compiled into machine code. We call this type of code “4GL” or 4th generation language.

In short, we use super low level languages to write compilers or interpreters which allow us to write more human readable code, but that code just ends up getting “translated” back into a lower level language. At the end of they day, the only code your computer actually runs is machine code, everything else is just a layer of abstraction built on top of machine language.

Anonymous 0 Comments

[removed]

Anonymous 0 Comments

On a related note, how do we turn electricity into symbols and letters, and then how do we make those symbols redirect electricity and run programs? We literally turn electricity into something intelligent and I will NEVER understand how.