• 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
                • Pproc
                • Preprocessor-states
                • Preprocessor-printer
                • Pproc-directive
                • Pread-token
                • Pproc-files
                • Pread-token/newline
                • Pproc-group-part
                • Preprocessor-lexer
                • Pproc-file
                • Pproc-include-directive
                • Pproc-text-line
                • Pproc-*-group-part
                • Punread-token
                • *pproc-files-max*
                • String-plexeme-list-alist-to-filepath-filedata-map
                • String-plexeme-list-alist
                • Read-input-file-to-preproc
                • 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 in some cases. 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. This is only done under certain conditions; in general, the C preprocessor operates at a low lexical level, making it difficult to preserve code structure in general.

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

Pproc
Preprocess files.
Preprocessor-states
States of the preprocessor.
Preprocessor-printer
Printer component of the preprocessor.
Pproc-directive
Preprocess a directive.
Pread-token
Read a token during preprocessing.
Pproc-files
Preprocess zero or more files.
Pread-token/newline
Read a token or new line during preprocessing.
Pproc-group-part
Preprocess a group part.
Preprocessor-lexer
Lexer component of the preprocessor.
Pproc-file
Preprocess a file.
Pproc-include-directive
Preprocess a #include directive.
Pproc-text-line
Preprocess a (non-empty) text line.
Pproc-*-group-part
Preprocess zero or more group parts.
Punread-token
Unread a token.
*pproc-files-max*
Maximum number of files being preprocessed.
String-plexeme-list-alist-to-filepath-filedata-map
Turn (1) an alist from string to lists of preprocessing lexemes into (2) a map from file paths to file data.
String-plexeme-list-alist
Fixtype of alists from strings to lists of preprocessing lexemes.
Read-input-file-to-preproc
Read a file to preprocess, explicitly specified as user input.
Preprocessor-reader
Reader component of the preprocessor.
Preprocessor-messages
Messages from he preprocessor (including lexer and reader).