{"id":17931773,"url":"https://github.com/noti0na1/codetranslator","last_synced_at":"2025-04-03T10:30:07.661Z","repository":{"id":213713815,"uuid":"84271697","full_name":"noti0na1/CodeTranslator","owner":"noti0na1","description":"A Code Translator for C8, CS146","archived":false,"fork":false,"pushed_at":"2017-04-22T13:52:13.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T23:47:38.037Z","etag":null,"topics":["c8","cs146","haskell","uwaterloo"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noti0na1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-08T02:59:15.000Z","updated_at":"2017-04-25T20:00:36.000Z","dependencies_parsed_at":"2023-12-22T16:10:35.062Z","dependency_job_id":null,"html_url":"https://github.com/noti0na1/CodeTranslator","commit_stats":null,"previous_names":["noti0na1/codetranslator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noti0na1%2FCodeTranslator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noti0na1%2FCodeTranslator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noti0na1%2FCodeTranslator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noti0na1%2FCodeTranslator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noti0na1","download_url":"https://codeload.github.com/noti0na1/CodeTranslator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246984316,"owners_count":20864417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c8","cs146","haskell","uwaterloo"],"created_at":"2024-10-28T21:23:51.429Z","updated_at":"2025-04-03T10:30:07.582Z","avatar_url":"https://github.com/noti0na1.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Code Translator\nA Code Translator for C8, CS146.\n\nThis translate converts loops or ifs into labels, goto and simple ifs. All code and examples are in `translate.hs`.\n\n`ghci translate.hs` to run it.\n\n## Updated\n\nRewritten using Monad, the old version is `trans-old.hs`.\n\n## Examples:\n\n### Simple While Loop with Break\n\n```c\nint i = 0;\nwhile (i \u003c 100) {\n  printf(\"%d\\n\", i);\n  if (i == 66) break;\n  ++i;\n}\n```\n\nWrite the code above into Haskell:\n\n```haskell\ns2 = [Exp \"int i = 0\", \n    While \"i \u003c 100\" \n       [Exp \"printf(\\\"%d\\\\n\\\", i)\",\n        If \"i == 66\" [Break] [], \n        Exp \"++i\"]]\n```\n\nAfter translation:\n\n```c\n*Main\u003e ts s2\nint i = 0;\nL0:;\nif (!(i \u003c 100)) goto L2;\nprint i;\nif (i == 66) goto L1;\n++i;\ngoto L0;\nL2:;\nL1:;\n```\n\n### Perfect Numbers from 1 to 10000\n\n```c\nint i = 1;\nwhile (i \u003c= 10000) {\n  int acc = 0;\n  for (int j = 1; j \u003c i; ++j) {\n    if (i % j == 0) acc += j;\n  }\n  if (i == acc) printf(\"%d\\n\", i);\n  ++i;\n}\n```\n\n Write the code above into Haskell:\n\n```haskell\ns5 = [Exp \"int i = 1\", \n    While \"i \u003c= 10000\" \n       [Exp \"int acc = 0\", \n        (For \"int j = 1\" \"j \u003c i\" \"++j\" \n           [If \"i % j == 0\" [Exp \"acc += j\"] []]), \n        (If \"i == acc\" [Exp \"printf(\\\"%d\\\\n\\\", i)\"] []), \n        (Exp \"++i\")]]\n```\n\nAfter translation:\n\n```c\n*Main\u003e ts s5\nint i = 1;\nL0:;\nif (!(i \u003c= 10000)) goto L2;\nint acc = 0;\nint j = 1;\nL3:;\nif (!(j \u003c i)) goto L6;\nif (i % j == 0) acc += j;\nL4:;\n++j;\ngoto L3;\nL6:;\nL5:;\nif (i == acc) printf(\"%d\\n\", i);\n++i;\ngoto L0;\nL2:;\nL1:;\n```\n\n### Switch\n\n``` haskell\ns4 = [Exp \"int i = 0\", \n    Switch \"i\" \n       [(\"0\", [Exp \"printf(\\\"%d = 0\\\\n\\\", i)\"]), \n        (\"1\", [Exp \"printf(\\\"%d = 1\\\\n\\\", i)\"]), \n        (\"2\", [Exp \"printf(\\\"%d = 2\\\\n\\\", i)\"])] \n       [Exp \"printf(\\\"other\\\\n\\\")\"]]\n```\n\ninto:\n\n```c\n*Main\u003e ts s4\nint i = 0;\nif (i == 0) goto L0;\nif (i == 1) goto L2;\nif (i == 2) goto L4;\nprintf(\"other\\n\");\ngoto L5;\nL4:;\nprintf(\"%d = 2\\n\", i);\nL5:;\ngoto L3;\nL2:;\nprintf(\"%d = 1\\n\", i);\nL3:;\ngoto L1;\nL0:;\nprintf(\"%d = 0\\n\", i);\nL1:;\n```\n\n## Report A Problem\n\nFeel free to report mistakes I made or give suggestions at  [GitHub Issue](https://github.com/noti0na1/CodeTranslator/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoti0na1%2Fcodetranslator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoti0na1%2Fcodetranslator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoti0na1%2Fcodetranslator/lists"}