Loading...
Searching...
No Matches
Parser

Definition

Fortran Preprocessor (fpx) – core parsing and preprocessing module.

This module implements a full-featured, modern Fortran preprocessor supporting:

  • C-style line continuations with \ and \\
  • Fortran-style & continuations
  • #define, #undef, object-like and function-like macros with variadic support
  • #include with proper path resolution and recursion guard
  • Conditional compilation: #if, #ifdef, #ifndef, #elif, #else, #endif
  • Non-standard #for directive
  • C-style /* ... */ comments (nestable aware)
  • Macro expansion with argument substitution and stringification (#) / token-pasting (##)
  • Interactive REPL mode when reading from stdin
  • Multiple entry points for file-to-file, unit-to-unit, etc.
  • Support ${x} for substituting macro name

The preprocessor is designed to be standards-conforming where possible while adding useful extensions (variadic macros, better diagnostics, include path handling).

Examples

  1. Preprocess a file to stdout:
    call preprocess('input.F90')
  2. Preprocess a file and write to another file:
    call preprocess('src/main.F90', 'preprocessed/main.F90')
  3. Use in a build system with unit numbers:
    integer :: iu, ou
    open(newunit=iu, file='input.F90')
    open(newunit=ou, file='output.F90')
    call preprocess(iu, ou)
    close(iu); close(ou)
  4. Interactive mode (stdin to stdout):
    $ ./fpx
    [in] #define PI 3.1415926535
    [out]
    [in] real :: x = pi*2
    [out] real :: x = 3.1415926535*2
    [in] (empty line or 'quit' to exit)

Data Types

interface  preprocess
 Generic interface to start preprocessing from various sources/sinks. More...