New instructions, updated examples

This commit is contained in:
Mattia Mascarello 2021-09-29 18:48:54 +02:00
parent 8f74c747cd
commit 8f6770013c
4 changed files with 54 additions and 32 deletions

View File

@ -3,9 +3,16 @@ INT n
INT j
INT te
IN INT tot numero massimo
SET n 0
SET n 1
:scn
SET j 1
OUT $n$\n
:sieve
MOD n j te
JE sieve tot
OUT $n$
OUT j: $j$ \n
OUT te: $te$ \n
INC j
JME scn j n
JM sieve te 0
INC n
JLE scn n tot

31
gg.py
View File

@ -2,6 +2,7 @@ import sys
import re
vars={}
lines=open(sys.argv[1],"r").read().split("\n")
lines=list(map(lambda el: el.lstrip(),lines))
i=0
jumps={}
def sostT(text,vars):
@ -11,7 +12,13 @@ def sostT(text,vars):
text=text.replace("$"+match+"$",str(vars[match]))
return text
try:
while lines[i].strip()!="END":
for i in range(len(lines)):
ag=lines[i].split(" ")
if len(ag[0]):
if ag[0][0]==":":
jumps[ag[0][1:]]=i
i=0
while lines[i].strip()!="END" or i > len(lines) :
#print(lines[i])
if lines[i][0]=="#":
i+=1
@ -23,7 +30,7 @@ try:
vars[ag[1]]=ag[2]
elif ag[0]=="DEC":
if len(ag)==3:
if(ag[2].isnumeric());
if ag[2].isnumeric():
n=int(ag[2])
else:
n=int(vars[ag[2]])
@ -32,7 +39,7 @@ try:
vars[ag[1]]=int(vars[ag[1]])-n
elif ag[0]=="INC":
if len(ag)==3:
if(ag[2].isnumeric());
if ag[2].isnumeric():
n=int(ag[2])
else:
n=int(vars[ag[2]])
@ -41,25 +48,35 @@ try:
vars[ag[1]]=int(vars[ag[1]])+n
elif ag[0]=="CP":
vars[ag[1]]=vars[ag[2]]
elif ag[0]=="MOD":
if str(ag[1]).isnumeric():
m=float(ag[1])
else:
m=float(vars[ag[1]])
if str(ag[2]).isnumeric():
modTerm=float(ag[2])
else:
modTerm=float(vars[ag[2]])
vars[ag[3]]=m%modTerm
elif ag[0]=="JLE":
if str(ag[3]).isnumeric():
athr=float(ag[3])
else:
athr=vars[ag[3]]
athr=float(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]]
athr=float(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]]
athr=float(vars[ag[3]])
if vars[ag[2]]<athr:
i = jumps[ag[1]]
elif ag[0]=="JM":
@ -69,8 +86,6 @@ try:
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":