d
This commit is contained in:
35
functions.py
Normal file
35
functions.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# L4: Function.
|
||||||
|
|
||||||
|
def memory_generateConstPlayfield(
|
||||||
|
n: int
|
||||||
|
) -> dict[int, int]:
|
||||||
|
idGroups: dict[int, int] = { }
|
||||||
|
id = 0
|
||||||
|
for gid in range(0, n):
|
||||||
|
idGroups[id] = gid
|
||||||
|
id += 1
|
||||||
|
idGroups[id] = gid
|
||||||
|
id += 1
|
||||||
|
#}
|
||||||
|
return idGroups
|
||||||
|
#}
|
||||||
|
|
||||||
|
# L20: Test.
|
||||||
|
|
||||||
|
def test_memory_generateConstPlayfield(
|
||||||
|
) -> str:
|
||||||
|
idGroups = memory_generateConstPlayfield(2)
|
||||||
|
if (
|
||||||
|
len(idGroups) == 4 and
|
||||||
|
idGroups[0] == 0 and
|
||||||
|
idGroups[1] == 0 and
|
||||||
|
idGroups[2] == 1 and
|
||||||
|
idGroups[3] == 1
|
||||||
|
):
|
||||||
|
return "OK: memory_generateConstPlayfield"
|
||||||
|
#}
|
||||||
|
return "ERR: memory_generateConstPlayfield"
|
||||||
|
#}
|
||||||
38
main.py
38
main.py
@@ -1,39 +1,3 @@
|
|||||||
|
from functions import *
|
||||||
|
|
||||||
|
|
||||||
# L4: Function.
|
|
||||||
|
|
||||||
def memory_generateConstPlayfield(
|
|
||||||
n: int
|
|
||||||
) -> dict[int, int]:
|
|
||||||
idGroups: dict[int, int] = { }
|
|
||||||
id = 0
|
|
||||||
for gid in range(0, n):
|
|
||||||
idGroups[id] = gid
|
|
||||||
id += 1
|
|
||||||
idGroups[id] = gid
|
|
||||||
id += 1
|
|
||||||
#}
|
|
||||||
return idGroups
|
|
||||||
#}
|
|
||||||
|
|
||||||
# L20: Test.
|
|
||||||
|
|
||||||
def test_memory_generateConstPlayfield(
|
|
||||||
) -> str:
|
|
||||||
idGroups = memory_generateConstPlayfield(2)
|
|
||||||
if (
|
|
||||||
len(idGroups) == 4 and
|
|
||||||
idGroups[0] == 0 and
|
|
||||||
idGroups[1] == 0 and
|
|
||||||
idGroups[2] == 1 and
|
|
||||||
idGroups[3] == 1
|
|
||||||
):
|
|
||||||
return "OK: memory_generateConstPlayfield"
|
|
||||||
#}
|
|
||||||
return "ERR: memory_generateConstPlayfield"
|
|
||||||
#}
|
|
||||||
|
|
||||||
# L36: Run.
|
|
||||||
|
|
||||||
print(test_memory_generateConstPlayfield())
|
print(test_memory_generateConstPlayfield())
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ from Function import *
|
|||||||
def replaceAnd(s):
|
def replaceAnd(s):
|
||||||
return s.replace("and", "&&")
|
return s.replace("and", "&&")
|
||||||
|
|
||||||
|
def replaceComment(s):
|
||||||
|
return s.replace("#", "//")
|
||||||
|
|
||||||
def replaceLen(s):
|
def replaceLen(s):
|
||||||
posLen = s.find("len(")
|
posLen = s.find("len(")
|
||||||
posEnd = s.find(")")
|
posEnd = s.find(")")
|
||||||
|
|||||||
@@ -9,16 +9,29 @@ def process(FILE_IN):
|
|||||||
lines_in.append(line.rstrip())
|
lines_in.append(line.rstrip())
|
||||||
|
|
||||||
f = Function()
|
f = Function()
|
||||||
|
out = ""
|
||||||
|
|
||||||
# Parse.
|
# Parse.
|
||||||
for ln in lines_in:
|
for ln in lines_in:
|
||||||
ln = ln.rstrip()
|
ln = ln.rstrip()
|
||||||
f.parseLine(ln)
|
|
||||||
|
# Empty line.
|
||||||
|
if ln == "":
|
||||||
|
out += "\n"
|
||||||
|
# Comment.
|
||||||
|
elif (
|
||||||
|
ln.startswith("#") and
|
||||||
|
not f.isBody
|
||||||
|
):
|
||||||
|
out += replaceComment(ln) + "\n"
|
||||||
|
# Function.
|
||||||
|
else:
|
||||||
|
f.parseLine(ln)
|
||||||
|
|
||||||
if f.isComplete:
|
if f.isComplete:
|
||||||
print("Function ready! Here it is in C++:")
|
|
||||||
cpp = CPP(f)
|
cpp = CPP(f)
|
||||||
print(cpp.translate())
|
out += cpp.translate()
|
||||||
# Create new function instance.
|
# Create new function instance.
|
||||||
f = Function()
|
f = Function()
|
||||||
|
|
||||||
|
return out
|
||||||
|
|||||||
Reference in New Issue
Block a user