SlideShare a Scribd company logo
Create Your Own Language
How to implement a language on top of
Erlang Virtual Machine (BEAM)
Hamidreza Soleimani
Backend Developer / Architect @ BisPhone
Tehran Linux User Group
August 6, 2015
Why should we create
a new language?
Lisp
Javascript
XML
PHP
Python
Haskell
Erlang
Go Ruby
Java
CProlog
Scala
SQL
SQL
Elixir
C++
Rust
Perl
C# Objectiv-CSQL
There are lots of Languages!
By category:

Programming, Query, Domain Specific, etc
By Paradigm:

Imperative, Declarative (Logic, Functional), Structured (Object
Oriented, Modular), etc
By Implementation:

Compiled, Interpreted, Mixed, etc
By Type System:

Static, Dynamic, Strong, Weak, etc
So why should we create it?
Reason 1: Implementing a new idea
Reason 2: Solving a new problem
Reason 3: Mastering language concepts
Reason 4: Just for fun!
How can we create
a new language?
1. Designing
1.1. Identifying the problem
1.2. Planning the target platform/machine
1.3. Determining language category, paradigm, types, etc
2. Implementing Frontend
2.1. Lexical Scanning (Token Generating)

(example: lex, flex, leex, etc)
2.2. Syntax & Semantics Parsing (AST Generating)

(example: yacc, bison, yecc)
2.3. Preprocessing
2.4. Lint Analyzing
2.5. Generating Intermediate Language

(example: GCC IR, LLVM IR, BEAM Bytecode, Java Bytecode)
3. Implementing Backend
3.1. Analyzing Intermediate Language
3.2. Optimizing
3.3. Generating Machine Code
3.4. Evaluating and Executing
Lets look inside Erlang
compiler
– Holy Wikipedia
What is Erlang?
“Erlang is a general-purpose, functional, concurrent,
garbage-collected programming language and
runtime system, with eager evaluation, single
assignment, and dynamic typing. It was originally
designed by Ericsson to support distributed, fault-
tolerant, soft real-time, highly available, non-stop
applications. It supports hot swapping, so that code
can be changed without stopping a system.”
Code Generation Steps
Erlang Source Code
Parse Transformed & Preprocessed Code (erlc -P)
Source Transformed Code (erlc -E)
Abstract Syntax Tree (erlc +dabstr)
Expanded Abstract Syntax Tree (erlc +dexp)
Core Erlang (erlc +to_core)
Assembler Code (erlc -S)
BEAM Bytecode (erlc)
Source Code
$ vim test.erl
Parse Transformed Code
$ erlc -P test.erl
Source Transformed Code
$ erlc -E test.erl
AST Code
$ erlc +dabstr test.erl
Expanded AST Code
$ erlc +dexp test.erl
Core Erlang Code
$ erlc +to_core test.erl
Assembler Code
$ erlc -S test.erl
BEAM Byte Code
$ erlc test.erl
Lets create a query language
for Tnesia
– https://github.com/bisphone/Tnesia
What is Tnesia?
“Tnesia is a time-series data storage which lets you
run time-based queries on a large amount of data,
without scanning the whole set of data, and in a
key-value manner. It can be used embedded inside
an Erlang application, or stand-alone with HTTP
interface to outside which talks in a simple query
language called TQL.”
The Problem
It seems that its Erlang API looks strange to non-Erlang developer!
The Solution
Create a Query Language (TQL) that can be used over HTTP.
TQL Concepts
Syntax Types
Lexical Scanning
Using leex which is a Erlang lexer
Definitions Rules
Parsing
Non-terminals Terminals Rules
Using yecc which is an Erlang parser generator
Root-symbol
Evaluating
Evaluating AST in Erlang without any intermediate code generation
Question || Comment
- https://hamidreza-s.github.com

More Related Content

PDF
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
PDF
Gradle handson
PDF
Hadoop入門
PDF
EmbulkのGCS/BigQuery周りのプラグインについて
PPTX
パフォーマンスの良いGASの書き方 Best Practice
PDF
Elastic Search (엘라스틱서치) 입문
PPTX
Apache HBase™
PDF
AWS Elastic Beanstalk(初心者向け 超速マスター編)JAWSUG大阪
Erlang, LFE, Joxa and Elixir: Established and Emerging Languages in the Erlan...
Gradle handson
Hadoop入門
EmbulkのGCS/BigQuery周りのプラグインについて
パフォーマンスの良いGASの書き方 Best Practice
Elastic Search (엘라스틱서치) 입문
Apache HBase™
AWS Elastic Beanstalk(初心者向け 超速マスター編)JAWSUG大阪

What's hot (20)

PDF
Un débat à l’Ecclésia Zao P - 2015
PDF
AWS Batch를 통한 손쉬운 일괄 처리 작업 관리하기 - 윤석찬 (AWS 테크에반젤리스트)
PPTX
Building a Virtual Data Lake with Apache Arrow
PDF
Spiderストレージエンジンの使い方と利用事例 他ストレージエンジンの紹介
PDF
Code for Japan 勉強会 Vol.1 CKAN入門 プロジェクトのFork、デプロイ、CIまで
PPTX
FIWARE - スマートサービスを支えるオープンソース
PDF
最近のストリーム処理事情振り返り
PDF
MongoDB〜その性質と利用場面〜
PDF
AWS Black Belt Online Seminar AWS CloudFormation アップデート
PDF
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
PPTX
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
PDF
서비스 무중단 마이그레이션 : KT에서 Amazon으로
PDF
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
PDF
[164] pinpoint
PPTX
제조업의 AI/ML 고객 사례::남궁영환::AWS Summit Seoul 2018
PDF
Advanced Natural Language Processing with Apache Spark NLP
PDF
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
PPTX
What-is-Laravel-23-August-2017.pptx
PDF
Spring Day 2016 - Web API アクセス制御の最適解
PDF
Building Data Product Based on Apache Spark at Airbnb with Jingwei Lu and Liy...
Un débat à l’Ecclésia Zao P - 2015
AWS Batch를 통한 손쉬운 일괄 처리 작업 관리하기 - 윤석찬 (AWS 테크에반젤리스트)
Building a Virtual Data Lake with Apache Arrow
Spiderストレージエンジンの使い方と利用事例 他ストレージエンジンの紹介
Code for Japan 勉強会 Vol.1 CKAN入門 プロジェクトのFork、デプロイ、CIまで
FIWARE - スマートサービスを支えるオープンソース
最近のストリーム処理事情振り返り
MongoDB〜その性質と利用場面〜
AWS Black Belt Online Seminar AWS CloudFormation アップデート
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
서비스 무중단 마이그레이션 : KT에서 Amazon으로
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
[164] pinpoint
제조업의 AI/ML 고객 사례::남궁영환::AWS Summit Seoul 2018
Advanced Natural Language Processing with Apache Spark NLP
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
What-is-Laravel-23-August-2017.pptx
Spring Day 2016 - Web API アクセス制御の最適解
Building Data Product Based on Apache Spark at Airbnb with Jingwei Lu and Liy...
Ad

Viewers also liked (20)

PDF
Real life XMPP Instant Messaging
PDF
Multi Chat
PDF
Erlang White Label
PDF
2015: L'année d'Elixir, Code, écosystème et communauté
PDF
Nanomsg - Scalable Networking Library
ZIP
ProcessOne Push Platform: XMPP-based Push Solutions
PDF
Archipel Introduction - ejabberd SF Meetup
PDF
Event Driven Architecture Concepts in Web Technologies - Part 2
ZIP
OneTeam Media Server
ZIP
Real time Web Application with XMPP and Wave
ZIP
WaveOne server and client by ProcessOne
PDF
Multitasking in iOS 7
PDF
Nodejs Applications in Production
PDF
XMPP Academy #1
PDF
Event Driven Architecture Concepts in Web Technologies - Part 1
PDF
Practical Look at Erlang
PDF
A vision for ejabberd - ejabberd SF Meetup
PDF
Phoenix Presence: Le service temps réel de Phoenix - Paris.ex #8
KEY
The Real Time Web with XMPP
PDF
What is XMPP Protocol
Real life XMPP Instant Messaging
Multi Chat
Erlang White Label
2015: L'année d'Elixir, Code, écosystème et communauté
Nanomsg - Scalable Networking Library
ProcessOne Push Platform: XMPP-based Push Solutions
Archipel Introduction - ejabberd SF Meetup
Event Driven Architecture Concepts in Web Technologies - Part 2
OneTeam Media Server
Real time Web Application with XMPP and Wave
WaveOne server and client by ProcessOne
Multitasking in iOS 7
Nodejs Applications in Production
XMPP Academy #1
Event Driven Architecture Concepts in Web Technologies - Part 1
Practical Look at Erlang
A vision for ejabberd - ejabberd SF Meetup
Phoenix Presence: Le service temps réel de Phoenix - Paris.ex #8
The Real Time Web with XMPP
What is XMPP Protocol
Ad

Similar to Create Your Own Language (20)

PPT
02-chapter-1.ppt programming languages 10
PPT
brief intro for Programming Languages 02-chapter-1
PPTX
Lecture 1 introduction to language processors
PDF
Language Server Protocol - Why the Hype?
PPT
Introduction to perl_ a scripting language
PPTX
Unit1 principle of programming language
PDF
Diving into Functional Programming
PDF
Лев Валкин — Программируем функционально
PPT
02-chapter-1.ppt
PPTX
PDF
What we can learn from Rebol?
PDF
Elixir
PDF
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
PPT
Microsoft .NET Framework
PPTX
Future of PERL in IT
PPTX
PPTX
perl lauange
PPT
Ruby on Rails (RoR) as a back-end processor for Apex
PPTX
Elixir introduction
PDF
List of programming_languages_by_type
02-chapter-1.ppt programming languages 10
brief intro for Programming Languages 02-chapter-1
Lecture 1 introduction to language processors
Language Server Protocol - Why the Hype?
Introduction to perl_ a scripting language
Unit1 principle of programming language
Diving into Functional Programming
Лев Валкин — Программируем функционально
02-chapter-1.ppt
What we can learn from Rebol?
Elixir
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Microsoft .NET Framework
Future of PERL in IT
perl lauange
Ruby on Rails (RoR) as a back-end processor for Apex
Elixir introduction
List of programming_languages_by_type

More from Hamidreza Soleimani (7)

PDF
Principles of Engineering Management | Hamidreza Soleimani | Diginext Academy
PDF
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
PDF
How to Scale Your Engineering Team | Hamidreza Soleimani | Diginext Academy
PDF
The World works in Parallel | Hamidreza Soleimani | Diginext Academy
PDF
Technology Companies Development Story
PDF
Do Reinvent the Wheel - Nov 2021 - DigiNext.pdf
PDF
BEAM (Erlang VM) as a Soft Real-time Platform
Principles of Engineering Management | Hamidreza Soleimani | Diginext Academy
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
How to Scale Your Engineering Team | Hamidreza Soleimani | Diginext Academy
The World works in Parallel | Hamidreza Soleimani | Diginext Academy
Technology Companies Development Story
Do Reinvent the Wheel - Nov 2021 - DigiNext.pdf
BEAM (Erlang VM) as a Soft Real-time Platform

Recently uploaded (20)

PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Geodesy 1.pptx...............................................
PPT
Project quality management in manufacturing
PPTX
Welding lecture in detail for understanding
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Digital Logic Computer Design lecture notes
PPTX
web development for engineering and engineering
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Internet of Things (IOT) - A guide to understanding
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Geodesy 1.pptx...............................................
Project quality management in manufacturing
Welding lecture in detail for understanding
Arduino robotics embedded978-1-4302-3184-4.pdf
Digital Logic Computer Design lecture notes
web development for engineering and engineering
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Lecture Notes Electrical Wiring System Components
CH1 Production IntroductoryConcepts.pptx
573137875-Attendance-Management-System-original
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx

Create Your Own Language

  • 1. Create Your Own Language How to implement a language on top of Erlang Virtual Machine (BEAM) Hamidreza Soleimani Backend Developer / Architect @ BisPhone Tehran Linux User Group August 6, 2015
  • 2. Why should we create a new language? Lisp Javascript XML PHP Python Haskell Erlang Go Ruby Java CProlog Scala SQL SQL Elixir C++ Rust Perl C# Objectiv-CSQL
  • 3. There are lots of Languages! By category:
 Programming, Query, Domain Specific, etc By Paradigm:
 Imperative, Declarative (Logic, Functional), Structured (Object Oriented, Modular), etc By Implementation:
 Compiled, Interpreted, Mixed, etc By Type System:
 Static, Dynamic, Strong, Weak, etc
  • 4. So why should we create it? Reason 1: Implementing a new idea Reason 2: Solving a new problem Reason 3: Mastering language concepts Reason 4: Just for fun!
  • 5. How can we create a new language?
  • 6. 1. Designing 1.1. Identifying the problem 1.2. Planning the target platform/machine 1.3. Determining language category, paradigm, types, etc
  • 7. 2. Implementing Frontend 2.1. Lexical Scanning (Token Generating)
 (example: lex, flex, leex, etc) 2.2. Syntax & Semantics Parsing (AST Generating)
 (example: yacc, bison, yecc) 2.3. Preprocessing 2.4. Lint Analyzing 2.5. Generating Intermediate Language
 (example: GCC IR, LLVM IR, BEAM Bytecode, Java Bytecode)
  • 8. 3. Implementing Backend 3.1. Analyzing Intermediate Language 3.2. Optimizing 3.3. Generating Machine Code 3.4. Evaluating and Executing
  • 9. Lets look inside Erlang compiler
  • 10. – Holy Wikipedia What is Erlang? “Erlang is a general-purpose, functional, concurrent, garbage-collected programming language and runtime system, with eager evaluation, single assignment, and dynamic typing. It was originally designed by Ericsson to support distributed, fault- tolerant, soft real-time, highly available, non-stop applications. It supports hot swapping, so that code can be changed without stopping a system.”
  • 11. Code Generation Steps Erlang Source Code Parse Transformed & Preprocessed Code (erlc -P) Source Transformed Code (erlc -E) Abstract Syntax Tree (erlc +dabstr) Expanded Abstract Syntax Tree (erlc +dexp) Core Erlang (erlc +to_core) Assembler Code (erlc -S) BEAM Bytecode (erlc)
  • 12. Source Code $ vim test.erl
  • 13. Parse Transformed Code $ erlc -P test.erl
  • 14. Source Transformed Code $ erlc -E test.erl
  • 15. AST Code $ erlc +dabstr test.erl
  • 16. Expanded AST Code $ erlc +dexp test.erl
  • 17. Core Erlang Code $ erlc +to_core test.erl
  • 18. Assembler Code $ erlc -S test.erl
  • 19. BEAM Byte Code $ erlc test.erl
  • 20. Lets create a query language for Tnesia
  • 21. – https://github.com/bisphone/Tnesia What is Tnesia? “Tnesia is a time-series data storage which lets you run time-based queries on a large amount of data, without scanning the whole set of data, and in a key-value manner. It can be used embedded inside an Erlang application, or stand-alone with HTTP interface to outside which talks in a simple query language called TQL.”
  • 22. The Problem It seems that its Erlang API looks strange to non-Erlang developer!
  • 23. The Solution Create a Query Language (TQL) that can be used over HTTP.
  • 25. Lexical Scanning Using leex which is a Erlang lexer Definitions Rules
  • 26. Parsing Non-terminals Terminals Rules Using yecc which is an Erlang parser generator Root-symbol
  • 27. Evaluating Evaluating AST in Erlang without any intermediate code generation
  • 28. Question || Comment - https://hamidreza-s.github.com