![]() |
![]() |
![]() |
![]() |
![]() |
The Macro Expander
A macro is a form of text substitution used in the SDL system definitions. In a macro definition, a collection of lexical units is defined. A macro call indicates where the text from the macro definition body is to be included. All macro calls must be expanded before further analysis of the system definition can be done.
The name of the macro definition is visible in the whole system definition. A macro call may appear before its corresponding macro definition. A macro definition may contain macro calls, but not calls to itself, directly or indirectly.
A macro may use parameters, called formal parameters, in macro definitions and actual parameters in macro calls. There must be an equal number of formal parameters and actual parameters in corresponding macro definitions and macro calls. Using multiple formal parameters with the same name is not allowed.
When a character string is used as an actual parameter, the value of the character string will be used to replace the formal parameter in the macro body and not the character string itself.
The keyword MACROID may be used in a macro definition body only. The MACROID keyword will be replaced by a unique name at each expansion of the macro (that is, only one unique name is available at each expansion of a macro definition). New names can be constructed by concatenating names, parameters and MACROID using a percent sign (%) as a separator.
The reserved word MACRODEFINITION is not allowed inside a macro definition. The reserved words MACROID and ENDMACRO are only allowed inside a macro definition.
Macro expansion follows this order:
- The name in the macro call is used to find the corresponding macro definition, and a copy of that macro definition is made.
- In this copy, all occurrences of formal parameters are replaced by actual parameters. All occurrences of
MACROID are replaced by a unique name. Also, all percent signs (%) separating names are removed.- Macro calls in the modified macro definition body are expanded.
- The modified and expanded text is substituted for the macro call text in the system definition.
Implementation Details
The syntax checks made in the macro parser are entirely specific to macros since no other checks are possible until all macro calls are expanded. Some semantic checks are made during the expansion. These may produce error messages; see Error and Warning Messages.
Example 346 : Macro in SDL that Will Not Work
macro test('if par3 then','if not par3 then','k<0') ;where the text par3 in the first and second parameter strings is intended to be replaced by the third formal parameter in the macro definition will not work. This is because all formal parameters are replaced with actual parameters in a single step.
The reserved word MACROID is replaced by a unique name consisting of the string "XMID" and an integer. To assure system wide uniqueness the name is tested against all existing names in the system and the integer will be increased until the name is unique.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |