• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
          • Syntax-for-tools
            • Formalized-subset
            • Mapping-to-language-definition
            • Input-files
            • Compilation-database
            • Printer
            • Output-files
            • Abstract-syntax-operations
            • Implementation-environments
            • Abstract-syntax
            • Concrete-syntax
            • Disambiguation
            • Validation
            • Gcc-builtins
            • Preprocessing
              • Preprocessor
                • Preprocessor-states
                • Pread-token/newline
                • Pread-token
                • Preprocessor-lexer
                • Pproc-files
                • Preprocessor-printer
                • Pproc-file
                • Filepath-plexeme-list-alist-to-filepath-filedata-map
                • Filepath-plexeme-list-alist
                • Preprocessor-reader
                • Preprocessor-messages
              • External-preprocessing
            • Parsing
          • Atc
          • Transformation-tools
          • Language
          • Representation
          • Insertion-sort
          • Pack
        • Soft
        • Bv
        • Imp-language
        • Ethereum
        • Event-macros
        • Java
        • Riscv
        • Bitcoin
        • Zcash
        • Yul
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
        • Number-theory
        • Axe
        • Lists-light
        • Builtins
        • Solidity
        • Helpers
        • Htclient
        • Typed-lists-light
        • Arithmetic-light
      • X86isa
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Preprocessing

Preprocessor

A preprocessor for C.

We provide a preprocessor for C that, unlike typical preprocessors, preserves the information about the #include directives. That is, it does not replace such directives with the (preprocessed) contents of the referenced files, but it otherwise performs the rest of the preprocessing.

Our preprocessor maps a list of file paths to a file set (see files): it preprocesses all the files with the given file paths, as well as all the files directly and indirectly included. The resulting file set contains entries for all such files, not only the ones with the given file paths.

Our preprocessor reads characters and lexes them into lexemes, while executing the preprocessing directives. The resulting sequence of lexemes is then turned into characters that are written into files. The resulting file set is amenable to our parser (more precisely, it will be, once we have extended our parser to accept #include directives in certain places). Our preprocessor preserves white space, in order to preserve the layout (modulo the inherent layout changes caused by preprocessing). Our preprocessor also preserves comments, although some comments may no longer apply to preprocessed code (e.g. comments talking about macros).

Currently some of this preprocessor's code duplicates, at some level, some of the code in the parser (including the lexer and the reader). At some point we should integrate the preprocessor with the parser.

This preprocessor is still work in progress.

Subtopics

Preprocessor-states
States of the preprocessor.
Pread-token/newline
Read a token or newline during preprocessing.
Pread-token
Read a token during preprocessing.
Preprocessor-lexer
Lexer component of the preprocessor.
Pproc-files
Preprocess zero or more files.
Preprocessor-printer
Printer component of the preprocessor.
Pproc-file
Preprocess a file.
Filepath-plexeme-list-alist-to-filepath-filedata-map
Turn an alist from file paths to lists of preprocessing lexemes into a map from file paths to file data.
Filepath-plexeme-list-alist
Fixtype of alists from file paths to lists of preprocessing lexemes.
Preprocessor-reader
Reader component of the preprocessor.
Preprocessor-messages
Messages from he preprocessor (including lexer and reader).