{"id":22598682,"url":"https://github.com/it1shka/toylang","last_synced_at":"2025-07-29T22:12:43.958Z","repository":{"id":191939150,"uuid":"685513145","full_name":"it1shka/toylang","owner":"it1shka","description":"Interpreted scripting language implemented in C++","archived":false,"fork":false,"pushed_at":"2023-09-24T20:58:24.000Z","size":114,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T21:35:22.559Z","etag":null,"topics":["compiler","cpp","interpreter","programming-language","toy"],"latest_commit_sha":null,"homepage":"","language":"C++","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/it1shka.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-31T12:01:10.000Z","updated_at":"2024-06-05T08:14:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"b9901bda-229c-4ace-bef3-c74e193376d6","html_url":"https://github.com/it1shka/toylang","commit_stats":null,"previous_names":["it1shka/toylang"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it1shka%2Ftoylang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it1shka%2Ftoylang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it1shka%2Ftoylang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it1shka%2Ftoylang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/it1shka","download_url":"https://codeload.github.com/it1shka/toylang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246088425,"owners_count":20721682,"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":["compiler","cpp","interpreter","programming-language","toy"],"created_at":"2024-12-08T11:06:38.772Z","updated_at":"2025-03-28T19:32:02.526Z","avatar_url":"https://github.com/it1shka.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Toy Programming language\n\nAn interpreted language implemented in C++\n\n## Table of Contents\n\n- [Installation](#Installation)\n- [Short Guide](#ShortGuide)\n- [Real Application Example](#AppExample)\n- [Builtin Functions](#BuiltinFunctions)\n- [Contacts](#Contacts)\n\n## Installation\n\nIn order to work with the language,\nyou need to build it on your local machine.\nYou have to clone the project from this repo\nand build it using __CMake__\n\n\u003e Attention! You need to exclude __'tests'__ from \n\u003e directories listed in root __CMakeLists.txt__\n\u003e because the testing library (Google Test) is \n\u003e gitignored\n\n```shell\ngit clone https://github.com/it1shka/toylang\ncd toylang\ncodium CMakeLists.txt # open CMakeLists.txt in any text editor\n```\n\nAfter doing if everything is done successfully,\nyou will see __CMakeLists.txt__ file (it will look similar to \nthe one listed below):\n```cmake\nproject(toy_lang)\n# Exclude \"tests\" folder from the array below -- it's important!\nset(DIRECTORIES \"utils\" \"lexer\" \"parser\" \"interpreter\" \"app\" \"tests\") # Exclude the last\n\nforeach(directory ${DIRECTORIES})\n    message(\"Adding a subdirectory: ${directory}\")\n    add_subdirectory(${directory})\nendforeach()\n```\n\nFinally, you are ready to build:\n```shell\ncmake .\ncmake --build app\n```\n\nAnd you can find an executable following the path:\n**\"toylang/app/toy_lang_app\"**:\n\n```shell\ncd app\n./toy_lang_app help\n```\n\n## Short Guide\n\n1. Variable declaration \n```toy\nlet a = 1;\nlet b = a + 2;\nlet c;\n```\n2. For loop\n```toy\nfor (i from 1 to 10) {\n    echo \"Hello, \" + i;\n}\n\nlet sum = 0;\nfor (i from 1 to 100 step 2) {\n    sum += i;\n}\n```\n3. While loop\n```toy\nwhile (true) {\n    println(\"Infinite cycle\");\n}\n\nlet a = 0;\nwhile (a \u003c 10) a += 1;\n```\n4. Flow operators (break, continue, return)\n```toy\nlet running = true;\nwhile (running) {\n    if (input() == 'exit') break;\n    else continue; # Just for illustration purposes,\n                   # makes no sense\n}\n\nfun add(a, b) {\n    return a + b;\n}\n\nfun doSomething() {\n    echo \"Doing something\";\n    return; # For illustration purposes\n            # makes no sense\n}\n```\n5. If-Else statement\n```toy\nlet info = [input(\"Name: \"), input(\"Surname: \")];\nif (info == [\"Tikhon\", \"Belousov\"]) echo \"you are author\";\nelse {\n    echo \"you are user\";\n}\n```\n6. Functions\n```toy\nfun map(arr, fn) {\n    let output = array();\n    for (i from 0 to size(arr)) {\n        let elem = arr[i];\n        output += fn(elem);\n    }\n    return output;\n}\n\nfun main() {\n    let numbers = [1, 2, 3, 4, 5];\n    let doubled = map(numbers, lambda(x) { return x * 2; });\n    echo doubled;\n}\n```\n7. Import/Export\n```toy\n# library.toy\nexports.add = lambda(a, b) {\n    return a + b;\n};\n\n# lib2.toy\nfun subtract(a, b) {\n    return a - b;\n}\nexports = subtract;\n\n# main.toy\nimport library as lib;\nimport lib2;\necho lib.add(1, 2);\necho lib2(2, 1);\n```\n8. Output to the console\n```toy\necho \"Hello world!\"; # Prints to the output and hits new line\nprintln(\"Hello, \", \"world!\"); # The same as echo, but accepts multiple args\nprint(\"Hello, world!\"); # Prints without new line\n```\n9. Creating objects and values\n```toy\nlet a = 1.123123123;\nlet b = \"Hello\";\nlet c = 'world';\nlet d = true and false;\nlet nothing = nil;\nlet names = ['Tikhon', 'Sasha', \"Mateusz\", \"Jan\"];\nlet add = lambda(a, b) { return a + b; };\nlet me = obj {\n    \"name\": \"Tikhon\",\n    \"surname\": \"Belousov\",\n    \"age\": 19,\n};\n```\n10. Math operators:\n```\n=, or, and, ==, !=, \u003c, \u003e, \u003c=, \u003e=, -, +, *, /, div, mod, ^, not\n```\n11. OOP\n```toy\nfun Cat(name) {\n    \n    let foodEaten = 0;\n\n    fun meow() {\n        echo \"Cat \" + name + \"said meow!\";\n    }\n    \n    fun purr() {\n        echo \"Cat \" + name + \"said purrrrr!\";\n    }\n    \n    fun feed(food) {\n        foodEaten += food;\n    }\n    \n    fun hungry() {\n        return foodEaten \u003c 100;\n    }\n    \n    return obj {\n        \"meow\": meow,\n        \"purr\": purr,\n        \"feed\": feed,\n        \"hungry\": hungry,\n    };\n}\n```\n\n## Real Application Example\n\nI built a minesweeper console app in my language.\nYou can find it [here](https://github.com/it1shka/minesweeper-toy)\n\n## Builtin Functions\nBelow there is a list of functions included in __language prelude__\n\n1. **size(array)**\n   Returns the size (number of elements) of the given array.\n\n2. **chars(string)**\n   Converts a string into an array of individual characters.\n\n3. **abs(number)**\n   Returns the absolute value of the given number.\n\n4. **all(array)**\n   Returns true if all elements in the array evaluate to true; false otherwise.\n\n5. **any(array)**\n   Returns true if any element in the array evaluates to true; false otherwise.\n\n6. **print(...args)**\n   Prints the string representations of the provided arguments to the standard output.\n\n7. **println(...args)**\n   Prints the string representations of the provided arguments to the standard output, followed by a newline.\n\n8. **array(...args)**\n   Creates an array containing the provided arguments.\n\n9. **input(...args)**\n   Prints the string representations of the provided arguments, then reads a line of input from the user.\n\n10. **bool(value)**\n    Converts the given value to a boolean.\n\n11. **number(value)**\n    Converts the given value to a number.\n\n12. **max(array)**\n    Returns the maximum value in the array.\n\n13. **min(array)**\n    Returns the minimum value in the array.\n\n14. **range(start, end, step)**\n    Generates an array of numbers from start to end with the specified step size.\n\n15. **typeof(value)**\n    Returns the type of the given value as a string.\n\n16. **str(value)**\n    Converts the given value to its string representation.\n\n17. **sum(array)**\n    Computes the sum of all elements in the array.\n\n18. **slice(array, start, end)**\n    Returns a sub-array from the specified start index to the end index.\n\n19. **reversed(array)**\n    Returns a new array with the elements in reverse order.\n\n20. **read(filename)**\n    Reads the contents of a file specified by the filename.\n\n21. **write(filename, content)**\n    Writes the content to a file specified by the filename.\n\n22. **round(number)**\n    Rounds the given number to the nearest integer.\n\n23. **trunc(number)**\n    Truncates the given number towards zero.\n\n24. **keys(object)**\n    Returns an array of keys from the given object.\n\n25. **values(object)**\n    Returns an array of values from the given object.\n\n26. **wait(milliseconds)**\n    Pauses the execution for the specified number of milliseconds.\n\n27. **cls()**\n    Clears the console screen.\n\n28. **rand(lower, upper)**\n    Generates a random number between the lower and upper bounds.\n\n29. **randint(lower, upper)**\n    Generates a random integer between the lower and upper bounds.\n\n## Contacts\n\nIn case you have some suggestions / bugs to share with me, \nfeel free to contact me via email [2tishbel@gmail.com](mailto:2tishbel@gmail.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fit1shka%2Ftoylang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fit1shka%2Ftoylang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fit1shka%2Ftoylang/lists"}