First Pass - Initial processing
In the context of compilers (like COBOL) or assemblers (like HLASM) on z/OS, the "first pass" refers to the initial scan of the source code. Its primary purpose is to collect symbolic information, build symbol tables, and perform basic syntax checking without generating executable code.
Key Characteristics
-
- Symbol Table Construction: Identifies and records all defined symbols (variables, labels, procedure names) and their attributes (e.g., data type, length, address offset) in a symbol table.
- Syntax Analysis (Basic): Performs an initial check for fundamental syntax errors, such as missing keywords or incorrect statement structures, without deep semantic validation.
- Address Assignment (Relative): For assemblers, it often assigns relative addresses or offsets to symbols and instructions, preparing for the second pass where absolute addresses are resolved.
- Macro Expansion: In some compilers/assemblers, macro expansion might occur during the first pass, replacing macro calls with their expanded code.
- No Object Code Generation: Typically, no executable object code is generated during this pass; its output is primarily the symbol table and possibly an intermediate representation.
- Early Error Detection: Catches many common programming errors related to symbol definition and basic syntax early in the compilation/assembly process.
Use Cases
-
- COBOL Compilation: The COBOL compiler performs a first pass to build its internal symbol tables for data items (e.g.,
PICclauses,USAGE), procedure names, and section/paragraph labels. - HLASM Assembly: The High-Level Assembler (HLASM) uses a first pass to define symbols, assign relative locations, and process
EQUandDS/DCstatements to determine storage requirements. - Link-Edit Preparation: The information gathered in the first pass (e.g., symbol definitions, external references) is crucial for the subsequent link-editing process, even if not directly generating object code.
- Pre-compilers/Analyzers: Tools that perform static analysis or pre-compilation steps might employ a "first pass" concept to gather initial metadata about the source code before full compilation.
- COBOL Compilation: The COBOL compiler performs a first pass to build its internal symbol tables for data items (e.g.,
Related Concepts
The first pass is an integral part of the compiler/assembler toolchain on z/OS, directly preceding the second pass. While the first pass focuses on symbol resolution and basic syntax, the second pass uses the symbol table built in the first pass to generate the actual object code, resolve forward references, and produce the final executable output. It is fundamental to how source code (e.g., COBOL, Assembler) is transformed into load modules that can be executed by the z/OS operating system.
- Clean Code Structure: Writing well-structured COBOL or Assembler code with clear variable definitions and labels helps the first pass efficiently build accurate symbol tables, reducing potential issues.
- Early Error Resolution: Address any syntax errors reported during the first pass promptly, as these can cascade into more complex issues in subsequent compilation/assembly stages.
- Understand Compiler Listings: Familiarize yourself with the compiler/assembler listing, as it often provides insights into the symbol table generated during the first pass, which is invaluable for debugging.
- Consistent Naming Conventions: Adhering to consistent naming conventions for variables, paragraphs, and sections aids readability and reduces ambiguity, making the first pass more robust.