Objectives of macro expansion:
- Definition
- macro assembler
- macro preprocessor
- key notions of macro expansion
- flow of control during expansion
- algorithm
- lexical substitution
- 1) positional parameter
- 2) keyword parameter
Definition: Macro Expansion can be performed by using two kinds of language processors and when we use of macro name with a set of actual parameters is replaced by same code generated from its body .This is called macro expansion.
macro expansion can be performed two ways:
- macro assembler
- macro pre-processor
- Macro Assembler : It performs expansion of each macro call in a program into a sequence of assembly language statements and also assembles the resultant assembly language program.
- Macro pre-processor: It only processes the macro call . Other statements are processes with the help of assembler a macro pre-processor merely performs expansion of macro in program. It produces an assembly program in which a macro call has been replaced by statements that resulted form its expansion but statements that were not macro calls have been retained in their original from . This program can be assembled by using assembler.
The macro preprocessor operates as follows: If the first statement in the program input to its is macro header statement , it knows that one or more macro definitions exist in the program. It processes and stores all macro definitions in its own data program as follow.
Key notations of Macro Expansion:
We discuss the two key notions used in implementing macro expansion before we present a scheme for it.
- flow of control during expansion:
- Lexical substitution
1) Flow of Control During Expansion :
- The default flow of control during macro expansion is sequential.
- Thus, unless the flow of control is altered by using a preprocessor statement , model statement in a macro definition are visited sequentially starting with the statement following the macro prototype statement and ending with statement preceding the MEND statement.
- It rules determines the order in which model statements are visited during macro expansion.
- Flow of control during macro expansion is implemented using a macro expansion counter.
Algorithm:
Step 1 : MEC : = statement number of the first model statement following the prototype statements in the definition of the called macro.
Step 2 : while : - The statements is pointed to by MEC is not a MEND statement
1) If a model statements then
- expand the statements through lexical substitution.
- MEC:= MEC+1;
2) else
MEC:= value specified in the preprocessor statement.
step 3: Exit from macro expansion.
Lexical Substitution :
Lexical substitution is used to generate an assemble statement from a model statement
and model statement 3 types:
- ordinary string - Which is any string other than a string type 2 or type 3 .
- The name of formal parameter: Which is preceded by the character '&'.
- The name of preprocessor variable , which is also preceded by the character '&'.
During lexical substitution , an ordinary string in a model statement is retained in original form. A name formal parameter or preprocessor variable appearing in model statement is replaced with its value.
The value of Formal parameter is the corresponding to the actual parameter string used in a macro call. Where the rules of correspondence depend on what kind of parameter is. We will discuss two kinds of
formal parameters. positional and keyword parameters.
The value of a preprocessor variable is readily known to the preprocessor from its own data structures.
1) positional parameters: For positional formal parameters , the specification <parameter kind> of syntax rule is simply omitted.
The positional formal parameters is written as follows: &<parameter name> and example &SAMPLE where is sample is name of parameter.
In a call on a macro using positional parameters , the <actual parameters specifications> is an ordinary string.
2) keyword parameter :
For keyword parameter , the specifications < parameter kind> is the string = in syntax rule .
<The actual parameters specification > is written as <formal parameter name > = < ordinary string> .
No comments:
Post a Comment