Simple macro definition

A simple macro is identified by its name and body.

Syntax

&define identifier body
  1. identifier is the name of the macro. Any valid identifier can be used.
  2. body is any sequence of tokens until the end of the line.

After substitution, the macro definition is replaced with blank lines.

Usage

As the preprocessor scans the text, it substitutes the macro body for the name identifier.

The following example show macro substitution with 2 simple macros:

Source: File A
&define MAX_TEST 12
&define HW "Hello world"

MAIN
  DEFINE i INTEGER
  FOR i=1 TO MAX_TEST 
    DISPLAY HW
  END FOR
END MAIN
Result:
& 1 "A"



MAIN
  DEFINE i INTEGER
  FOR i=1 TO 12
    DISPLAY "Hello world"
  END FOR
END MAIN

The macro definition can be continued on multiple lines, but when the macro is expanded, it is joined to a single line as follows:

Source: File A
&define TABLE_VALUES 1, \
                     2, \
                     3
DISPLAY TABLE_VALUES      
Result:
& 1 "A"
 
 
 
DISPLAY 1, 2, 3

The source file is processed sequentially, so a macro takes effect at the place it has been written:

Source: File A
DISPLAY X
&define X "Hello"
DISPLAY X      
Result:
& 1 "A"
DISPLAY X

DISPLAY "Hello"

The macro body is expanded only when the macro is applied:

Source: File A
&define AA BB
&define BB 12
DISPLAY AA     
Result:
& 1 "A"
 
 
DISPLAY 12

In order to prevent infinite recursion, a macro cannot be expanded recursively.

Source: File A
&define A B
&define B A
&define C C
A C      
Result:
& 1 "A"



A C