On the Complexity and Performance of Parsing with Derivatives

Michael D. Adams, Celeste Hollenbeck, and Matthew Might

Status: Accepted. To be published at PLDI 2016

Abstract

Current algorithms for context-free parsing inflict a trade-off between ease of understanding, ease of implementation, theoretical complexity, and practical performance. No algorithm achieves all of these properties simultaneously.

Might et al. (2011) introduced parsing with derivatives, which handles arbitrary context-free grammars while being both easy to understand and simple to implement. Despite much initial enthusiasm and a multitude of independent implementations, its worst-case complexity has never been proven to be better than exponential. In fact, high-level arguments claiming it is fundamentally exponential have been advanced and even accepted as part of the folklore. Performance ended up being sluggish in practice, and this sluggishness was taken as informal evidence of exponentiality.

In this paper, we reexamine the performance of parsing with derivatives. We have discovered that it is not exponential but, in fact, cubic. Moreover, simple (though perhaps not obvious) modifications to the implementation by Might et al. (2011) lead to an implementation that is not only easy to understand but also highly performant in practice.

Keywords

Parsing; Parsing with derivatives; Performance

Citation

Michael D. Adams, Celeste Hollenbeck, and Matthew Might. On the complexity and performance of parsing with derivatives. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’16. ACM, New York, NY, USA, June 2016. ISBN 978-1-4503-4261-2. doi: 10.1145/2908080.2908128.

BibTeX Entry

@inproceedings{adams2016derivatives,
  author = {Adams, Michael D. and Hollenbeck, Celeste and Might, Matthew},
  title = {On the Complexity and Performance of Parsing with Derivatives},
  booktitle = {Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation},
  year = {2016},
  series = {PLDI '16},
  address = {New York, NY, USA},
  month = jun,
  publisher = {ACM},
  isbn = {978-1-4503-4261-2},
  doi = {10.1145/2908080.2908128},
}

Copyright Notice

© ACM, 2016. This is the author’s version of the work. It is posted here by permission of ACM for your personal use. Not for redistribution. The definitive version was published in Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation, (2016). http://doi.acm.org/10.1145/2908080.2908128.