论文标题

钉子的语义框架

A Semantic Framework for PEGs

论文作者

Medeiros, Sérgio, Olarte, Carlos

论文摘要

解析表达语法(PEG)是一种基于识别的形式主义,可以描述语言的句法和词汇元素。无上下文语法(CFG)和PEG之间的主要区别在于选择操作员的解释:而CFG的无序选择E | E'被解释为E和E所认可的语言的结合,如果E成功,则钉在优先选择的e/e'dost e'。如此微妙但重要的区别改变了识别语言,并产生更有效的解析算法。本文提出了针对钉子的重写逻辑语义。我们从重写理论开始,赋予钉子中通常的结构。后来,我们表明剪切是控制钉子中回溯的机制,在我们的框架中也发现了自然的表示。我们概括了这种机制,以精确,统一和正式的语义允许本地和全球削减。因此,我们的工作努力更好地理解和控制PEG的解析器。我们提出的语义是可执行的,除了是具有适度效率的解析器外,它还可以用作测试不同优化想法的操场。更重要的是,它是一种数学工具,可用于不同的分析。

Parsing Expression Grammars (PEGs) are a recognition-based formalism which allows to describe the syntactical and the lexical elements of a language. The main difference between Context-Free Grammars (CFGs) and PEGs relies on the interpretation of the choice operator: while the CFGs' unordered choice e | e' is interpreted as the union of the languages recognized by e and e, the PEGs' prioritized choice e/e' discards e' if e succeeds. Such subtle, but important difference, changes the language recognized and yields more efficient parsing algorithms. This paper proposes a rewriting logic semantics for PEGs. We start with a rewrite theory giving meaning to the usual constructs in PEGs. Later, we show that cuts, a mechanism for controlling backtracks in PEGs, finds also a natural representation in our framework. We generalize such mechanism, allowing for both local and global cuts with a precise, unified and formal semantics. Hence, our work strives at better understanding and controlling backtracks in parsers for PEGs. The semantics we propose is executable and, besides being a parser with modest efficiency, it can be used as a playground to test different optimization ideas. More importantly, it is a mathematical tool that can be used for different analyses.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源