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.
翻译:文件格式规定了数据如何进行编码以实现持久化存储。由于文件格式规范中包含上下文相关的模式,例如随机访问模式和类型-长度-值模式,因此无法将其形式化为上下文无关文法。我们提出了一种新的文法机制,称为区间解析文法(Interval Parsing Grammars,IPG)。IPG为每个非终结符/终结符附加一个区间,该区间指定了该非终结符/终结符所消耗的输入范围。通过连接区间与属性,可以很好地处理文件格式中的上下文相关模式。在本文中,我们形式化了IPG的语法及其语义,其语义自然地引出了一个解析器生成器,该生成器能够从IPG生成递归下降解析器。一般来说,IPG具有声明性、模块化特性,并支持终止性检查。我们已使用IPG来规范多种文件格式,包括ZIP、ELF、GIF、PE以及部分PDF;同时,我们还评估了所生成解析器的性能。