0% found this document useful (0 votes)
103 views

Synopsis Macro

The document describes a one-pass macro processor that can handle recursive macro definitions. It involves three main data structures: a definition table (DEFTAB) to store macro definitions, a name table (NAMTAB) to index DEFTAB, and an argument table (ARGTAB) to store arguments during macro expansion. The macro processor functions DEFINE, EXPAND, GETLINE, and PROCESSLINE work together to first define macros, then expand macro invocations by substituting arguments from ARGTAB into the macro body from DEFTAB.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Synopsis Macro

The document describes a one-pass macro processor that can handle recursive macro definitions. It involves three main data structures: a definition table (DEFTAB) to store macro definitions, a name table (NAMTAB) to index DEFTAB, and an argument table (ARGTAB) to store arguments during macro expansion. The macro processor functions DEFINE, EXPAND, GETLINE, and PROCESSLINE work together to first define macros, then expand macro invocations by substituting arguments from ARGTAB into the macro body from DEFTAB.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SYNOPSIS

Title of the Project

MACROPROCESSOR

Developed by

DEEPAK. R (09GAEC3016) HRISHIKESH. R (09GAEC3022)

INTRODUCTION
Brief Description of Macros: A macro is an abbreviation for sequence of operations. Macros are used to replace text and help solve problems such as readability and simplicity. In primitive assembly code, macros are defined by two instructions the MACRO and MEND instruction. A macro operation permits writing a sequence of assembly instructions and to using its name in to replace it. A macro processor is by itself a language processor with its own syntax and rules. The general form of writing a macro in assembly language is MACRO <macro-name> //Body of the macro MEND Therefore, the keyword MACRO is an indication of a start of a macro and the following text is the name of the macro. This is required for storage and retrieval of macros. The MEND is an indication of end of the macro. In more sophisticated languages such as C/C++, the MACRO keyword may be replaced by the # symbol and the <macro-name> with the text that follows. The body of the macro is the text that follows the name and the MEND is indicated by a newline character \n.

IMPLEMENTATION
A one-pass macro processor that alternate between macro definition and macro expansion in a recursive way is able to handle recursive macro definition. Because of the one-pass structure, the definition of a macro must appear in the source program before any statements that invoke that macro. Three main data structures: The implementation of One Pass Macro processor involves several different data structures. 1. DEFTAB: The macro definitions are stored in a definition table (DEFTAB), which contains the macro type and the statements that make up the macro body. 2. NAMTAB: The macro names are entering into NAMTAB, which serves as an index to DEFTAB. For each macro instruction defined NAMTAB contains pointers to the beginning and end of the definition in DEFTAB. 3. ARGTAB: An argument table(ARGTAB) is used during the expansion of macro invocations .When a macro invocation statement is recognized, the arguments are stored in ARGTAB according to their position in the argument list. As the macro is expanded, arguments from ARGTAB are substituted for the corresponding parameters in the macro body.

Functions which implements macro processor: 1. DEFINE: The procedure DEFINE, which is called when the beginning of a macro definition is recognized, makes the appropriate entries in DEFTAB and NAMTAB. DEFINE ( )

Enter Macro name into NAMTAB. Enter macro prototype into DEFTAB. Set LEVEL=1. Substitute parameters with positional notations and enter to DEFTAB. If OPCODE=MACRO, LEVEL++; If OPCODE=MEND, LEVEL--; Continue this until LEVEL=0 Store beginning and end of definition as pointers within NAMTAB

2. EXPAND: EXPAND is called to set up the argument values in ARGTAB and expand a macro invocation statement. EXPAND ( ) EXPANDING = TRUE Set up arguments from macro invocation in ARGTAB. Write macro invocation statement to expanded file as a comment line. Call GETLINE() and PROCESSLINE() till macro definition ends. Set EXPANDING=FALSE.

3. GETLINE: The procedure GETLINE, which is called at several points in the algorithm, gets next line to be processed. This line may come from DEFTAB. GETLINE ( ) If EXPANDING is TRUE, read from DEFTAB (data structure where macro body is stored) and substitute arguments for positional notations. If EXPANDING is FALSE, read next line from input file. 4. PROCESSLINE: PROCESSLINE ( ) If OPCODE is a macro name then EXPAND ( ). Else if OPCODE is MACRO, then DEFINE ( ). Else write line to expanded file as such.

Block representation of macro expansion

Scan files for macros Input file

Macro names Macro definition

Extract macros with name and definition

Scan for macro names

Replace macro name with corresponding definition

Processed File

You might also like