This document provides information on how to build your own programming language. It discusses why someone would want to learn how to build a programming language, including to better understand computers and existing languages. It also outlines some of the key components involved, such as lexers, parsers, compilers, interpreters, grammars, and ASTs. The document recommends starting simply, such as with domain-specific languages or template languages, and provides several resources for learning more about building programming languages.
1. How to build your own
programming language ?
May 18, 2017
2. About me
Work at xoxzo.com
Web Developer
PHP/Python/JavaScript … etc
3. It’s not MAGIC
It just a translator !
How to translate word from BM to BI ?
4. Why learn to build programming language ?
We are just consumer !
Not much research yet on programming language development (is there any ?)
● MalayBasic
Current research
● LLVM - Low Level Virtual Machine, started in 2000 at the University of
Illinois at Urbana–Champaign
● PyPy
5. Why learn to build programming language ?
Understand computer better
Understand current language better
Need lot of different technical skills and the skills can be useful in writing any
kind of software, not just compiler/interpreter
Personal challenge, feel in control, Take a over the world ;)
It’s fun
6. Two Separate roles
Designing a language
Writing compiler/interpreter for the language
**********************************
The language specification
The language implementation
7. Bootstrapping
Python written in C (also in Java, .NET, and Python itself)
Java written in C
Go compiler originally written in C, now written in Go itself
C written in what ?
11. Lexing
Recognize characters
Tokenized
Stream of tokens
Parsing
Recognize phrase -
enforce grammar
AST
Set of structures
Compiling
Interpreting
Converting to target
language or executing
the instructions
19. Free choice on syntax - {{ varname }}, %varname%, $varname etc
Show user syntax error - substitution just silent on in invalid syntax
Tell user exact line error occured.
Just few lines of code, easy to understand instead of full blown template
language.
Why not just substitution ?
21. Resources
Let’s build a compiler - classic (1989) - http://compilers.iecc.com/crenshaw/
● Original article use Pascal, but being ported in lot of language
http://createyourproglang.com/ - recommended by Matz (Ruby) and Jeremy
Ashkenas (CoffeeScript)
Let’s Build Simple Interpreter - https://ruslanspivak.com/lsbasi-part1/
https://interpreterbook.com/ - Go
http://www.craftinginterpreters.com/ - Incomplete