自作コンパイラのお話

Swift 

freddi
1
(@freddi_kit)









Python

Perl Swift
• Swift 

•
• 

= 

• 

• 



• 

•
Swift
•


•
自作コンパイラのお話
• 

• C -> ( ) -> 

• Swift -> (SIL) -> LLVM IR

• C -> Python
自作コンパイラのお話
• 

• 

• 

• 



• 

• 

















• 

















• 

• 



•


(ab,aa )


• 

• let( ) letlet( ) 



( )

let[ ]a … → let 

letlet[ ]a …→ letlet


• 

• 



• 

自作コンパイラのお話


: >> let a = 10;
// l ”l” (accept)
accept(Braph.QKeyWord, Braph.TokenNode.identifier(Optional("l")))
["l"]
// e ”le”
accept(Braph.QKeyWord, Braph.TokenNode.identifier(Optional("le")))
["l", "e"]
// e ”let”
accept(Braph.QForIndetifier,
Braph.TokenNode.keyword(Braph.TokenNode.KeyWordType.declaration, Optional("let")))
["l", "e", "t"]
// (undefined).

// ”let”
undefined
["l", "e", "t", " "]
//
accept(Braph.QForSeparator, Braph.TokenNode.separator)
[" "]

//
自作コンパイラのお話
• 

• 

• 

• (Syntax)

•Syntax Error 

•
 

• ( )
< expr > ::= <expr> <+- > <term>

<expr>

< term > ::= <term> <*/ > <factor>

<factor>

< factor > ::= literal 10 1
int a = 10 + 5 - 10;
int a = 10 + 5 - 10;
int a = 10 + 5 - 10;


int a = 10 + 5 - 10;
+


int a = 10 + 5 - 10;
+
+

int a = 10 + 5 - 10;
+
+

:= `=`
:= `+` or



Swift Tour tuple
BNF( )
• BNF
• BNF) 

•
 

< statement > ::= <declaration>

<expr>

<return>

<assign>
< expr > ::= <expr> + <term>

<expr>

< term > ::= <term> * <factor>

<factor>

< factor > ::= literal
< initializer > ::= = <expr>

< assign > ::= identifier <initializer>

< declaration > ::= let identifier <initializer>

var identifier <initializer>


•LL 

•SLR 

•LR 

•LALR
• LL 

• 

• 

= OK
• 

( ) < expr > ::= <expr> + <term>

<expr>

• 

→ 

•LR SLR LALR 

• 

• OK 

• LR 

C++
• 

•
• 



• 

• LR(1) 

• 1 

LALR(1) LL(1)
•BNF 

• 

• -> 

• -> LR




https://github.com/freddi-kit/Braph



->




https://github.com/freddi-kit/Braph

ω v
• 

• 

•
• 





自作コンパイラのお話
• 

https://books.rakuten.co.jp/rb/12932375/

• LR parsing 

https://www.slideshare.net/ichikaz3/lr-parsing

• LLVM 

LLVM IR clang Brainf**k 

https://itchyny.hatenablog.com/entry/2017/02/27/100000
https://github.com/freddi-kit/Braph
1 of 53

Recommended

Thoughts On Learning A New Programming Language by
Thoughts On Learning A New Programming LanguageThoughts On Learning A New Programming Language
Thoughts On Learning A New Programming LanguagePatricia Aas
653 views75 slides
Secure Programming Practices in C++ (NDC Security 2018) by
Secure Programming Practices in C++ (NDC Security 2018)Secure Programming Practices in C++ (NDC Security 2018)
Secure Programming Practices in C++ (NDC Security 2018)Patricia Aas
2K views67 slides
Php extensions by
Php extensionsPhp extensions
Php extensionsElizabeth Smith
2K views81 slides
Perl Intro 8 File Handles by
Perl Intro 8 File HandlesPerl Intro 8 File Handles
Perl Intro 8 File HandlesShaun Griffith
463 views10 slides
C++ for Java Developers (JavaZone Academy 2018) by
C++ for Java Developers (JavaZone Academy 2018)C++ for Java Developers (JavaZone Academy 2018)
C++ for Java Developers (JavaZone Academy 2018)Patricia Aas
1.4K views56 slides
PHP 5.3 And PHP 6 A Look Ahead by
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
4.1K views53 slides

More Related Content

What's hot

The Anatomy of an Exploit (NDC TechTown 2019) by
The Anatomy of an Exploit (NDC TechTown 2019)The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)Patricia Aas
621 views104 slides
Perl basics for pentesters part 2 by
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2n|u - The Open Security Community
1.2K views26 slides
Perl Basics for Pentesters Part 1 by
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1n|u - The Open Security Community
1.5K views20 slides
Python - Getting to the Essence - Points.com - Dave Park by
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
935 views17 slides
Starting Out With PHP by
Starting Out With PHPStarting Out With PHP
Starting Out With PHPMark Niebergall
355 views84 slides
C++ The Principles of Most Surprise by
C++ The Principles of Most SurpriseC++ The Principles of Most Surprise
C++ The Principles of Most SurprisePatricia Aas
1.1K views19 slides

What's hot(19)

The Anatomy of an Exploit (NDC TechTown 2019) by Patricia Aas
The Anatomy of an Exploit (NDC TechTown 2019)The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)
Patricia Aas621 views
Python - Getting to the Essence - Points.com - Dave Park by pointstechgeeks
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
pointstechgeeks935 views
C++ The Principles of Most Surprise by Patricia Aas
C++ The Principles of Most SurpriseC++ The Principles of Most Surprise
C++ The Principles of Most Surprise
Patricia Aas1.1K views
Software Vulnerabilities in C and C++ (CppCon 2018) by Patricia Aas
Software Vulnerabilities in C and C++ (CppCon 2018)Software Vulnerabilities in C and C++ (CppCon 2018)
Software Vulnerabilities in C and C++ (CppCon 2018)
Patricia Aas1.1K views
201705 metaprogramming in julia by 岳華 杜
201705 metaprogramming in julia201705 metaprogramming in julia
201705 metaprogramming in julia
岳華 杜380 views
Trying to learn C# (NDC Oslo 2019) by Patricia Aas
Trying to learn C# (NDC Oslo 2019)Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)
Patricia Aas997 views
Php7 hhvm and co by Pierre Joye
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and co
Pierre Joye1.6K views
Utility Modules That You Should Know About by joshua.mcadams
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know About
joshua.mcadams1.6K views
Secure Programming Practices in C++ (NDC Oslo 2018) by Patricia Aas
Secure Programming Practices in C++ (NDC Oslo 2018)Secure Programming Practices in C++ (NDC Oslo 2018)
Secure Programming Practices in C++ (NDC Oslo 2018)
Patricia Aas2.5K views
Tuples, Dicts and Exception Handling by PranavSB
Tuples, Dicts and Exception HandlingTuples, Dicts and Exception Handling
Tuples, Dicts and Exception Handling
PranavSB234 views
The Ring programming language version 1.8 book - Part 96 of 202 by Mahmoud Samir Fayed
The Ring programming language version 1.8 book - Part 96 of 202The Ring programming language version 1.8 book - Part 96 of 202
The Ring programming language version 1.8 book - Part 96 of 202
Whatsnew in-perl by daoswald
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
daoswald187 views
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018 by Codemotion
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Codemotion81 views
Voice That Matter 2010 - Core Audio by Kevin Avila
Voice That Matter 2010 - Core AudioVoice That Matter 2010 - Core Audio
Voice That Matter 2010 - Core Audio
Kevin Avila631 views

Similar to 自作コンパイラのお話

Hamamatsu.swift @浜松IT合同勉強会 by
Hamamatsu.swift @浜松IT合同勉強会Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会Takuya Ogawa
355 views45 slides
Ruby is an Acceptable Lisp by
Ruby is an Acceptable LispRuby is an Acceptable Lisp
Ruby is an Acceptable LispAstrails
2.4K views85 slides
并发模型介绍 by
并发模型介绍并发模型介绍
并发模型介绍qiang
787 views28 slides
Java プログラマーのための Swift 入門 #中央線Meetup by
Java プログラマーのための Swift 入門 #中央線MeetupJava プログラマーのための Swift 入門 #中央線Meetup
Java プログラマーのための Swift 入門 #中央線MeetupShinya Mochida
821 views32 slides
What's New in Swift 4 by
What's New in Swift 4What's New in Swift 4
What's New in Swift 4Young Hoo Kim
763 views66 slides
Clojure Intro by
Clojure IntroClojure Intro
Clojure Introthnetos
10.5K views30 slides

Similar to 自作コンパイラのお話(18)

Hamamatsu.swift @浜松IT合同勉強会 by Takuya Ogawa
Hamamatsu.swift @浜松IT合同勉強会Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会
Takuya Ogawa355 views
Ruby is an Acceptable Lisp by Astrails
Ruby is an Acceptable LispRuby is an Acceptable Lisp
Ruby is an Acceptable Lisp
Astrails2.4K views
并发模型介绍 by qiang
并发模型介绍并发模型介绍
并发模型介绍
qiang787 views
Java プログラマーのための Swift 入門 #中央線Meetup by Shinya Mochida
Java プログラマーのための Swift 入門 #中央線MeetupJava プログラマーのための Swift 入門 #中央線Meetup
Java プログラマーのための Swift 入門 #中央線Meetup
Shinya Mochida821 views
Clojure Intro by thnetos
Clojure IntroClojure Intro
Clojure Intro
thnetos10.5K views
swift-nio のアーキテクチャーと RxHttpClient by Shinya Mochida
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClient
Shinya Mochida1.2K views
scala-gopher: async implementation of CSP for scala by Ruslan Shevchenko
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
Ruslan Shevchenko1.9K views
Vim Script Programming by Lin Yo-An
Vim Script ProgrammingVim Script Programming
Vim Script Programming
Lin Yo-An5.6K views
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015 by Speedment, Inc.
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
Speedment, Inc.1.4K views
python beginner talk slide by jonycse
python beginner talk slidepython beginner talk slide
python beginner talk slide
jonycse867 views
Go Web Development by Cheng-Yi Yu
Go Web DevelopmentGo Web Development
Go Web Development
Cheng-Yi Yu244 views
Denis Lebedev, Swift by Yandex
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex38.4K views
CoderDojo: Intermediate Python programming course by Alexander Galkin
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
Alexander Galkin1.1K views
Lego: A brick system build by scala by lunfu zhong
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scala
lunfu zhong1.2K views
Python于Web 2.0网站的应用 - QCon Beijing 2010 by Qiangning Hong
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong22.2K views

More from 秋 勇紀

For Developing URL Routing of SwiftUI App by
For Developing URL Routing of SwiftUI AppFor Developing URL Routing of SwiftUI App
For Developing URL Routing of SwiftUI App秋 勇紀
260 views22 slides
Tutorial for developing SILOptimizer Pass by
Tutorial for developing SILOptimizer PassTutorial for developing SILOptimizer Pass
Tutorial for developing SILOptimizer Pass秋 勇紀
771 views61 slides
A Deeper Deep Dive into Swift Literal by
A Deeper Deep Dive into Swift LiteralA Deeper Deep Dive into Swift Literal
A Deeper Deep Dive into Swift Literal秋 勇紀
1.5K views115 slides
What Swifty is, from Enum by
What Swifty is, from EnumWhat Swifty is, from Enum
What Swifty is, from Enum秋 勇紀
1.5K views51 slides
Deep Dive into Swift Literal by
Deep Dive into Swift LiteralDeep Dive into Swift Literal
Deep Dive into Swift Literal秋 勇紀
1.3K views15 slides
SILOptimizerのCode Reading入門 by
SILOptimizerのCode Reading入門SILOptimizerのCode Reading入門
SILOptimizerのCode Reading入門秋 勇紀
239 views31 slides

More from 秋 勇紀(7)

For Developing URL Routing of SwiftUI App by 秋 勇紀
For Developing URL Routing of SwiftUI AppFor Developing URL Routing of SwiftUI App
For Developing URL Routing of SwiftUI App
秋 勇紀260 views
Tutorial for developing SILOptimizer Pass by 秋 勇紀
Tutorial for developing SILOptimizer PassTutorial for developing SILOptimizer Pass
Tutorial for developing SILOptimizer Pass
秋 勇紀771 views
A Deeper Deep Dive into Swift Literal by 秋 勇紀
A Deeper Deep Dive into Swift LiteralA Deeper Deep Dive into Swift Literal
A Deeper Deep Dive into Swift Literal
秋 勇紀1.5K views
What Swifty is, from Enum by 秋 勇紀
What Swifty is, from EnumWhat Swifty is, from Enum
What Swifty is, from Enum
秋 勇紀1.5K views
Deep Dive into Swift Literal by 秋 勇紀
Deep Dive into Swift LiteralDeep Dive into Swift Literal
Deep Dive into Swift Literal
秋 勇紀1.3K views
SILOptimizerのCode Reading入門 by 秋 勇紀
SILOptimizerのCode Reading入門SILOptimizerのCode Reading入門
SILOptimizerのCode Reading入門
秋 勇紀239 views
ディープラーニングでポプテピピック by 秋 勇紀
ディープラーニングでポプテピピックディープラーニングでポプテピピック
ディープラーニングでポプテピピック
秋 勇紀481 views

Recently uploaded

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
146 views15 slides
The Role of Patterns in the Era of Large Language Models by
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language ModelsYunyao Li
80 views65 slides
Business Analyst Series 2023 - Week 4 Session 7 by
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
126 views31 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
154 views62 slides
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...ShapeBlue
138 views18 slides
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericShapeBlue
88 views9 slides

Recently uploaded(20)

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue146 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li80 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10126 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue154 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue138 views
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue88 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue94 views
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... by ShapeBlue
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
ShapeBlue88 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue222 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue120 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson156 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue176 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue166 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue179 views

自作コンパイラのお話