A macro processor is a program that copies text, making replacements according to macro definitions. Macro processors are embedded in other programs like assemblers and compilers, or exist as standalone programs. ELENA is a researched macro processor that defines macros with headers and parameters identified by %. It provides macro variables and instructions to control expansion. Macros are expanded by matching keywords in headers to invocations. ELENA handles ambiguities by selecting the macro header with the fewest parameters.
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
What is a macro processor
1.
2. A macro processor is a general-purpose macro processor that is
not tied to or integrated with a particular language or piece of
software.
A macro processor is a program that copies a stream of text from
one place to another, making a systematic set of replacements as it
does so.
Macro processors are often embedded in other programs, such as
assemblers and compilers. Sometimes they are standalone
programs that can be used to process any kind of text.
Example is the C language pre-processor .
What is a macro processor?
3. ELENA MACRO PROCESSOR
ELENA was developed as a researched tool, not as a
commercial software product.
However the same design and implementation techniques
could be used in developing other general-purpose macro
processors.
Further information about ELENA can be found in
Barcucci and Pelacani(1984).
4. CONT….
Macro definitions in ELENA are composed of a
header and a body
The header consists of keywords and parameter
markers, which are identified by the character %
At least one of the first two tokens in a macro
header must be a keyword, not a parameter
marker
5. The macro processor appends a numeric value to
create unique labels.
ELENA provides macro-time variables and macro-
time instructions that can be used to control the
macro expansion.
The IF statement is a macro-time conditional “go to”
statement.
The macro is identified by the sequence of
keywords that appear in its header.
CONT….
6. For ex: a macro with header.
ALPHA = %1 + %2
ALPHA = BETA + GAMMA
ADD %1 TO THE VALUE OF
%2
ADD 10 TO THE VALUE OF
INDEX
7. ELENA use with different lang.
In c language,
%1 := ABSDIFF(%2,%3)
%1=(%2) >(%3) ? (%2 - %3) : (%3 - %2)
Z := ABSDIFF(X,Y)
Z=(X) >(Y) ? (X - Y) : (Y - X)
8. In x86 assembly language program
%1 := ABSDIFF(%2,%3)
MOV EAZ,%2
SUB EAX,%3
JNS &STORE
NEG EAX
&STORE MOV EAX,%1
Z := ABSDIFF(X,Y)
MOV EAZ,X
SUB EAX,Y
JNS STORE0001
NEG EAX
STORE001 MOV EAX,Z
9. ADD %1 TO THE FIRST %2 ELEMENTS OF
V
.SET .LAA = 1
.E V(.LAA) = V(.LAA) + %1
.SET .LAA = .LAA +1
IF .LAA LE %2 .JUMP .E
We can use macro time variables and macro time instruction
ADD 5 TO THE FIRST 3 ELEMENTS OF V
V(1) = V(1) + 5
V(2) = V(2) + 5
V(3) = V(3) + 5
10. DISPLAY TABLE
DISPLAY %1
%1 TABLE
At least one of the first two tokens in a macro header must be a keyword,
not a parameter marker
11. ELENA consist of a data structure index with macro
headers according to the keywords in the first 2 tokens.
Macro invocation are compared against all headers with
keywords
Eg: A SUM B,C
During this process, it's possible that sequence of token
match with more than one macro header.
12. For EX:
SUM A=B+1
SUM %1 = %2 + %3
SUM %1 = %2 + 1
In this situation, ELENA select the header with fewest parameter.