{"id":18841758,"url":"https://github.com/nirlep5252/fun","last_synced_at":"2025-04-14T07:31:11.673Z","repository":{"id":201698090,"uuid":"704877266","full_name":"Nirlep5252/fun","owner":"Nirlep5252","description":"A funny little interpreted programming language heavily inspired by Lox.","archived":false,"fork":false,"pushed_at":"2024-03-26T16:38:07.000Z","size":103,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T21:11:30.723Z","etag":null,"topics":["interpreter","java","language","lox","parser"],"latest_commit_sha":null,"homepage":"https://github.com/Nirlep5252/fun/releases","language":"Java","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/Nirlep5252.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["nirlep5252"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-10-14T11:25:09.000Z","updated_at":"2024-03-26T16:34:39.000Z","dependencies_parsed_at":"2024-03-26T17:45:21.223Z","dependency_job_id":null,"html_url":"https://github.com/Nirlep5252/fun","commit_stats":null,"previous_names":["nirlep5252/breakingmath","nirlep5252/fun"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nirlep5252%2Ffun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nirlep5252%2Ffun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nirlep5252%2Ffun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nirlep5252%2Ffun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nirlep5252","download_url":"https://codeload.github.com/Nirlep5252/fun/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248839350,"owners_count":21169795,"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":["interpreter","java","language","lox","parser"],"created_at":"2024-11-08T02:52:23.241Z","updated_at":"2025-04-14T07:31:11.339Z","avatar_url":"https://github.com/Nirlep5252.png","language":"Java","funding_links":["https://github.com/sponsors/nirlep5252"],"categories":[],"sub_categories":[],"readme":"# Fun\n\nFun is a fun interpreted programming language inspired by [Lox](https://github.com/munificent/craftinginterpreters).\n\nIt supports:\n\n- [x] Basic mathematical operations (`+`, `-`, `*`, `/`, `**`)\n- [x] Builtin mathematical functions (`sin`, `cos`, `tan`, `log`)\n- [x] Parenthesis\n- [x] Unary operators (`-`)\n- [x] Print/Show output (`show`)\n- [x] Boolean values (`true`, `false`)\n- [x] Comparison operators (`==`, `\u003c`, `\u003e`, `\u003c=`, `\u003e=`)\n- [x] Logical operators (`and`, `or`)\n- [x] Variables\n- [x] Optional mutability of variables\n- [x] Variable scoping\n- [x] User defined functions\n- [ ] `return` statements in functions\n- [x] Control flow (`if`, `else`, `for`, `while`)\n- [ ] `break` and `continue` statements\n- [x] User input (`get`)\n- [ ] Importing other files (`use`)\n- [ ] Prepositional logic (premises, validation of statements, rules of inference, etc.) (real shit)\n\n## How to run the interpreter?\n\n- Install [Java 21](https://openjdk.org/projects/jdk/21/) or above.\n- Get the `fun.jar` file from the [releases](https://github.com/Nirlep5252/fun/releases)\n- Run the following command:\n\n    ```bash\n    java -jar fun.jar \u003cpath_to_your_code_file\u003e\n    ```\n\n## Examples\n\n1. Basic stuff\n\n    ```python\n    let a = 6;\n    let b = 9;\n    show a + b + a * b;\n\n    show (2 + -3) * (5 + 4) ** 2; # u can use parenthesis or the `**` operator for exponentiation\n    ```\n\n    Output:\n\n    ```text\n    69\n    -81\n    ```\n\n2. Boolean values and comparisons and logical operations\n\n    ```python\n    let a = 123;\n    let b = 456;\n\n    show a == b;\n    show not (a == b); # there is no `!=`\n    show a \u003e= b;\n    show a \u003e b;\n    show a \u003c= b;\n    show a \u003c b;\n\n    let x = true;\n    let y = untrue; # same as false lol\n\n    show x or y; # true\n    show x and y; # false\n    ```\n\n    Output\n\n    ```text\n    false\n    true\n    false\n    false\n    true\n    true\n    true\n    false\n    ```\n\n3. Variable scope\n\n    ```python\n    let a = 123;\n\n    {\n        let a = 456;\n        show a; # 456\n        let b = 69;\n    }\n\n    show a; # 123\n    show b; # error! `b` is not defined\n    ```\n\n    Output\n\n    ```text\n    456\n    123\n    [line 10] ERROR: Variable `b` is not defined.\n    ```\n\n4. Variable mutability\n\n    ```python\n    let a = 123;\n    let mut b = 456;\n\n    b = b + 1;\n    show b; # 457\n\n    a = a + 1; # error! `a` is not mutable\n    ```\n\n    Output\n\n    ```text\n    457\n    [line 7] ERROR: Variable `a` is not mutable.\n    ```\n\n5. Control flow\n\n    ```python\n    let a = 123;\n    let b = 456;\n\n    if a \u003e b {\n        show 1;\n    } else {\n        show 2;\n    }\n\n    let mut i = 0;\n    while i \u003c= 5 {\n        show i;\n        i = i + 1;\n    }\n\n    # for loop is just a while loop with a fancy syntax\n    for i from 0 to 5 {\n        show i;\n    }\n\n    # exponential for loop\n    for i from 1 to 10000 by i {\n        show i;\n    }\n    ```\n\n    Output\n\n    ```text\n    2\n    0\n    1\n    2\n    3\n    4\n    5\n    0\n    1\n    2\n    3\n    4\n    5\n    1\n    2\n    4\n    8\n    16\n    32\n    64\n    128\n    256\n    512\n    1024\n    2048\n    4096\n    8192\n    ```\n\n6. User input\n\n    ```python\n    let a = get; # Gets a number from the user (value is NULL if user entered a non-number)\n    show a;\n\n    if a == NULL {\n        show -1;\n    } else {\n        show 1;\n    }\n    ```\n\n7. Functions\n\n    ```python\n    fn tower_of_hanoi (count, start, mid, end) {\n        if count == 1 {\n            show start, end;\n        } else {\n            tower_of_hanoi(count - 1, start, end, mid);\n            tower_of_hanoi(1, start, mid, end);\n            tower_of_hanoi(count - 1, mid, start, end);\n        }\n    }\n\n    tower_of_hanoi(get, 1, 2, 3);\n    ```\n\n    Output\n\n    ```text\n    3 (input)\n    1 3\n    1 2\n    3 2\n    1 3\n    2 1\n    2 3\n    1 3\n    ```\n\n## Language Grammar\n\n- This is similar to [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form)\n- Also inspired from: [https://craftinginterpreters.com/representing-code.html](https://craftinginterpreters.com/representing-code.html)\n\n```text\nprogram -\u003e declaration* EOF;\nblock -\u003e \"{\" declaration* \"}\";\ndeclaration -\u003e functionDeclaration | variableDeclaration | statement;\nstatement -\u003e expressionStatement | printStatement | ifStatement | whileStatement | forStatement | block;\n\nfunctionDeclaration -\u003e \"fn\" function \";\";\nfunction -\u003e IDENTIFIER \"(\" parameters? \")\" block;\nvariableDeclaration -\u003e \"let\" (\"mut\")? IDENTIFIER \"=\" expression \";\";\nexpressionStatement -\u003e expression \";\";\nprintStatement -\u003e \"print\" expression ( \",\" expression )* \";\";\nifStatement -\u003e \"if\" expression statement (\"else\" statement)?;\nwhileStatement -\u003e \"while\" expression statement;\nforStatement -\u003e \"for\" IDENTIFIER \"from\" expression \"to\" expression (\"by\" expression)? statement;\n\nexpression -\u003e assignment;\nassignment -\u003e (IDENTIFIER \"=\" assignment) | logic_or;\nlogic_or -\u003e logic_and (\"or\" logic_and)*;\nlogic_and -\u003e equality (\"and\" equality)*;\nequality -\u003e comparison ((\"==\") comparison)*;\ncomparison -\u003e term ((\"\u003e\" | \"\u003e=\" | \"\u003c\" | \"\u003c=\") term)*;\nterm -\u003e factor (( \"+\" | \"-\" ) factor)*;\nfactor -\u003e pow (( \"/\" | \"*\" | \"%\" ) pow)*;\npow -\u003e unary (\"**\" unary)*;\nunary -\u003e ((\"-\" | NOT) unary) | call;\ncall -\u003e primary (\"(\" arguments? \")\")*;\narguments -\u003e expression (\",\" expression)*\nprimary -\u003e NUMBER | \"(\" expression \")\" | IDENTIFIER | TRUE | FALSE | GET | NULL;\n```\n\n## References\n\n- Guide Followed: \u003chttps://craftinginterpreters.com/\u003e OR \u003chttps://github.com/munificent/craftinginterpreters\u003e\n- Visitor Pattern: \u003chttps://en.wikipedia.org/wiki/Visitor_pattern\u003e\n- BNF: \u003chttps://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirlep5252%2Ffun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnirlep5252%2Ffun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirlep5252%2Ffun/lists"}