arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2011.04360cs.FLcs.PL
收藏

PEG的语义框架

A Semantic Framework for PEGs

Sérgio Medeiros, Carlos Olarte

摘要:

解析表达式语法(PEG)是一种基于语法的形式主义,它允许描述语言的语法和词汇元素。上下文无关文法(CFG)和PEG之间的主要区别依赖于选择运算符的解释:而CFG的无序选择运算符e| e'被解释为e和e识别的语言的并集,如果e成功,则PEG的优先选择e/e'丢弃e'。这种微妙但重要的差异改变了识别的语言,并产生了更有效的解析算法。本文提出了一种可重写的PEG逻辑语义。我们从重写理论开始,为PEG中的常用结构赋予意义。后来,我们表明,削减,在PEG中控制回溯的机制,发现在我们的框架中也是一个自然的表示。我们推广这样的机制,允许本地和全球削减一个精确的,统一的和正式的语义。因此,我们的工作力求更好地理解和控制在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.

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

↑