arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1207.0443cs.FL
收藏

解析表达式文法中的左递归

Left Recursion in Parsing Expression Grammars

Sérgio Medeiros, Fabio Mascarenhas, Roberto Ierusalimschy

摘要:

解析表达式语法(Parsing Expression Grammars,PEG)是一种形式主义,它可以通过一组规则来描述所有确定性上下文无关语言,这些规则指定了某种语言的自顶向下解析器。PEG易于使用,并且在几种程序设计语言中有PEG库的有效实现。PEG的一个经常被忽略的功能是左递归,它通常用于上下文无关文法(CFG)中,以编码左关联操作。我们提出了一个简单的保守扩展的语义PEG,直接和间接的左递归规则提供了有用的意义,并表明,我们的扩展可以很容易地表达左递归成语从CFG的PEG,具有类似的结果。我们证明了这些扩展的保守性,也证明了他们的工作与任何左递归PEG。PEG也可以在低级解析机中编译成程序。我们提出了一个扩展的语义分析机器的操作,让它解释左递归PEG,并证明这种扩展是正确的关于我们的语义左递归PEG。

英文摘要:

Parsing Expression Grammars (PEGs) are a formalism that can describe all deterministic context-free languages through a set of rules that specify a top-down parser for some language. PEGs are easy to use, and there are efficient implementations of PEG libraries in several programming languages. A frequently missed feature of PEGs is left recursion, which is commonly used in Context-Free Grammars (CFGs) to encode left-associative operations. We present a simple conservative extension to the semantics of PEGs that gives useful meaning to direct and indirect left-recursive rules, and show that our extensions make it easy to express left-recursive idioms from CFGs in PEGs, with similar results. We prove the conservativeness of these extensions, and also prove that they work with any left-recursive PEG. PEGs can also be compiled to programs in a low-level parsing machine. We present an extension to the semantics of the operations of this parsing machine that let it interpret left-recursive PEGs, and prove that this extension is correct with regards to our semantics for left-recursive PEGs.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑