Added alternate macro code in python version folder.
This commit is contained in:
parent
40d8160b5d
commit
d1dc6d1414
86
Codes/Python version/Assignment-A2 (Macro)/Code-A2.py
Normal file
86
Codes/Python version/Assignment-A2 (Macro)/Code-A2.py
Normal file
@ -0,0 +1,86 @@
|
||||
# Assignment-A2 (Pass 1 and pass 2 macro processor)
|
||||
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.\nOpen Macroprocessor Folder in VSC[not the main folder]\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 pass1():
|
||||
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)
|
||||
|
||||
pass1()
|
||||
#pass 2 starts here:
|
||||
def inserter(sline, name):
|
||||
global MDT, MNT
|
||||
sline = ''
|
||||
for a in MNT:
|
||||
if a[1] == name:
|
||||
add = a[2]
|
||||
break
|
||||
while True:
|
||||
if 'MEND' in MDT[add]:
|
||||
break
|
||||
sline += MDT[add] + '\n'
|
||||
add+=1
|
||||
return sline
|
||||
|
||||
def pass2():
|
||||
source.seek(0)
|
||||
output = open('output.txt', 'w')
|
||||
output.close()
|
||||
output = open('output.txt', 'a+')
|
||||
while True:
|
||||
sline= source.readline().upper()
|
||||
if not sline:break
|
||||
for a in MNT:
|
||||
if a[1] in sline and 'MACRO' not in sline:
|
||||
sline=inserter(sline, a[1])
|
||||
d = sline.strip()
|
||||
if d not in MDT:
|
||||
output.write(sline)
|
||||
print('done.')
|
||||
|
||||
|
||||
pass2()
|
21
Codes/Python version/Assignment-A2 (Macro)/source.txt
Normal file
21
Codes/Python version/Assignment-A2 (Macro)/source.txt
Normal file
@ -0,0 +1,21 @@
|
||||
macro add num1, num2
|
||||
a1
|
||||
maCro sub num1, num2
|
||||
s1
|
||||
s2
|
||||
s3
|
||||
mend
|
||||
a2
|
||||
mend
|
||||
The code above should not come in output coz it's just definitions.
|
||||
The actual code begins from here.
|
||||
sure, you can write any shit in the file.
|
||||
start 1000
|
||||
mover areg, 50
|
||||
movem breg, 100
|
||||
I am now calling first function. The following line should be replaced by the body:
|
||||
add areg, 30
|
||||
dbms_output.print_line('Present Ma'am!')
|
||||
equ areg, 40
|
||||
add 5,6
|
||||
sub 3,4
|
@ -9,7 +9,7 @@
|
||||
---
|
||||
|
||||
- [Assignment-A1 (Pass 1 and pass 2 assembler)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Python%20version/Assignment-A1%20%28Assembler%29)
|
||||
- [Assignment-A2 (Pass 1 and pass 2 macro)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Code-A2.py) - This code is from "Codes/Group A" folder
|
||||
- [Assignment-A2 (Pass 1 and pass 2 macro)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Python%20version/Assignment-A2%20%28Macro%29) // Alternate version available in [Codes/Group A](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Code-A2.py) folder.
|
||||
- [Assignment-A3 (DLL)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A3) - This code is from "Codes/Group A" folder
|
||||
- [Assignment-A4 (Mutex and Semaphore)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Code-B4.cpp) - This code is from "Codes/Group B" folder
|
||||
- [Assignment-A5 (CPU scheduling)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Python%20version/Assignment-A5%20%28CPU%20Scheduling%29)
|
||||
|
Loading…
Reference in New Issue
Block a user