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