KEMBAR78
How to build your own programming language | ODP
How to build your own
programming language ?
May 18, 2017
About me
Work at xoxzo.com
Web Developer
PHP/Python/JavaScript … etc
It’s not MAGIC
It just a translator !
How to translate word from BM to BI ?
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
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
Two Separate roles
Designing a language
Writing compiler/interpreter for the language
**********************************
The language specification
The language implementation
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 ?
Bootstrapping
The first Pascal compiler was written in Fortran
Bootstrapping
The target is to become self-hosting - a compiler that can compile itself.
Jargon
Lexer
Parser
Compiler/Interpreter
Grammar
AST
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
BUT ...
Where to start ?
Start small ...
DSL, simple command - chatbot command
Template language
Chat bot command
/remind me to meet Amin at 9.00 AM tomorrow
How to parse this ?
[/command] [who] [what - tasks description][when]
Mail merge like template
Mail merge like template
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 ?
Shortcut ...
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
Resources
https://koditi.my/bagaimana-bahasa-pengaturcaraan/
Question ?
https://koditi.my/

How to build your own programming language

  • 1.
    How to buildyour own programming language ? May 18, 2017
  • 2.
    About me Work atxoxzo.com Web Developer PHP/Python/JavaScript … etc
  • 3.
    It’s not MAGIC Itjust a translator ! How to translate word from BM to BI ?
  • 4.
    Why learn tobuild 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 tobuild 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 Designinga language Writing compiler/interpreter for the language ********************************** The language specification The language implementation
  • 7.
    Bootstrapping Python written inC (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 ?
  • 8.
    Bootstrapping The first Pascalcompiler was written in Fortran
  • 9.
    Bootstrapping The target isto become self-hosting - a compiler that can compile itself.
  • 10.
  • 11.
    Lexing Recognize characters Tokenized Stream oftokens Parsing Recognize phrase - enforce grammar AST Set of structures Compiling Interpreting Converting to target language or executing the instructions
  • 12.
  • 13.
    Where to start? Start small ... DSL, simple command - chatbot command Template language
  • 14.
    Chat bot command /remindme to meet Amin at 9.00 AM tomorrow How to parse this ? [/command] [who] [what - tasks description][when]
  • 17.
  • 18.
  • 19.
    Free choice onsyntax - {{ 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 ?
  • 20.
  • 21.
    Resources Let’s build acompiler - 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
  • 22.
  • 23.

Editor's Notes

  • #12 Similar to forming sentence in BM or BI using correct grammar - we’re doing parsing, in our brain.