PetitParser Compiler

![Logo](https://scg.unibe.ch/assets/files/ba/756pt73kvee5u2lojwv0jrog8wxd9q/pc-logo-v2.png)


Petit Compiler accepts PetitParser as input and produces a Smalltalk class with an equivalent top-down parser. Combinators of PetitParser are analyzed and the fastest parsing strategy is choosen for each of them. The compiled parser is significantly faster.



Performance

Smalltalk

We compare four different Smalltalk parsers. All of them create an identical AST:

![Smalltalk-speedup](https://scg.unibe.ch/assets/files/99/grhp8rrtv1sct6ezrqtzmsicuhf71v/performance-smalltalk-speedup.png)
Speedup compared to PetitParser.
![Smalltalk-tpc](https://scg.unibe.ch/assets/files/55/n97jiqzxq7jjt7bpu5v8dw1lllrcez/performance-smalltalk-tpc.png)
Average time per character for each of the parsers.

Other Benchmarks

In general, we measure performance speedup ranging form factor two to ten. In the figure bellow, there is a speedup for the following grammars:

![Speedup](https://scg.unibe.ch/assets/files/b8/rwxmje9y5a1teein09iyfwb4sb41fg/performance-0.png)

Installation

Gofer new smalltalkhubUser: 'JanKurs' project: 'PetitParser';
    configurationOf: #PetitCompiler; load.
(Smalltalk at: #ConfigurationOfPetitCompiler) perform: #'loadStable'.

Using PetitCompiler

| petitParser compiledParser |
petitParser := PPSmalltlakParser new.
"compilation might be costly do it only when you change your parser"
compiledParser := parser compile.
compiledParser parse: 'foo ^ 1'.

Visit Smalltalkhub for more information.

Limitations

Supported Smalltalks

PetitCompiler supports Pharo 5 and Smalltalk/X.

Do not hesitate to contact us, if you want to port into your own Smallatlk.

Publications

Author Page