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:
PetitParser is an implementation of a Smalltalk parser in PetitParser.
Compiled PetitParser is a compiled version of the above parser.
SmaCC is a parser compiled by SmaCC (see more) from a LALR grammar.
Hand-Written is a hand-written parser used by Pharo to compile its code.
Speedup compared to PetitParser.
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:
Identifier parses list of identifiers
Arithmetics parses an aritmetic expressions (with priorities of operators)
Smalltalk is PetitParser implementation of Smalltalk grammar.
Java is PetitParser implementation of Java grammar.
Python is an island gramar that extracts structure of Python programs while utilizing indentation.
| petitParser compiledParser |
petitParser := PPSmalltlakParser new.
"compilation might be costly do it only when you change your parser"
compiledParser := parser compile.
compiledParser parse: 'foo ^ 1'.
Do not hesitate to contact us, if you want to port into your own Smallatlk.
Publications
2016
Jan Kur, Jan Vraný, Mohammad Ghafari, Mircea Lungu, and Oscar Nierstrasz. Optimizing Parser Combinators. In Proceedings of International Workshop on Smalltalk Technologies (IWST 2016), p. 1:1—1:13, 2016.DOIPDF→