Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Dynamic Grammars
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Lukas Renggli
October 04, 2011
Technology
58
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dynamic Grammars
Lukas Renggli
October 04, 2011
More Decks by Lukas Renggli
See All by Lukas Renggli
Domain-Specific Program Checking
renggli
1
38
Natural Language Checking with Program Checking Tools
renggli
1
57
The Dynamic Language is not Enough
renggli
1
54
Dynamic Language Embedding With Homogeneous Tool Support
renggli
1
120
Other Decks in Technology
See All in Technology
AIはどのように 組織のアジリティを変えるのか?
junki
4
1.1k
「軸足」は 固定しなくていい - 熱量と強みで描く、しなやかなキャリアの形
kakehashi
PRO
1
200
人材育成分科会.pdf
_awache
4
310
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
170
スタートアップにAmazon EKSは早すぎる? マルチプロダクト戦略を加速する Platform Engineeringの実践 / Is Amazon EKS Too Soon for Startups? Practical Platform Engineering to Accelerate a Multi-Product Strategy
elmodev09
1
1.5k
新しいUbuntu/GNOMEが使いたいからXからWaylandへ移行頑張ってるの巻 2026-06-20
nobutomurata
0
160
現場のトークンマネジメント
dak2
1
160
SONiCのLinuxベースを活かしたZabbix監視
sonic
0
260
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
130
[AWS Summit Japan 2026]迷っているあなたへ_小さな一歩が、やがて自分を助けてくれる
sh_fk2
1
340
40代で“やっとエンジニアになれた”――閉じた学びを開き、空の青さを知る / 20260628 Naoki Takahashi
shift_evolve
PRO
4
520
「ビジネスがわかるエンジニア」とは何か?
ryooob
0
210
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
440
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The SEO identity crisis: Don't let AI make you average
varn
0
490
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
Abbi's Birthday
coloredviolet
2
8.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
Transcript
Dynamic Grammars Lukas Renggli, Stéphane Ducasse, Tudor Gîrba, Oscar Nierstrasz
[Adapted from The New Oxford American Dictionary on Grammar] grammar
a set of rules governing what strings are valid or allowable in a [formal] language.
dynamic grammar a high-level grammar that executes at runtime behaviors
that other grammars perform during compilation, see dynamic languages. [Adapted from Wikipedia on Dynamic Programming Languages]
Dynamic Grammars Dynamic Languages ‣ Late-bound behavior ‣ First-class representation
‣ On-the-fly transformation ‣ Introspection and reflection
Why would we want that?
Language Boxes Host Environment Language and Tool Extensions
Language Boxes Host Environment Dynamic Grammars Language and Tool Extensions
Language Change Language Concern Language Scope Language Box * *
* *
Language Change = Host Language Grammar δ
Language Change = Grammar Transformation
scanIdentifier self step. ((currentCharacter between: $A and: $Z) or: [
currentCharacter between: $a and: $z ]) ifTrue: [ [ self recordMatch: #IDENTIFIER. self step. (currentCharacter between: $0 and: $9) or: [ (currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ] ] ] whileTrue. ^ self reportLastMatch ]
scanIdentifier self step. ((currentCharacter between: $A and: $Z) or: [
currentCharacter between: $a and: $z ]) ifTrue: [ [ self recordMatch: #IDENTIFIER. self step. (currentCharacter between: $0 and: $9) or: [ (currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ] ] ] whileTrue. ^ self reportLastMatch ] ✖
#( #[1 0 9 0 25 0 13 0 34
0 17 0 40 0 21 0 41] #[1 0 9 0 25 0 13 0 34 0 93 0 76 0 157 0 112] #[1 2 38 0 21 2 38 0 25 2 38 0 26 0 13 0 34] #[0 1 154 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[0 1 210 0 76 0 81] #[0 1 214 0 76 0 81] #[1 0 173 0 76 0 177 0 81] #[0 1 134 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[1 1 46 0 21 1 46 0 25 1 46 0 26 1 69] #[1 1 54 0 21 1 54 0 25 1 54 0 26 1 54 0 34] #[0 2 102 0 21 0 25 0 26 0 34 0 40 0 41 0 76] #[0 2 50 0 21 0 25 0 26 0 76 0 79] #[1 1 13 0 76 2 85 0 124 1 21 0 125] #[1 2 89 0 17 2 30 0 21 2 30 0 82] #[1 2 93 0 21 2 97 0 82] )
#( #[1 0 9 0 25 0 13 0 34
0 17 0 40 0 21 0 41] #[1 0 9 0 25 0 13 0 34 0 93 0 76 0 157 0 112] #[1 2 38 0 21 2 38 0 25 2 38 0 26 0 13 0 34] #[0 1 154 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[0 1 210 0 76 0 81] #[0 1 214 0 76 0 81] #[1 0 173 0 76 0 177 0 81] #[0 1 134 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[1 1 46 0 21 1 46 0 25 1 46 0 26 1 69] #[1 1 54 0 21 1 54 0 25 1 54 0 26 1 54 0 34] #[0 2 102 0 21 0 25 0 26 0 34 0 40 0 41 0 76] #[0 2 50 0 21 0 25 0 26 0 76 0 79] #[1 1 13 0 76 2 85 0 124 1 21 0 125] #[1 2 89 0 17 2 30 0 21 2 30 0 82] #[1 2 93 0 21 2 97 0 82] ) ✖
None
a..z a..z 0..9 ID ::= letter { letter | digit
} ;
letter letter digit sequence choice star id := #letter ,
(#letter / #digit) star
letter letter digit sequence choice star id := #letter asParser
, (#letter asParser / #digit asParser) star
Scannerless Parser
Parsing Expression Grammar
Packrat Parser
Parser Combinator
None
Grammar Transformation
Graph Rewriting
letter letter digit sequence choice star #letter → #letter /
$_
letter digit sequence choice star choice _ letter choice _
#letter → #letter / $_
Optimizations
letter digit sequence choice star choice _ letter choice _
(`a / `b) / `c → `a / `b / `c
letter digit sequence choice star choice _ letter _ (`a
/ `b) / `c → `a / `b / `c
letter digit sequence choice star choice _ letter _ in
general a graph (`a / `b) / `c → `a / `b / `c
Conflicts?
SELECT * FROM users
SELECT * FROM users | r | r := ^
User fromRow: r .
expr sql |
SELECT * FROM users <SQL: >
expr sql / ordered
No Conflicts
No Ambiguities
expr sql / surprise
/ expr sql surprise
expr sql | !expr sql / !sql expr
expr sql $ !expr sql / !sql expr / ui