Creating Your Own Programming Language - Computerphile

preview_player
Показать описание
What's in a language? Dr Laurie Tratt breaks it down by creating a brand new programming language by writing an interpreter in a few lines of code.

Dr Laurence Tratt is programmer and the Shopify / Royal Academy of Engineering Research Chair in Language Engineering in the Department of Informatics at King’s College London

This video was filmed and edited by Sean Riley.

Рекомендации по теме
Комментарии
Автор

Made a small one in my teens, a commenter wrote on sourceforge I had no idea what I was doing ... they were right

sundhaug
Автор

Proving the Turing completeness of this programming language is left as an exercise to the viewer.

firaskallel
Автор

A fun excercise - I always thought such things would be purely academic, but I wound up writing a custom sort of query language for a work project. It was to allow non or less technical staff to write their own custom tests for some tooling I'd created. Devilishly hard to actually get right end to end - huge amounts of considerations around data types, parsing, things like brackets, ands ors. But I got there and it works well.

regiondeltas
Автор

Q: Why do programmers have such big egos?
A: So there's something left after the compiler gets done telling them how bad they are at their job!

Ice_Karma
Автор

i wrote a compiled imperative language in rust :) writing a compiled language is probably the most educational project that exists ever, because you learn (on a deep level):

- how memory works (including pointers, allocator kinds aka stack, region, heap, temp, gc, etc, how stack frames work)
- how compilers work (lexer -> parser -> pre-IR for semanalysis -> compilation to IR -> asm -> object code -> linked into executable)
- how to maintain a larger scale project (with potentially 10k+ lines of code)
- how to structure a larger scale project (with project file names and splitting of code into different files/functions etc)
- best practices in terms of data structures to use (Array vs HashMap vs HashSet, null terminated string vs sized string, etc)
- abstract syntax trees and/or grammar (including different parsing algorithms for operator precedence if you write your own parser (as you should) such as recursive descent or shunting yard)
- how to debug potentially thousands of lines of code,
- how modern language features actually work under the hood (for example, loops and conditionals being compiled into just jumps, monomorphization vs dynamic dispatch for generics on structs and/or functions, capturing lambdas and their environments, etc etc)
- how to use tooling to your advantage
- how to effectively test your code

among others. i think there is not a project that ticks more boxes at once than writing a compiled language. plus its really fun seeing it slowly expand and being able to do more things over time :3

acquite
Автор

A long time ago, I made a simple stack-based esolang (esoteric programming language) called "Noy", because it used every letter of the English alphabet except Y. (Alternatively, I also called it Alphabet Soup.) It had two stacks: a main stack and a temp/scratch stack that you could transfer to and from. Operations were a single letter each, attempting to be mnemonic (all I remember was "k" for "kick to temp stack" and "u" for "unkick from temp stack"). Digits were also a single letter each ("a" through "i"), and to get bigger numbers you'd have to just operate on the digits you pushed. Every programming language, therefore, was just a string of letters, without any symbols, numbers, whitespace, or line breaks.

I made an interpreter for it in JavaScript, C++, and PHP (JS and PHP were my go-to languages at the time).

Totally useless, but also really fun to make 😁

IceMetalPunk
Автор

I like to follow, and implement when possible, this way of sharing knowledge when introducing a topic:
- No frameworks
- No add ons
- Code something practical, pause, ask questions, implement the answers.

Very nice explanation Dr. Tratt

sebastiantomasalvarez
Автор

Making programming languages has always fascinated me as I always thought "But don't you already need a programming language to make one. And how is your programming language a language if it needs the original language to work?"

TheStevenWhiting
Автор

The language should've been called Splits because it's an excellent demo on how far split carries software design 😊

SimGunther
Автор

20:35 "No one uses reverse polish notation in a real language"... Forth begs to differ! A quirky but really fun and powerful language once you get your head around it 😆

Автор

Interpreter being interpreted by an interpreter...
- C/C++ programmers fuming
- integrated circuits screaming in fear
- memory controller in shambles
- LLVM crying

nekrosis
Автор

Small piece of advice: write out full variable names. For somebody just starting out in programming, toks and ev don't mean anything. Tokens and eval is more expressive and it's just a few more keystrokes.

verticallife
Автор

Funny, I just did a video on writing a basic FORTH in ZIG 3 weeks ago. RPN should've been our mathematics notation over infix, I stand by that. Not only makes programming interpreters easier but also gets rids of all the priority rules you need to remember.

CallousCoder
Автор

Reverse Polish Notation is awesome. I love the consistency of not needing parentheses. Begone, operator precedence.

P-_Airacobra
Автор

Look at you implementing a PostScript interpreter right on screen!

ShaunCKennedyAuthor
Автор

For a programming language to be useful, you need:
1. PC
2. Conditional Branching
3. Indirection (pointer)

With those, you can implement loops, variables, and arrays. Then, move on to stacks, queues, and lists.

Operator precedent isn't that hard to do. Well, Dijkstra algorithm one is hard to understand. I personally used 3 stacks algo. 2 stacks if you don't mind right to left parsing.

I don't understand why Tiny BASIC has FOR loops but not WHILE loops. From experience, I can say that implementing WHILE/REPEAT loops are easy. FOR loops may be easy to compile, but not interpreted!

TinyBASIC is surprisingly close to assembly language, imo, that I'm surprised that not more people are working on it!

simpletongeek
Автор

Why is it that academics always seem to write least readable code. It's no longer 1983, we have space for variable names longer than two characters.

MladenMijatov
Автор

As many here I tried a few times, however I used Bison/YACC instead because I was at university and we were learning compilers and I decided to go a step ahead and start learning Bison and all that. I also uploaded it at Sourceforge. This was for a strategy game which where you would write script, feed it to the game so that the game would execute them would play the game until the end, then you would have to rewrite the rules to handle events, attacks and invasions and continue improving the script. Writing the parser itself was the easiest part, though, once Bison clicked. Unfortunately (and with most things) once I reached the point to start writing graphics code I gave up.

refactorear
Автор

Great intro to writing your own programming language!

sanderbos
Автор

His enthusiasm is really infectious :D

kodaklen