English

Interval Parsing Grammars for File Format Parsing

Programming Languages 2023-04-24 v2

Abstract

File formats specify how data is encoded for persistent storage. They cannot be formalized as context-free grammars since their specifications include context-sensitive patterns such as the random access pattern and the type-length-value pattern. We propose a new grammar mechanism called Interval Parsing Grammars IPGs) for file format specifications. An IPG attaches to every nonterminal/terminal an interval, which specifies the range of input the nonterminal/terminal consumes. By connecting intervals and attributes, the context-sensitive patterns in file formats can be well handled. In this paper, we formalize IPGs' syntax as well as its semantics, and its semantics naturally leads to a parser generator that generates a recursive-descent parser from an IPG. In general, IPGs are declarative, modular, and enable termination checking. We have used IPGs to specify a number of file formats including ZIP, ELF, GIF, PE, and part of PDF; we have also evaluated the performance of the generated parsers.

Cite

@article{arxiv.2304.04859,
  title  = {Interval Parsing Grammars for File Format Parsing},
  author = {Jialun Zhang and Greg Morrisett and Gang Tan},
  journal= {arXiv preprint arXiv:2304.04859},
  year   = {2023}
}

Comments

To appear on PLDI'23

R2 v1 2026-06-28T09:58:19.898Z