3
1
SystemsProgrammingAndOperat.../Codes/macro 1.py

55 lines
1.4 KiB
Python
Raw Permalink Normal View History

#Original Code, Engineered by Afan Shaikh.
try:
source= open('source.txt', 'r')
dum = source.readline()
print("File is read successfully.")
source.seek(0)
except FileNotFoundError:
print('\n\n\nsource.txt file not found. Create it first!\n\n\n')
except IOError:
print('The source file has an IO error')
MDT =[]
MNT =[]
def macroman(line):
name = line.split()[1] #A concise way to get the 2nd word-> name of macro. index =1. first split and then get 2nd word
entry = []
entry.append(line.strip()) #append the macro definition line
while True:
line=source.readline().upper()
if not line:
print('No MEND found for: ', name)
return
if 'MACRO' in line:
macroman(line)
elif 'MEND' in line:
global MDT, MNT
entry.append(line.strip()) #MEND line appended too
MNT.append([len(MNT)+1, name, len(MDT)+1]) # Eg. 1 Fibo 50
MDT = MDT + entry
return
else:
entry.append(line.strip())
def driver():
global MDT, MNT
while True:
line = source.readline().upper()
if not line:break
if 'MACRO' in line:
macroman(line)
print('\nMNT:')
for a in MNT:
print(a)
print('\n\nMDT:')
i=0
for a in MDT:
i=i+1
print (i, ' ',a)
driver()