1
PetitParser CompilerJan Kurš & Jan Vraný
Mohammad Ghafari, Mircea Lungu and
Oscar Nierstrasz
3
Parsing Contexts
Bounded Seas
Furthest Failure
Layout-senstivity
6
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
7
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
8
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
9
id ← #letter #word*
expr ← term /‘(‘ expr ‘)’ /…
10
id ← #letter #word*
expr ← term /‘(‘ expr ‘)’ /…
11
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
12
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
13
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
14
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
15
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
17
id ← #letter #word*
block ← #INDENT expr / block /
… #DEDENT
expr ← term /‘(‘ expr ‘)’ /…
18
PetitParserCompiler
19
10k methods of Pharo code
3 parsers
Compared to Compiled PetitParser
Speedup
20PetitParser SmaCC RBParser
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
21Expressions Python Smalltalk Java Ruby
0
2
4
6
8
10
12
14
22
PetitParser SmaCC RBParser0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
Compiler
23
map:
Plusprogram
TokenclassToken
TokenidToken
Sequencebody
Actionclass
Sequenceidentifier
Sequence
ClassNode new id: idToken value body: body
CharClass#letter
ChoiceletterOrDigit
CharClass#digit
Star
… Indentindent
Star Dedentdedent
Choice
Actionmethod
…
24
0
0.2
0.4
0.6
0.8
1
1.2Ti
me [
mic
rose
conds]
Time per Character of Smalltalk
Compiled ParserGC time