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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
攻撃者視点で考えるDetection Engineering
cryptopeg
3
2k
時期が悪い!それでもRaspberry Piを買って遊んで活用するには / 20260627-osc26do-rpi-jikigawarui
akkiesoft
0
140
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.7k
AWS Security Hub CSPMの成功・失敗体験
cmusudakeisuke
0
450
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
180
iOS アプリの「これって不具合ですか?」を AI に調べてもらう
miichan
0
130
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
170
AWS Security Agent といっしょに脅威モデリングをやってみよう
amarelo_n24
1
200
クラウドファンディング版StackChan 3体(4体)をインタラクティブな体験型作品にして展示もした話 / スタックチャンお誕生日会2026
you
PRO
0
150
【2026年版】 ベクトル検索とEmbedding最前線
mocobeta
23
7k
秘密度ラベル初心者が第1歩でつまづかないための「設計・運用」ポイント
seafay
PRO
1
430
感情と身体を置き去りにしない、エンジニアの生きのこり方 ──いまから、ここから「自分の状態」を扱うという選択
saorimurooka
0
200
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
480
GitHub's CSS Performance
jonrohan
1033
470k
The Invisible Side of Design
smashingmag
301
52k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
610
YesSQL, Process and Tooling at Scale
rocio
174
15k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
320
Unsuck your backbone
ammeep
672
58k
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