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

1.13K 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

> 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

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

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.