paperbot · PL 论文追踪

全部论文 待读 收藏

P2 A Simple, Possibly Correct LR Parser for C11

一个简单、或许正确的C11 LR解析器
TOPLAS 39(4)2017匹配度 2/10 · 该论文研究C11语言的LALR(1)解析器实现,属于经典编译前端与语法分析工程,与用户关注的静态分析、LLM/Agent交叉、浮点程序分析、贝叶斯程序分析等核心方向没有直接关系。它可能作为构建C分析工具的基础设施,但不涉及AI/PL交叉或新分析技术。引用 11 inbox
Jacques-Henri Jourdan, François Pottier
dblp: 2026-09-10crossref: 2026-09-10

AI 速览

一句话:提出一个简单且接近C11标准的LALR(1)解析器,用词法反馈与作用域处理解决歧义。

C11标准用歧义上下文无关文法描述语法,并借助英文散文说明作用域和歧义片段的解释,因此实现合规解析器并不简单。作者梳理主要困难,提出结合LALR(1)与词法反馈的解析方案:改进词法反馈以兼容向前看,简化作用域处理,并对文法作少量修正。该解析器虽未形式验证,但避免其他实现的若干陷阱;其简洁性、声明式风格及与C11文法的高度相似性构成正确性的非形式论据。作者还附带一组棘手C11程序测试集,望作为编译器与分析工具的参考或起点。

问题
如何实现一个符合C11标准、能正确处理文法歧义与作用域规则的解析器。
方法
将LALR(1)解析器与改进的词法反馈机制结合,简化作用域处理并修正文法。
评估
通过一组精心设计的棘手C11程序测试,并与其他实现易错点比较,进行非形式论证。
原文摘要(Abstract)

The syntax of the C programming language is described in the C11 standard by an ambiguous context-free grammar, accompanied with English prose that describes the concept of “scope” and indicates how certain ambiguous code fragments should be interpreted. Based on these elements, the problem of implementing a compliant C11 parser is not entirely trivial. We review the main sources of difficulty and describe a relatively simple solution to the problem. Our solution employs the well-known technique of combining an LALR(1) parser with a “lexical feedback” mechanism. It draws on folklore knowledge and adds several original aspects, including a twist on lexical feedback that allows a smooth interaction with lookahead; a simplified and powerful treatment of scopes; and a few amendments in the grammar. Although not formally verified, our parser avoids several pitfalls that other implementations have fallen prey to. We believe that its simplicity, its mostly declarative nature, and its high similarity with the C11 grammar are strong informal arguments in favor of its correctness. Our parser is accompanied with a small suite of “tricky” C11 programs. We hope that it may serve as a reference or a starting point in the implementation of compilers and analysis tools.

链接与引用

DOI 原文 · PDF(开放获取) · DBLP

BibTeX
@article{JourdanP17,
  title = {A Simple, Possibly Correct LR Parser for C11},
  author = {Jacques-Henri Jourdan and François Pottier},
  journal = {ACM Transactions on Programming Languages and Systems},
  volume = {39},
  number = {4},
  year = {2017},
  doi = {10.1145/3064848}
}