{"id":19053068,"url":"https://github.com/louisdh/cub","last_synced_at":"2025-09-02T15:06:19.063Z","repository":{"id":56906878,"uuid":"120228547","full_name":"louisdh/cub","owner":"louisdh","description":"The Cub Programming Language","archived":false,"fork":false,"pushed_at":"2018-09-25T19:18:22.000Z","size":484,"stargazers_count":224,"open_issues_count":4,"forks_count":18,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-15T09:34:50.924Z","etag":null,"topics":["ast","bytecode","compiler","interpreter","lexer","parser","virtual-machine"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/louisdh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-04T22:19:44.000Z","updated_at":"2025-03-07T22:41:12.000Z","dependencies_parsed_at":"2022-08-21T02:21:01.167Z","dependency_job_id":null,"html_url":"https://github.com/louisdh/cub","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/louisdh/cub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisdh%2Fcub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisdh%2Fcub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisdh%2Fcub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisdh%2Fcub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/louisdh","download_url":"https://codeload.github.com/louisdh/cub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisdh%2Fcub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273301877,"owners_count":25081105,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ast","bytecode","compiler","interpreter","lexer","parser","virtual-machine"],"created_at":"2024-11-08T23:28:56.290Z","updated_at":"2025-09-02T15:06:19.045Z","avatar_url":"https://github.com/louisdh.png","language":"Swift","funding_links":["https://paypal.me/louisdhauwe"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/louisdh/lioness\"\u003eLioness\u003c/a\u003e \u0026bull;\n  \u003cb\u003e Cub \u003c/b\u003e \u0026bull;\n  \u003ca href=\"https://github.com/louisdh/savannakit\"\u003eSavannaKit\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"docs/resources/readme/logo@2x.png\" alt=\"Cub Logo\" height=\"200px\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eThe Cub Programming Language\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://travis-ci.org/louisdh/cub\"\u003e\u003cimg src=\"https://travis-ci.org/louisdh/cub.svg?branch=master\" alt=\"Travis build status\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/louisdh/cub\"\u003e\u003cimg src=\"https://codecov.io/gh/louisdh/cub/branch/master/graph/badge.svg\" alt=\"Codecov\"/\u003e\u003c/a\u003e\n\u003cbr\u003e\n\u003cimg src=\"https://img.shields.io/badge/version-1.0.1-blue.svg\" style=\"max-height: 300px;\" alt=\"version 1.0.1\"\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4bc51d.svg?style=flat\" style=\"max-height: 300px;\" alt=\"Carthage Compatible\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://developer.apple.com/swift/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift-4.1-orange.svg?style=flat\" style=\"max-height: 300px;\" alt=\"Swift\"/\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-lightgrey.svg\" style=\"max-height: 300px;\" alt=\"Platform: iOS macOS tvOS watchOS\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/extension-.cub-FF9C27.svg\" style=\"max-height: 300px;\" alt=\"Extension: .cub\"\u003e\n\u003cbr\u003e\n\u003ca href=\"http://twitter.com/LouisDhauwe\"\u003e\u003cimg src=\"https://img.shields.io/badge/Twitter-@LouisDhauwe-blue.svg?style=flat\" style=\"max-height: 300px;\" alt=\"Twitter\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://paypal.me/louisdhauwe\"\u003e\u003cimg src=\"https://img.shields.io/badge/Donate-PayPal-green.svg?style=flat\" alt=\"Donate via PayPal\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nCub is an interpreted, dynamically typed, scripting language inspired by Swift. This project includes a lexer, parser, compiler and interpreter, all written in Swift.\n\nCub is used for [OpenTerm](https://github.com/louisdh/openterm)'s scripting feature. A language guide is available in OpenTerm and [online](https://silverfox.be/cub/guide/index.html).\nCub was derived from [Lioness](https://github.com/louisdh/lioness) (my first programming language).\n\nThe standard library (abbreviated: stdlib) contains basic utility functions, for example to convert from/to dates.\n\n## Source examples\nThe following Cub code calculates factorials recursively:\n\n```swift\nfunc factorial(x) returns {\n\t\n    if x \u003e 1 {\n        return x * factorial(x - 1)\n    }\n\t\n    return 1\n}\n\na = factorial(5) // a = 120\n```\n\nThe following Cub code uses a ```do times``` loop:\n\n```swift\na = 1\nn = 10\ndo n times {\n    a += a\n}\n// a = 1024\n```\n\n*More examples can be found [here](Source%20examples).*\n\n## External functions\nAn important feature Cub has is the ability to define external functions. These functions are implemented in native code (for example Swift) and thus allows Cub to call native code.\n\nAn external function pauses the interpreter, executes the native code, and resumes the interpreter when the native code is executed.\n\nThe following example implements a print function:\n\n```swift\nlet runner = Runner(logDebug: true, logTime: true)\n\t\t\nrunner.registerExternalFunction(name: \"print\", argumentNames: [\"input\"], returns: true) { (arguments, callback) in\n\t\t\t\n\tfor (name, arg) in arguments {\n\t\tprint(arg)\n\t}\n\t\t\t\n\tcallback(nil)\n}\n\n```\n\nExternal functions are called like any other global functions in Cub, the print function from the example above could be called like this:\n\n```swift\nprint(\"Hello world\")\n```\n\n\n## Features\n\n* Minimalistic, yet expressive, syntax\n* No type system, language is dynamic\n* 5 basic operators: ```+```, ```-```, ```/```, ```*``` and ```^```\n\t* ```^``` means \"to the power of\", e.g. ```2^10``` equals 1024\n\t* all operators have a shorthand, e.g. ```+=``` for ```+```\n* Numbers\n\t* All numbers are floating point \n* Booleans\n\t* Can be evaluated from comparison\n\t* Can be defined by literal: ```true``` or ```false``` \n* Strings\n\t* Can be concatenated with the + operator \n* Arrays\n\t* Can contain any type, including other arrays  \n* Functions\n\t* Supports parameters, returning and recursion \n\t* Can be declared inside other functions\n* Structs\n\t* Can contain any type, including other structs  \n* Loops\n\t* ```for```\n\t* ```while```\n\t* ```do times```\n\t* ```repeat while```\n\t* ```break```\n\t* ```continue```\n* ```if``` / ```else``` / ```else if``` statements\n\n## Running\nSince the project does not rely on any dependencies, running it requires no setup. \n\n### macOS\nOpen ```Cub.xcworkspace``` (preferably in the latest non-beta version of Xcode) and run the ```macOS Example``` target. The example will run the code in ```A.cub```. The output will be printed to the console.\n\n## Installing framework\n \n### Using Swift Package Manager\n\nAdd to your `Package.swift` file's `dependencies` section:\n\n```swift\n.Package(url: \"https://github.com/louisdh/cub.git\",\n\t\t         majorVersion: 1, minor: 0)\n```\n\n### Using [CocoaPods](http://cocoapods.org)\n\nAdd the following line to your ```Podfile```:\n\n```ruby\npod 'Cub', '~\u003e 1.0'\n```\n\n### Using [Carthage](https://github.com/Carthage/Carthage)\nAdd the following line to your ```Cartfile```:\n\n```ruby\ngithub \"louisdh/cub\" ~\u003e 1.0\n```\nRun ```carthage update``` to build the framework and drag the built ```Cub.framework``` into your Xcode project.\n\n## Roadmap\n- [x] Structs\n- [x] Completion suggestions  (given an incomplete source string and insertion point)\n- [ ] Breakpoint support in interpreter\n- [x] Stdlib documentation\n- [ ] Compiler warnings\n- [ ] Compiler optimizations\n- [x] Faster Lexer (without regex)\n- [x] Support emoticons for identifier names\n- [ ] ```guard``` statement\n- [ ] A lot more unit tests\n- [x] Linux support\n\n## Xcode file template\nCub source files can easily be created with Xcode, see [XcodeTemplate.md](XcodeTemplate.md) for instructions.\n\n\n## Architecture\nA detailed explanation of the project's architecture can be found [here](docs/Architecture.md).\n\n## License\n\nThis project is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisdh%2Fcub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flouisdh%2Fcub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisdh%2Fcub/lists"}