How to Write a Programming Language

By Andy Balaam

It sounds too difficult for mere mortals, but in principle a programming language interpreter is a relatively simple program. To demonstrate the main ideas involved, I wrote a very simple programming language called Cell (github.com/andybalaam/cell) and in this session we will walk through how it works.

Cell’s interpreter is written in Python, and the Cell language itself is designed to be as simple as possible to implement. This leads to some different trade-offs from most other languages, but hopefully leaves the main concepts intact.

We will walk through the code of Cell’s lexer (40 lines), parser (81 lines) and evaluator (92 lines) and on the way cover the main ideas you need to write your own language, including detecting the different symbols and literals the programmer wrote, building them up into a tree structure, evaluating the logic that is being represented, and writing a standard library of basic functions and structures.

This session is suitable for someone who has never thought of writing a programming language before. We will assume a working knowledge of Python code in places, but it should be simple enough to follow for anyone who regularly writes code in any language.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.