Михаил Капелько 8 月之前
父節點
當前提交
4122ffd816
共有 4 個文件被更改,包括 50 次插入10 次删除
  1. +36
    -0
      main-2.cpp
  2. +1
    -3
      main.cpp
  3. +1
    -7
      pythonToC++
  4. +12
    -0
      sed.pythonToC++

+ 36
- 0
main-2.cpp 查看文件

@@ -0,0 +1,36 @@



// L4: Function.

std::map<int, int> memory_generateConstPlayfield(n: int) {
idGroups: std::map<int, int> = { }
id = 0
for gid in range(0, n):
idGroups[id] = gid
id += 1
idGroups[id] = gid
id += 1
}
return idGroups
}

// L20: Test.

str test_memory_generateConstPlayfield() {
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())

+ 1
- 3
main.cpp 查看文件

@@ -3,9 +3,7 @@

// L4: Function.

std::map<int, int> memory_generateConstPlayfield(
int n
) {
std::map<int, int> memory_generateConstPlayfield(int n) {
std::map<int, int> idGroups;
auto id = 0;
for (auto gid = 0; gid < n; ++gid) {


+ 1
- 7
pythonToC++ 查看文件

@@ -1,10 +1,4 @@
IN=main.py
OUT=main-2.cpp

# Simple check. TODO REMOVE later
sed 's|# L4: Function.|// L4: Function.|' $IN > $OUT

# dict[X, Y] -> std::map<X, Y>
sed -E 's|dict\[(.*), (.*)\]|std::map<\1, \2>|' $IN > $OUT
# def functionName(X) -> Y -> Y functionName(X) {
sed -E 's|def (.*) -> (.*):|\2 \1 {|' $OUT > $OUT
sed -Ef sed.pythonToC++ <$IN >$OUT

+ 12
- 0
sed.pythonToC++ 查看文件

@@ -0,0 +1,12 @@
# #} -> }
s|#}|}|

# # -> //
s|#|//|

# dict[X, Y] -> std::map<X, Y>
s_dict\[(.*), (.*)\]_std::map<\1, \2>_

# def functionName(X) -> Y -> Y functionName(X) {
s|def (.*) -> (.*):|\2 \1 {|


Loading…
取消
儲存