From 4122ffd816e27d9fa6e21c6fafb1483ca658cc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 1 Apr 2024 22:59:43 +0300 Subject: [PATCH] d --- main-2.cpp | 36 ++++++++++++++++++++++++++++++++++++ main.cpp | 4 +--- pythonToC++ | 8 +------- sed.pythonToC++ | 12 ++++++++++++ 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 sed.pythonToC++ diff --git a/main-2.cpp b/main-2.cpp index e69de29..409aa15 100644 --- a/main-2.cpp +++ b/main-2.cpp @@ -0,0 +1,36 @@ + + + +// L4: Function. + +std::map memory_generateConstPlayfield(n: int) { + idGroups: std::map = { } + 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()) diff --git a/main.cpp b/main.cpp index 52ecdef..1c5430c 100644 --- a/main.cpp +++ b/main.cpp @@ -3,9 +3,7 @@ // L4: Function. -std::map memory_generateConstPlayfield( - int n -) { +std::map memory_generateConstPlayfield(int n) { std::map idGroups; auto id = 0; for (auto gid = 0; gid < n; ++gid) { diff --git a/pythonToC++ b/pythonToC++ index 3ad1814..c3aafdd 100755 --- a/pythonToC++ +++ b/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 -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 diff --git a/sed.pythonToC++ b/sed.pythonToC++ new file mode 100644 index 0000000..bbe1cc2 --- /dev/null +++ b/sed.pythonToC++ @@ -0,0 +1,12 @@ +# #} -> } +s|#}|}| + +# # -> // +s|#|//| + +# dict[X, Y] -> std::map +s_dict\[(.*), (.*)\]_std::map<\1, \2>_ + +# def functionName(X) -> Y -> Y functionName(X) { +s|def (.*) -> (.*):|\2 \1 {| +