A Simple, Possibly Correct LR Parser for C11

Author:

Jourdan Jacques-Henri1,Pottier François2

Affiliation:

1. Inria Paris, MPI-SWS, Saarbrücken, Germany

2. Inria Paris, Paris Cedex, France

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.

Funder

Agence Nationale de la Recherche

Publisher

Association for Computing Machinery (ACM)

Subject

Software

Reference35 articles.

1. 1992. Lookahead vs. Scanner Feedback. Retrieved from https://groups.google.com/forum/#!topic/comp.compilers/gqeQy3mXqnA. 1992. Lookahead vs. Scanner Feedback. Retrieved from https://groups.google.com/forum/#!topic/comp.compilers/gqeQy3mXqnA.

2. Alfred V. Aho Ravi Sethi and Jeffrey D. Ullman. 1986. Compilers: Principles Techniques and Tools. Addison Wesley. Alfred V. Aho Ravi Sethi and Jeffrey D. Ullman. 1986. Compilers: Principles Techniques and Tools. Addison Wesley.

3. ANSI. 1989. ANSI X3.159-1989 Programming Language C. (1989). ANSI. 1989. ANSI X3.159-1989 Programming Language C. (1989).

4. Eli Bendersky. 2012. How Clang handles the type / variable name ambiguity of C/C++. Retrieved from http://eli.thegreenplace.net/2012/07/05/how-clang-handles-the-type-variable-name-ambiguity-of-cc/. Eli Bendersky. 2012. How Clang handles the type / variable name ambiguity of C/C++. Retrieved from http://eli.thegreenplace.net/2012/07/05/how-clang-handles-the-type-variable-name-ambiguity-of-cc/.

Cited by 5 articles. 订阅此论文施引文献 订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献

1. Ranked Syntax Completion With LR Parsing;Proceedings of the 39th ACM/SIGAPP Symposium on Applied Computing;2024-04-08

2. A text-based syntax completion method using LR parsing and its evaluation;Science of Computer Programming;2023-06

3. Petr4: formal foundations for p4 data planes;Proceedings of the ACM on Programming Languages;2021-01-04

4. Exploring C semantics and pointer provenance;Proceedings of the ACM on Programming Languages;2019-01-02

5. A Simple, Possibly Correct LR Parser for C11;ACM Transactions on Programming Languages and Systems;2017-09-18

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3