Code4z VS Code PL/I Language Extension Preprocessor Support

5 min read Original article ↗

Azat Satklyčov

In my previous blog “Code4z’s Newest Mainframe Language Extension”, I’ve written about a new VS Code extension for PL/I Programming Language [1]. Now the extension supports PL/I preprocessor statements.

Let’s expand on what is and how are PL/I preprocessor statements and usage of these preprocessors in VS Code extension for PL/I Language.

What is a PL/I Preprocessor?

Before answering that question, let’s understand what a preprocessor in computer science is. A preprocessor is a program (automated editor or text manipulator tool) that processes (precomputes or modifies) source code (its input data) before the actual program compilation begins. In other words, its processed output data will be used as an input data to another program [2].

The PL/I preprocessor is the preprocessor for PL/I programming language, that prepares the PL/I source code for the compiler.

The Role and Challenges of PL/I Preprocessors

The PL/I preprocessor is known as a powerful PL/I compile-time facility tool that operates as a “compiler before the compiler.” It works by scanning source code before the main compilation stage and identifies special commands prefixed with a percentage sign (%), such as %INCLUDE, %DCL, and etc. PL/I preprocessor supports complex logic, variable manipulation, and string processing to generate optimized or customized code (favor of custom syntax instead of the ones written on the stone).

But PL/I preprocessors bring key challenges in legacy environments like: Invisible syntax errors (standard editors fail to recognize macro syntax), no code completion support, code obscurity (e.g. without modern tools you have to expand macro), and monolithic complexity.

How VS Code Makes Developer Work Easier

Modern extensions such as code4z — PL/I Language extension can help to solve these challenges by integrating preprocessor logic inside the IDE and offers several technical advantages that bridge the gap between legacy mainframe development and modern software engineering.

Here are the key benefits of PL/I Preprocessors support in VS Code: Real time syntax accuracy, persistent language intelligence (code completion, go-to definition, hover-over etc.), integrated error handling (e.g. can highlight the skipped code with low opacity) and semantic awareness (e.g. some variables and procedures that are only available after the preprocessor has run)

Key Preprocessor Facilities

PL/I processors provide a wide range of preprocessor facilities for developing, optimizing, and maintaining mission-critical applications. These processors are designed for versatile, high-performance computing, supporting scientific, engineering, and commercial data processing [3].

Press enter or click to view image in full size

Figure-1: PL/I programming language preprocessor key facilities

Preprocessor Statements

The PL/I preprocessor uses a set of specific preprocessor statements to manipulate source text, manage conditional compilation, flow control, and automate code generation. Preprocessor statements are executed when encountered for:

Declarations and activation: %DECLARE (or %DCL), %ACTIVATE, etc.

Control flow and conditional logic: %IF…%THEN…%ELSE, %DO, %END, %SELECT etc.

Code generation and Inclusion: %ANSWER, %INCLUDE, %INSCAN, %XINCLUDE, %XINSCAN etc.

Utilities: %NOTE, %NULL

Integrated Include Preprocessor: Allows you to incorporate external source files into your programs by using ‘via ++INCLUDE or -INC’ directives beyond the standard include directive.

Preprocessor procedures (also called as Macros)

You can use preprocessor statements and groups inside preprocessor procedures to perform many kinds of different operations, like below:

Validation: Use %IF inside the procedure to check if arguments are valid and provide a diagnostic message using a %NOTE if they aren’t.

Complex Formatting: Use built-in functions like INDEX, SUBSTR, and TRANSLATE to play with input data before it becomes coded.

State Management: Procedures can update global %DCL variables to keep track of how many times a particular code block has been generated.

Providing results: To pass results pack to preprocessor scan use either ANSWER or RETURN statements.

Macro preprocessor options

To enable macro preprocessors, you can either use PP(MACRO) compile-time option in the program after %PROCESS directive or define it in the configuration file for global usage.

You can use macro preprocessors for below use-cases:

Data and Syntax control: using NAMEPREFIX (character) and FIXED(option) to determine default base for preprocessor variables and use

Source code handling and transformation: Use CASE(UPPER|ASIS) option whether the preprocessor converts your input source text to uppercase before processing it. The RESCAN (UPPER | ASIS) option controls how the preprocessor behaves after it has already performed a text replacement.

Use DEPRECATE (ERROR | WARN) to flag macro procedures that are intended to be phased out, issuing either a warning or an error.

Use INCONLY option to only handle %INCLUDE and %XINCLUDE and ignore other macro logic.

See below code animation for some preprocessor examples or just try it on your own PL/I code:

Press enter or click to view image in full size

In case you have not installed or used the extension, please try the guidance here.

Summary

PL/I preprocessors provide significant advantages in mainframe development by enabling code automation, enhancing maintainability, and improving the efficiency of the compilation process. They allow developers to manipulate source code before it is passed to the compiler using specialized preprocessors which we mentioned above in detail.

In coming releases extension will extend its support to PL/I specialized integrated preprocessors like CICS and DB2, they will be processed inside a block EXEC CICS and EXEC SQL respectively and translates (CICS and SQL) statements into PL/I calls.

For further information, you may contact us on Slack: che4z.slack.com

References

[1] https://azat-satklichov.medium.com/pl-i-the-newest-mainframe-language-code4z-extension-68e27a7ab420

[2] https://en.wikipedia.org/wiki/PL/I_preprocessor

[3] https://www.ibm.com/docs/en/epfz/5.3.0?topic=reference-preprocessor-facilities

[4] https://www.ibm.com/docs/en/epfz/5.3.0?topic=guide-pdf-version