SuperC: Parsing all of C by taming the preprocessor

Paul Gazzillo, Robert Grimm

Research output: Contribution to journalArticle

Abstract

C tools, such as source browsers, bug finders, and automated refactorings, need to process two languages: C itself and the preprocessor. The latter improves expressivity through file includes, macros, and static conditionals. But it operates only on tokens, making it hard to even parse both languages. This paper presents a complete, performant solution to this problem. First, a configurationpreserving preprocessor resolves includes and macros yet leaves static conditionals intact, thus preserving a program's variability. To ensure completeness, we analyze all interactions between preprocessor features and identify techniques for correctly handling them. Second, a configuration- preserving parser generates a wellformed AST with static choice nodes for conditionals. It forks new subparsers when encountering static conditionals and merges them again after the conditionals. To ensure performance, we present a simple algorithm for table-driven Fork-Merge LR parsing and four novel optimizations. We demonstrate the effectiveness of our approach on the x86 Linux kernel.

Original languageEnglish (US)
Pages (from-to)323-334
Number of pages12
JournalACM SIGPLAN Notices
Volume47
Issue number6
DOIs
StatePublished - Aug 2012

Fingerprint

Macros
Linux

Keywords

  • C
  • Fork-Merge LR parsing
  • LR parsing
  • Preprocessor
  • SuperC

ASJC Scopus subject areas

  • Computer Science(all)

Cite this

SuperC : Parsing all of C by taming the preprocessor. / Gazzillo, Paul; Grimm, Robert.

In: ACM SIGPLAN Notices, Vol. 47, No. 6, 08.2012, p. 323-334.

Research output: Contribution to journalArticle

Gazzillo, Paul ; Grimm, Robert. / SuperC : Parsing all of C by taming the preprocessor. In: ACM SIGPLAN Notices. 2012 ; Vol. 47, No. 6. pp. 323-334.
@article{2829353e7f7f4b92ad823da0bf845011,
title = "SuperC: Parsing all of C by taming the preprocessor",
abstract = "C tools, such as source browsers, bug finders, and automated refactorings, need to process two languages: C itself and the preprocessor. The latter improves expressivity through file includes, macros, and static conditionals. But it operates only on tokens, making it hard to even parse both languages. This paper presents a complete, performant solution to this problem. First, a configurationpreserving preprocessor resolves includes and macros yet leaves static conditionals intact, thus preserving a program's variability. To ensure completeness, we analyze all interactions between preprocessor features and identify techniques for correctly handling them. Second, a configuration- preserving parser generates a wellformed AST with static choice nodes for conditionals. It forks new subparsers when encountering static conditionals and merges them again after the conditionals. To ensure performance, we present a simple algorithm for table-driven Fork-Merge LR parsing and four novel optimizations. We demonstrate the effectiveness of our approach on the x86 Linux kernel.",
keywords = "C, Fork-Merge LR parsing, LR parsing, Preprocessor, SuperC",
author = "Paul Gazzillo and Robert Grimm",
year = "2012",
month = "8",
doi = "10.1145/2345156.2254103",
language = "English (US)",
volume = "47",
pages = "323--334",
journal = "ACM SIGPLAN Notices",
issn = "1523-2867",
publisher = "Association for Computing Machinery (ACM)",
number = "6",

}

TY - JOUR

T1 - SuperC

T2 - Parsing all of C by taming the preprocessor

AU - Gazzillo, Paul

AU - Grimm, Robert

PY - 2012/8

Y1 - 2012/8

N2 - C tools, such as source browsers, bug finders, and automated refactorings, need to process two languages: C itself and the preprocessor. The latter improves expressivity through file includes, macros, and static conditionals. But it operates only on tokens, making it hard to even parse both languages. This paper presents a complete, performant solution to this problem. First, a configurationpreserving preprocessor resolves includes and macros yet leaves static conditionals intact, thus preserving a program's variability. To ensure completeness, we analyze all interactions between preprocessor features and identify techniques for correctly handling them. Second, a configuration- preserving parser generates a wellformed AST with static choice nodes for conditionals. It forks new subparsers when encountering static conditionals and merges them again after the conditionals. To ensure performance, we present a simple algorithm for table-driven Fork-Merge LR parsing and four novel optimizations. We demonstrate the effectiveness of our approach on the x86 Linux kernel.

AB - C tools, such as source browsers, bug finders, and automated refactorings, need to process two languages: C itself and the preprocessor. The latter improves expressivity through file includes, macros, and static conditionals. But it operates only on tokens, making it hard to even parse both languages. This paper presents a complete, performant solution to this problem. First, a configurationpreserving preprocessor resolves includes and macros yet leaves static conditionals intact, thus preserving a program's variability. To ensure completeness, we analyze all interactions between preprocessor features and identify techniques for correctly handling them. Second, a configuration- preserving parser generates a wellformed AST with static choice nodes for conditionals. It forks new subparsers when encountering static conditionals and merges them again after the conditionals. To ensure performance, we present a simple algorithm for table-driven Fork-Merge LR parsing and four novel optimizations. We demonstrate the effectiveness of our approach on the x86 Linux kernel.

KW - C

KW - Fork-Merge LR parsing

KW - LR parsing

KW - Preprocessor

KW - SuperC

UR - http://www.scopus.com/inward/record.url?scp=84866363385&partnerID=8YFLogxK

UR - http://www.scopus.com/inward/citedby.url?scp=84866363385&partnerID=8YFLogxK

U2 - 10.1145/2345156.2254103

DO - 10.1145/2345156.2254103

M3 - Article

VL - 47

SP - 323

EP - 334

JO - ACM SIGPLAN Notices

JF - ACM SIGPLAN Notices

SN - 1523-2867

IS - 6

ER -