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 j
INT te INT te
IN INT tot numero massimo IN INT tot numero massimo
SET n 0 SET n 1
:scn :scn
SET j 1
OUT $n$\n
:sieve :sieve
MOD n j te MOD n j te
JE sieve tot OUT j: $j$ \n
OUT $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 import re
vars={} vars={}
lines=open(sys.argv[1],"r").read().split("\n") lines=open(sys.argv[1],"r").read().split("\n")
lines=list(map(lambda el: el.lstrip(),lines))
i=0 i=0
jumps={} jumps={}
def sostT(text,vars): def sostT(text,vars):
@ -11,7 +12,13 @@ def sostT(text,vars):
text=text.replace("$"+match+"$",str(vars[match])) text=text.replace("$"+match+"$",str(vars[match]))
return text return text
try: 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]) #print(lines[i])
if lines[i][0]=="#": if lines[i][0]=="#":
i+=1 i+=1
@ -23,7 +30,7 @@ try:
vars[ag[1]]=ag[2] vars[ag[1]]=ag[2]
elif ag[0]=="DEC": elif ag[0]=="DEC":
if len(ag)==3: if len(ag)==3:
if(ag[2].isnumeric()); if ag[2].isnumeric():
n=int(ag[2]) n=int(ag[2])
else: else:
n=int(vars[ag[2]]) n=int(vars[ag[2]])
@ -32,7 +39,7 @@ try:
vars[ag[1]]=int(vars[ag[1]])-n vars[ag[1]]=int(vars[ag[1]])-n
elif ag[0]=="INC": elif ag[0]=="INC":
if len(ag)==3: if len(ag)==3:
if(ag[2].isnumeric()); if ag[2].isnumeric():
n=int(ag[2]) n=int(ag[2])
else: else:
n=int(vars[ag[2]]) n=int(vars[ag[2]])
@ -41,25 +48,35 @@ try:
vars[ag[1]]=int(vars[ag[1]])+n vars[ag[1]]=int(vars[ag[1]])+n
elif ag[0]=="CP": elif ag[0]=="CP":
vars[ag[1]]=vars[ag[2]] 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": elif ag[0]=="JLE":
if str(ag[3]).isnumeric(): if str(ag[3]).isnumeric():
athr=float(ag[3]) athr=float(ag[3])
else: else:
athr=vars[ag[3]] athr=float(vars[ag[3]])
if vars[ag[2]]<=athr: if vars[ag[2]]<=athr:
i = jumps[ag[1]] i = jumps[ag[1]]
elif ag[0]=="JME": elif ag[0]=="JME":
if str(ag[3]).isnumeric(): if str(ag[3]).isnumeric():
athr=float(ag[3]) athr=float(ag[3])
else: else:
athr=vars[ag[3]] athr=float(vars[ag[3]])
if vars[ag[2]]>=athr: if vars[ag[2]]>=athr:
i = jumps[ag[1]] i = jumps[ag[1]]
elif ag[0]=="JL": elif ag[0]=="JL":
if str(ag[3]).isnumeric(): if str(ag[3]).isnumeric():
athr=float(ag[3]) athr=float(ag[3])
else: else:
athr=vars[ag[3]] athr=float(vars[ag[3]])
if vars[ag[2]]<athr: if vars[ag[2]]<athr:
i = jumps[ag[1]] i = jumps[ag[1]]
elif ag[0]=="JM": elif ag[0]=="JM":
@ -69,8 +86,6 @@ try:
athr=vars[ag[3]] athr=vars[ag[3]]
if vars[ag[2]]>athr: if vars[ag[2]]>athr:
i = jumps[ag[1]] i = jumps[ag[1]]
elif ag[0][0]==":":
jumps[ag[0][1:]]=i
elif ag[0]=="OUT": elif ag[0]=="OUT":
print(sostT(" ".join(ag[1:]),vars).replace("\\n","\n"),end='') print(sostT(" ".join(ag[1:]),vars).replace("\\n","\n"),end='')
elif ag[0]=="IN": elif ag[0]=="IN":