当前位置: X-MOL 学术arXiv.cs.PL › 论文详情
Our official English website, www.x-mol.net, welcomes your feedback! (Note: you will need to create a separate account there.)
A Semantic Framework for PEGs
arXiv - CS - Programming Languages Pub Date : 2020-11-09 , DOI: arxiv-2011.04360
S\'ergio Medeiros and Carlos Olarte

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.

中文翻译:

PEG 的语义框架

解析表达式语法 (PEG) 是一种基于识别的形式主义,它允许描述语言的句法和词汇元素。上下文无关文法 (CFG) 和 PEG 之间的主要区别取决于选择运算符的解释:而 CFG 的无序选择 e | e' 被解释为 e 和 e 识别的语言的联合,如果 e 成功,PEG 的优先选择 e/e' 丢弃 e'。这种微妙但重要的差异改变了识别的语言并产生更有效的解析算法。本文提出了一种 PEG 的重写逻辑语义。我们从重写理论开始,为 PEG 中的常见结构赋予意义。后来,我们展示了 cut,一种控制 PEG 中回溯的机制,在我们的框架中也找到了自然的表示。我们概括了这种机制,允许使用精确、统一和正式的语义进行局部和全局切割。因此,我们的工作致力于更好地理解和控制 PEG 解析器中的回溯。我们提出的语义是可执行的,除了作为一个效率适中的解析器之外,它还可以用作测试不同优化思想的游乐场。更重要的是,它是一种可用于不同分析的数学工具。
更新日期:2020-11-10
down
wechat
bug