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
Proglrの紹介
Search
tkob
March 31, 2018
0
510
Proglrの紹介
tkob
March 31, 2018
Tweet
Share
Featured
See All Featured
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
310
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
The Spectacular Lies of Maps
axbom
PRO
1
520
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
Building Adaptive Systems
keathley
44
2.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
320
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
160
How GitHub (no longer) Works
holman
316
140k
Transcript
Proglrの紹介 tkob https://github.com/tkob/proglr
SMLと私 • ML-MessagePack https://github.com/tkob/mlmsgpack • UXML https://github.com/tkob/uxml – XML Parser
• SMLZIP https://github.com/tkob/smlzip – Access to ZIP files • 最近の活動 – SMLでsyslogdを作っています
Proglrの紹介 • SML向けのパーサージェネレーター – 私が作りました • BNFC互換のLBNFからパーサーとASTを生成 • Generalized LR
• 生成したパーサーが多くのSML処理系で使える
BNFC互換のLabelled BNF文法定義 token Add "+" ; … token Integer of
int; EAdd. Exp ::= Exp "+" Exp1 ; ESub. Exp ::= Exp "-" Exp1 ; EMul. Exp1 ::= Exp1 "*" Exp2 ; EDiv. Exp1 ::= Exp1 "/" Exp2 ; EInt. Exp2 ::= Integer ; coercions Exp 2 ;
生成されるAST structure Ast = struct datatype exp = EAdd of
Lex.span * exp * exp | ESub of Lex.span * exp * exp | EMul of Lex.span * exp * exp | EDiv of Lex.span * exp * exp | EInt of Lex.span * int …
生成されるパーサー(概略イメージ) fun go … = … and state15 … =
… … (* stateNが続く *) and state0 … = … fun parse sourcemap strm = … (* go を呼ぶ *) • 相互末尾再帰関数で状態を表現する – 読めなくもない気分のコード
parseの型 val parse : sourcemap -> strm -> Ast.exp list
• 何故Ast.expでなくAst.exp listなのか – 多義的な文法かもしれない(文脈自由文法) – ProglrはGeneralized LRを使用
なぜGLRなのか • あまり深い理由は… – 自分のパーサージェネレーターがほしい! – 教科書を読みながらまずはLR(0)まで作成 • 面倒くさくなってきた –
手っ取り早く表現力をあげられないか? – LR(0)ベースのGLRにするのが一番はやい(と思った)
Q: Proglrは私のSMLコンパイラで使えますか? • A: きっと… – 対応処理系: • SML/NJ, MLton,
Poly/ML, Alice ML, MLKit, Moscow ML, SML# – Proglr自体はMLtonかPoly/MLでビルドするのがおすすめ
Proglrの利用方法(MLton) $ proglr -m mlton -o parse.sml -l scan.ulex calc.cf
$ mlton main.mlb $ ./main sample.txt • -mオプションで処理系を指定するとプロジェクト一式 (MakefileやMLBやCM)が全部生成される • 用意するのは文法だけ
おわり • 大体全部の現存SML処理系で使えるパーサージェネレー ターのProglrを紹介しました