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

Experiment No. Experiment Name

This document outlines an experiment to implement Pass 1 of a macro processor. The objectives are to learn macro definition/name identification and macro usage. The task is to write a program to identify macros in a file and display relevant tables. The theory discusses macro processing in two passes - Pass 1 recognizes and saves macro definitions while Pass 2 recognizes calls and performs expansion. The program code implements Pass 1 by reading the file, identifying the macro name and arguments, and displaying the Argument List, Macro Definition, and Macro Name tables. The outcome is a successful implementation of Pass 1 of the macro processor in Python.

Uploaded by

Reena Kale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Experiment No. Experiment Name

This document outlines an experiment to implement Pass 1 of a macro processor. The objectives are to learn macro definition/name identification and macro usage. The task is to write a program to identify macros in a file and display relevant tables. The theory discusses macro processing in two passes - Pass 1 recognizes and saves macro definitions while Pass 2 recognizes calls and performs expansion. The program code implements Pass 1 by reading the file, identifying the macro name and arguments, and displaying the Argument List, Macro Definition, and Macro Name tables. The outcome is a successful implementation of Pass 1 of the macro processor in Python.

Uploaded by

Reena Kale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Don Bosco Institute of Technology, Kurla(W)

Department of Computer Engineering


CSL602: System Software Lab
2020-21

Experiment Experiment Name


No.
4 Design and Implement Pass 1 of a Macro processor

Student Name: Reena Kale


Roll No : 23

Objective:
 Students will be able to learn and identify macro definition and macro name in
a given program.
 Students will be able to understand the use of Macros in a program

Task to be performed:
A. Write a program to read a given text file which can identify the macros in the
program and display MNT, MDT and Argument List Array.

Theory & Macro represents a group of commonly used statements in the source
Algorithm : programming language. It is used for identifying the macro name and
performing expansion.

Features of macro processor:


1. Recognize the macro definition
2. Save macro definition
3. Recognize the macro call
4. Perform macro expansion

The assembler specifies that the macro definition should occur


anywhere in the program . So there can be chances of macro call before
it’s definition witch gives rise to the forwards reference problem of macro
Due to which macro is divided into two passes PASS 1- Recognize
macro definition save macro definition PASS 2- Recognize macro call
perform macro expansion

Algorithm for Pass 1 Macro Processor:

•Pass1 of the macro processor makes a line-by- line scan over its input.
•Set MDTC = 1 as well as MNTC = 1.
•Read the next line from the input program.
•If it is a MACRO pseudo-op, the entire macro definition except this
(MACRO) line is stored in MDT.
•The name is entered into the Macro Name Table along with a pointer to
the first location of the MDT entry of the definition.
•When the END pseudo-op is encountered all the macro-definitions
have been processed, so control is transferred to pass2
FLOWCHART:

Program dicts={}
Code: argu1=[]
def arg(file):
with open(file,'r') as f:
argu=[]
argument=False
print('Argument List Table')
print('-------------------------')
print('Index '+'Argument')
flag=0
for line in f:
split_line=line.split()
for i in split_line:
if 'MACRO' in i:
flag=1
continue;
if flag==1:
macro_name=i
flag=0
for ch in i:
if '&' in ch:
argument=True
if argument==True:
argu.append(i)
argument=False
argu1=list(set(argu))
#print(argu1)
keys=range(1,4)
for i in keys:
dicts[i]=argu[i-1]
print(str(i)+' '+dicts[i])
return macro_name
def mdt(file,macro_name):
with open(file,'r') as f:
keys=list(dicts.keys())
vals=list(dicts.values())
print('\n')
print('Macro Definition Table')
print('-------------------------')
print('Index'+' Macro Definition')
k=1
for line in f:
split_line=line.split()
if 'START' in split_line:
continue
if macro_name in split_line:
continue
for i in split_line:
if i=='MACRO':
continue
elif i=='MEND':
print(k,end=' ')
print(i)
return
elif i in vals:
key=vals.index(i)
print('#'+str(key+1),end=' ')
elif i==',':
print(i,end=' ')
else:
print(k,end=' ')
print(i,end=' ')
k=k+1
print('\n')
def mnt(file,macro_name):
print('\n')
print('Macro Name Table')
print('-------------------------')
print('Index'+' Macro Name'+' MDT Index')
j=1
with open(file,'r') as f:
print(str(j)+' '+macro_name+' '+str(j))
if __name__ == '__main__':
file = 'input_macro4.txt'
macro_name=arg(file)
mdt(file,macro_name)
mnt(file,macro_name)
Input to the PG1 START
Program: MACRO
INCR &ARG1 , &ARG2 , &ARG3
MOVER &ARG1 , &ARG2
ADD &ARG1 , &ARG3
MOVEM &ARG1 , &ARG2
MEND
INCR REG1, A, B
END
Output
Screenshot:

Outcome of Thus, we have successfully implemented this experiment by


the understanding the use of macros in a program, and implementing the
Experiment: pass 1 of Macro Processor using python programming language.
References https://www.geeksforgeeks.org/macro-processor/
used:

Course In-charge: Ditty Varghese

You might also like