New instructions, updated examples
This commit is contained in:
parent
8f74c747cd
commit
8f6770013c
|
@ -2,10 +2,10 @@ 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
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,20 +17,20 @@ SET wr 0
|
|||
SET hr 0
|
||||
# set height counter to 0
|
||||
:wrc
|
||||
#row label
|
||||
:wf
|
||||
#column label
|
||||
OUT *
|
||||
#put char
|
||||
INC wr
|
||||
#increment width counter
|
||||
JL wf wr w
|
||||
#loop until desired width
|
||||
OUT \n
|
||||
#put newline char
|
||||
SET wr 0
|
||||
# set width counter to 0
|
||||
INC hr
|
||||
#row label
|
||||
:wf
|
||||
#column label
|
||||
OUT *
|
||||
#put char
|
||||
INC wr
|
||||
#increment width counter
|
||||
JL wf wr w
|
||||
#loop until desired width
|
||||
OUT \n
|
||||
#put newline char
|
||||
SET wr 0
|
||||
# set width counter to 0
|
||||
INC hr
|
||||
#increment height counter
|
||||
JL wrc hr h
|
||||
#loop until desired height
|
||||
|
|
31
gg.py
31
gg.py
|
@ -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":
|
||||
|
|
Reference in New Issue
Block a user