First commit
This commit is contained in:
parent
0aaa575eb0
commit
d472caa320
11
examples/99.mga
Normal file
11
examples/99.mga
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
INT i
|
||||||
|
INT im
|
||||||
|
SET i 99
|
||||||
|
:beg
|
||||||
|
OUT bottles of beer on the wall,$i$ bottles of beer\n
|
||||||
|
CP im i
|
||||||
|
DEC im 1
|
||||||
|
OUT Take one down and pass it around, $im$ bottles of beer on the wall\n
|
||||||
|
DEC i 1
|
||||||
|
JME beg i 1
|
||||||
|
END
|
19
examples/rect.mga
Normal file
19
examples/rect.mga
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
OUT I will draw a rectangle\n
|
||||||
|
INT w
|
||||||
|
INT h
|
||||||
|
IN INT w l
|
||||||
|
IN INT h h
|
||||||
|
INT wr
|
||||||
|
INT hr
|
||||||
|
SET wr 0
|
||||||
|
SET hr 0
|
||||||
|
:wrc
|
||||||
|
:wf
|
||||||
|
OUT *
|
||||||
|
INC wr
|
||||||
|
JL wf wr w
|
||||||
|
OUT \n
|
||||||
|
SET wr 0
|
||||||
|
INC hr
|
||||||
|
JL wrc hr h
|
||||||
|
END
|
70
gg.py
Normal file
70
gg.py
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
vars={}
|
||||||
|
lines=open(sys.argv[1],"r").read().split("\n")
|
||||||
|
i=0
|
||||||
|
jumps={}
|
||||||
|
def sostT(text,vars):
|
||||||
|
matches=re.findall(r"(?<=\$)(.*)(?=\$)",text)
|
||||||
|
for match in matches:
|
||||||
|
if match in vars.keys():
|
||||||
|
text=text.replace("$"+match+"$",str(vars[match]))
|
||||||
|
return text
|
||||||
|
try:
|
||||||
|
while lines[i].strip()!="END":
|
||||||
|
#print(lines[i])
|
||||||
|
if lines[i][0]=="#":
|
||||||
|
i+=1
|
||||||
|
continue
|
||||||
|
ag=lines[i].split(" ")
|
||||||
|
if ag[0] == "INT":
|
||||||
|
vars[ag[1]]=0
|
||||||
|
elif ag[0]=="SET":
|
||||||
|
vars[ag[1]]=ag[2]
|
||||||
|
elif ag[0]=="DEC":
|
||||||
|
vars[ag[1]]=int(vars[ag[1]])-1
|
||||||
|
elif ag[0]=="INC":
|
||||||
|
vars[ag[1]]=int(vars[ag[1]])+1
|
||||||
|
elif ag[0]=="CP":
|
||||||
|
vars[ag[1]]=vars[ag[2]]
|
||||||
|
elif ag[0]=="JLE":
|
||||||
|
if str(ag[3]).isnumeric():
|
||||||
|
athr=float(ag[3])
|
||||||
|
else:
|
||||||
|
athr=vars[ag[3]]
|
||||||
|
if vars[ag[2]]<=athr:
|
||||||
|
i = jumps[ag[1]]
|
||||||
|
elif ag[0]=="JME":
|
||||||
|
if str(ag[3]).isnumeric():
|
||||||
|
athr=float(ag[3])
|
||||||
|
else:
|
||||||
|
athr=vars[ag[3]]
|
||||||
|
if vars[ag[2]]>=athr:
|
||||||
|
i = jumps[ag[1]]
|
||||||
|
elif ag[0]=="JL":
|
||||||
|
if str(ag[3]).isnumeric():
|
||||||
|
athr=float(ag[3])
|
||||||
|
else:
|
||||||
|
athr=vars[ag[3]]
|
||||||
|
if vars[ag[2]]<athr:
|
||||||
|
i = jumps[ag[1]]
|
||||||
|
elif ag[0]=="JM":
|
||||||
|
if str(ag[3]).isnumeric():
|
||||||
|
athr=float(ag[3])
|
||||||
|
else:
|
||||||
|
athr=vars[ag[3]]
|
||||||
|
if vars[ag[2]]>athr:
|
||||||
|
i = jumps[ag[1]]
|
||||||
|
elif ag[0][0]==":":
|
||||||
|
jumps[ag[0][1:]]=i
|
||||||
|
elif ag[0]=="OUT":
|
||||||
|
print(sostT(" ".join(ag[1:]),vars).replace("\\n","\n"),end='')
|
||||||
|
elif ag[0]=="IN":
|
||||||
|
print(sostT(" ".join(ag[3:]),vars).replace("\\n","\n"),end='')
|
||||||
|
vars[ag[2]]=int(input(""))
|
||||||
|
i+=1
|
||||||
|
except Exception as e:
|
||||||
|
print(vars)
|
||||||
|
print(jumps)
|
||||||
|
raise e
|
||||||
|
#print(lines)
|
Reference in New Issue
Block a user