{"id":21294721,"url":"https://github.com/vaquierm/golite_transpiler","last_synced_at":"2025-07-11T16:33:21.506Z","repository":{"id":63419063,"uuid":"237467649","full_name":"vaquierm/GoLite_Transpiler","owner":"vaquierm","description":"💻 Transpiler written in OCaml that that converts a subset of golang to C++","archived":false,"fork":false,"pushed_at":"2020-03-09T01:17:14.000Z","size":190,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-23T17:22:51.122Z","etag":null,"topics":["code-generation","cpp","golang","ocaml","parser","scanner","transpiler"],"latest_commit_sha":null,"homepage":"","language":"OCaml","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/vaquierm.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}},"created_at":"2020-01-31T16:15:40.000Z","updated_at":"2023-04-12T15:53:12.000Z","dependencies_parsed_at":"2022-11-18T15:02:33.989Z","dependency_job_id":null,"html_url":"https://github.com/vaquierm/GoLite_Transpiler","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaquierm%2FGoLite_Transpiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaquierm%2FGoLite_Transpiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaquierm%2FGoLite_Transpiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaquierm%2FGoLite_Transpiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaquierm","download_url":"https://codeload.github.com/vaquierm/GoLite_Transpiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225741039,"owners_count":17516895,"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":["code-generation","cpp","golang","ocaml","parser","scanner","transpiler"],"created_at":"2024-11-21T14:00:21.336Z","updated_at":"2024-11-21T14:01:08.714Z","avatar_url":"https://github.com/vaquierm.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoLite Transpiler 💻\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"banner.jpg\" width=\"700\" /\u003e\n\u003c/p\u003e\n\nThis project is a transpiler that converts goLite (A strict subset of [golang](https://golang.org/)) source code into [C++](http://www.cplusplus.com/) source code.\n\nThe transpiler is written in OCaml and the parser was built using **Ocamllex** (which comes with the OCaml distribution) and [**Menhir**](http://gallium.inria.fr/~fpottier/menhir/manual.html) (A scanner generator similar to [bison](https://www.gnu.org/software/bison/manual/bison.html) which is compatible with C)\n\n## GoLite specification 🚀\n\nAll supported features for the goLite language are described [**here**](goLite_spec.md)\n\n## Example\n\nThe simple binary search goLite program\n\n````go\npackage main\n\ntype l [10]int;\n\nfunc bin_search(array l, start, end, target int) int {\n\tif start \u003e end {\n\t\treturn -1;\n\t}\n\tvar mid = (end + start)/2;\n\tif array[mid] == target {\n\t\treturn mid;\n\t} else if array[mid] \u003e target {\n\t\treturn bin_search(array, start, mid - 1, target);\n\t} else {\n\t\treturn bin_search(array, mid + 1, end, target);\n\t}\n}\n\nfunc main() {\n\tvar glist l\n\tglist[0] = 0\n\tglist[1] = 3\n\tglist[2] = 3\n\tglist[3] = 8\n\tglist[4] = 9\n\tglist[5] = 10\n\tglist[6] = 13\n\tglist[7] = 14\n\tglist[8] = 18\n\tglist[9] = 19\n\n\tprintln(bin_search(glist, 0, 9, 13))\n}\n````\n\nIs transpiled to\n\n````cpp\n#include \u003carray\u003e\n#include \u003ciostream\u003e\nint bin_search(std::array\u003cint, 10\u003e \u0026array, int start, int end, int target);\nint main();\nint bin_search(std::array\u003cint, 10\u003e \u0026array, int start, int end, int target) {\n    if ((start \u003e end)) {\n        return (-1);\n    }\n    int mid = ((end + start) / 2);\n    if ((array[mid] == target)) {\n        return mid;\n    }\n    else {\n        if ((array[mid] \u003e target)) {\n            return bin_search(array, start, (mid - 1), target);\n        }\n        else {\n            return bin_search(array, (mid + 1), end, target);\n        }\n    }\n}\nint main() {\n    std::array\u003cint, 10\u003e glist;\n    glist[0] = 0;\n    glist[1] = 3;\n    glist[2] = 3;\n    glist[3] = 8;\n    glist[4] = 9;\n    glist[5] = 10;\n    glist[6] = 13;\n    glist[7] = 14;\n    glist[8] = 18;\n    glist[9] = 19;\n    std::cout \u003c\u003c bin_search(glist, 0, 9, 13) \u003c\u003c std::endl;\n}\n\n````\n\nMore complicated example can be found [here](examples.md)\n\n## How to run it! 🏃‍\n\n**1. Clone the repo**\n\n````\n$ git clone https://github.com/vaquierm/GoLite_Transpiler.git\n````\n\n**2. Install OCaml**\n\n````\n$ sudo apt install ocaml\n````\n\n**3. Install opam (to install the testing package)**\n\n````\n$ add-apt-repository ppa:avsm/ppa\n$ sudo apt install opam\n$ opam init\n````\n\n**4. Install [ounit](https://github.com/gildor478/ounit)** (for tests)\n\n````\n$ opam install ounit2\n````\n\n**5. Run all tests** (Hopefully they pass 😟)\n\n````\n$ make test\n````\n\n**6. Compile the transpiler**\n\n````\n$ make\n````\n\n**7. Transpile a goLite file** (Insert the filepath of the goLite file you want to transpile into ````\u003cgoLite_file\u003e.go````)\n\n````\n$ ./goLite_transpiler \u003cgoLite_file\u003e.go\n````\n\n- If there are syntax or type errors a message will be displayed.\n- If everything was fine, a file ````\u003cgoLite_file\u003e.cpp```` which contains the translated program will be generated.\n\n**8. Compile and run the C++ file** (if you want)\n\n````\n$ g++ \u003cgoLite_file\u003e.cpp -o \u003cgoLite_file\u003e.out \u003cgoLite_file\u003e.cpp\n$ ./\u003cgoLite_file\u003e.out\n````\n\n**9. Clean up the repo** (deletes all build files and generated transpiled files)\n\n````\n$ make clean\n````\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaquierm%2Fgolite_transpiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaquierm%2Fgolite_transpiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaquierm%2Fgolite_transpiler/lists"}