diff --git a/examples/99.mga b/examples/99.mga index e2f2135..53cecf9 100644 --- a/examples/99.mga +++ b/examples/99.mga @@ -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 diff --git a/examples/primes.mga b/examples/primes.mga index 3966cae..422aa79 100644 --- a/examples/primes.mga +++ b/examples/primes.mga @@ -2,10 +2,17 @@ INT tot INT n INT j INT te -IN INT tot numero massimo -SET n 0 +IN INT tot numero massimo +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 diff --git a/examples/rect.mga b/examples/rect.mga index 2e20a3f..aa7e96c 100644 --- a/examples/rect.mga +++ b/examples/rect.mga @@ -4,7 +4,7 @@ INT w #initialize width INT h #initialize height -IN INT w l +IN INT w l #input height as an int IN INT h h #input width as an int @@ -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 diff --git a/gg.py b/gg.py index b2ce89c..0cb6e1c 100644 --- a/gg.py +++ b/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][0]==":": - jumps[ag[0][1:]]=i elif ag[0]=="OUT": print(sostT(" ".join(ag[1:]),vars).replace("\\n","\n"),end='') elif ag[0]=="IN":