Thursday, 4 April 2013

What are macros and macro processors? Explain in brief.


Q.n.3 What are macros and macro processors? Explain in brief.


A macro is similar to a subroutine (or a procedure), but there are important Differences between them. A subroutine is a section of the program that is writtenOnce, and can be used many times by simply calling it from any point in the program. Similarly, a macro is a section of code that the programmer writes (defines) once, and then can use many times. The main difference between a subroutine and a Macro is that the former is stored in memory once (just one copy), whereas the Latter is duplicated as many times as necessary. Macros involve two separate phases. Handling the definition and Handling the expansions. A macro can only be defined once but it can be expanded many times. Handling the definition is a relatively simple process. The assembler reads the Definition from the source files and saves it in a special table, the Macro Definition Table (MDT).The assembler does not try to check the definition for errors, to assemble it, execute it, or do anything else with it.
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.
Macro processors have been used for language expansion (defining new language constructs that can be expressed in terms of existing language components), for systematic text replacements that require decision making, and for text reformatting (e.g. conditional extraction of material from an HTML file).

No comments:

Post a Comment