SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

超簡単!TELNETの話
超簡単!TELNETの話超簡単!TELNETの話
超簡単!TELNETの話
ogatay
 

La actualidad más candente (20)

Four Languages From Forty Years Ago
Four Languages From Forty Years AgoFour Languages From Forty Years Ago
Four Languages From Forty Years Ago
 
Gcc porting
Gcc portingGcc porting
Gcc porting
 
Rによるlm関数を使わない回帰と梃子比・cookの距離
Rによるlm関数を使わない回帰と梃子比・cookの距離 Rによるlm関数を使わない回帰と梃子比・cookの距離
Rによるlm関数を使わない回帰と梃子比・cookの距離
 
Asterisk Rest Interface - ARI
Asterisk Rest Interface - ARIAsterisk Rest Interface - ARI
Asterisk Rest Interface - ARI
 
Rust Intro
Rust IntroRust Intro
Rust Intro
 
Error Management: Future vs ZIO
Error Management: Future vs ZIOError Management: Future vs ZIO
Error Management: Future vs ZIO
 
Why rust?
Why rust?Why rust?
Why rust?
 
Scientific calcultor-Java
Scientific calcultor-JavaScientific calcultor-Java
Scientific calcultor-Java
 
This is toast ui calendar presentation
This is toast ui calendar presentationThis is toast ui calendar presentation
This is toast ui calendar presentation
 
Seminar
SeminarSeminar
Seminar
 
SciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programmingSciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programming
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
超簡単!TELNETの話
超簡単!TELNETの話超簡単!TELNETの話
超簡単!TELNETの話
 
Verilog ques
Verilog quesVerilog ques
Verilog ques
 
Hashing
HashingHashing
Hashing
 
llvm入門
llvm入門llvm入門
llvm入門
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!
 
C++コミュニティーの中心でC++をDISる
C++コミュニティーの中心でC++をDISるC++コミュニティーの中心でC++をDISる
C++コミュニティーの中心でC++をDISる
 
GLSLによるシェーダーアートことはじめ
GLSLによるシェーダーアートことはじめGLSLによるシェーダーアートことはじめ
GLSLによるシェーダーアートことはじめ
 

Destacado

Destacado (20)

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

Similar a Create Your Own Language

Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
Vasavi College of Engg
 
Diving into Functional Programming
Diving into Functional ProgrammingDiving into Functional Programming
Diving into Functional Programming
Lev Walkin
 
Лев Валкин — Программируем функционально
Лев Валкин — Программируем функциональноЛев Валкин — Программируем функционально
Лев Валкин — Программируем функционально
Daria Oreshkina
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
oscon2007
 

Similar a Create Your Own Language (20)

Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting language
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Diving into Functional Programming
Diving into Functional ProgrammingDiving into Functional Programming
Diving into Functional Programming
 
Лев Валкин — Программируем функционально
Лев Валкин — Программируем функциональноЛев Валкин — Программируем функционально
Лев Валкин — Программируем функционально
 
02-chapter-1.ppt
02-chapter-1.ppt02-chapter-1.ppt
02-chapter-1.ppt
 
Avro
AvroAvro
Avro
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
 
Elixir
ElixirElixir
Elixir
 
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
 
Microsoft .NET Framework
Microsoft .NET FrameworkMicrosoft .NET Framework
Microsoft .NET Framework
 
Future of PERL in IT
Future of PERL in ITFuture of PERL in IT
Future of PERL in IT
 
perl lauange
perl lauangeperl lauange
perl lauange
 
Pearl
PearlPearl
Pearl
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
Elixir introduction
Elixir introductionElixir introduction
Elixir introduction
 
List of programming_languages_by_type
List of programming_languages_by_typeList of programming_languages_by_type
List of programming_languages_by_type
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 

Más de Hamidreza Soleimani

Más de Hamidreza Soleimani (6)

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

Último

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Último (20)

chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

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