{"id":15466172,"url":"https://github.com/mozamimy/kaguya","last_synced_at":"2025-03-28T11:45:07.439Z","repository":{"id":56879809,"uuid":"86977927","full_name":"mozamimy/kaguya","owner":"mozamimy","description":"Kaguya is an implementation of Brainf**k by Ruby","archived":false,"fork":false,"pushed_at":"2017-04-02T11:22:02.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T00:43:58.543Z","etag":null,"topics":["brainfuck","programming-language","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/mozamimy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-02T10:04:31.000Z","updated_at":"2017-04-02T10:50:30.000Z","dependencies_parsed_at":"2022-08-20T23:40:19.463Z","dependency_job_id":null,"html_url":"https://github.com/mozamimy/kaguya","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozamimy%2Fkaguya","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozamimy%2Fkaguya/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozamimy%2Fkaguya/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozamimy%2Fkaguya/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mozamimy","download_url":"https://codeload.github.com/mozamimy/kaguya/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246025938,"owners_count":20711575,"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":["brainfuck","programming-language","ruby"],"created_at":"2024-10-02T01:05:18.058Z","updated_at":"2025-03-28T11:45:07.411Z","avatar_url":"https://github.com/mozamimy.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kaguya\n\nKaguya is an implementation of Brainf\\*\\*k by Ruby.\n\nThis implementation consits of following elements,\n\n- Tiny parser\n- Tiny compiler\n- Tiny virtual stack machine\n\n## Installation\n\n```\n$ gem install kaguya\n```\n\n## Usage\n\n```\n$ kaguya helloworld.bf\n```\n\nAn option `--debug` helps you to see AST and instruction sequence.\n\n```\n$ kaguya --debug helloworld.bf\n```\n\n## Technical components\n\n### Parser\n\nhttps://github.com/mozamimy/kaguya/blob/master/lib/kaguya/parser.rb\n\nThe parser parses a BF script one charactor at a time. Errors can be raised by the parser if the script contains invalid corresponding of `[` and `]` or invalid charactors.\n\nOnly the root node and `while` nodes have children.\n\n### Virtual machine\n\nhttps://github.com/mozamimy/kaguya/blob/master/lib/kaguya/vm.rb\n\nKaguya VM has a two stacks (left\\_stack, right\\_stack) and has following 9 instructions,\n\n- `forward`: Forward stack, if right\\_stack is empty then push 0 to left\\_stack else move top of right\\_stack to left\\_stack.\n- `backward`: Backward stack, top data of left\\_stack is poped and pushed to right\\_stack.\n- `increment`: Increment top of left\\_stack.\n- `decrement`: Decrement top of left\\_stack.\n- `output`: Output top of left\\_stack to standard I/O.\n- `input`: Input a value from standard I/O and push it to left\\_stack.\n- `branch_ifzero N`: Jump to an instruction at `PC - N` if top of left\\_stack is 0.\n- `branch_unlesszero N`: Jump to an instruction at `PC - N` unless top of left\\_stack is 0.\n- `leave`: Exit\n\n### Compiler\n\nhttps://github.com/mozamimy/kaguya/blob/master/lib/kaguya/compiler.rb\n\nKaguya compiler compiles an AST generated by the parser to an instruction sequence for Kaguya VM.\n\n### Example\n\n```\n[20:17:51]mozamimy@queen:kaguya (master) (-'x'-).oO(\n\u003e cat example/useless.bf\n\u003e\u003e+[\u003c\u003e[+-]]\n[20:17:53]mozamimy@queen:kaguya (master) (-'x'-).oO(\n\u003e be exe/kaguya --debug example/useless.bf\n=== AST ===\n#\u003cKaguya::AST::Node:0x007fd755a3f8c0\n @children=\n  [#\u003cKaguya::AST::Node:0x007fd755a3f780\n    @children=[],\n    @parent=#\u003cKaguya::AST::Node:0x007fd755a3f8c0 ...\u003e,\n    @type=:forward\u003e,\n   #\u003cKaguya::AST::Node:0x007fd755a3f500\n    @children=[],\n    @parent=#\u003cKaguya::AST::Node:0x007fd755a3f8c0 ...\u003e,\n    @type=:forward\u003e,\n   #\u003cKaguya::AST::Node:0x007fd755a3f230\n    @children=[],\n    @parent=#\u003cKaguya::AST::Node:0x007fd755a3f8c0 ...\u003e,\n    @type=:increment\u003e,\n   #\u003cKaguya::AST::Node:0x007fd755a3f028\n    @children=\n     [#\u003cKaguya::AST::Node:0x007fd755a3edd0\n       @children=[],\n       @parent=#\u003cKaguya::AST::Node:0x007fd755a3f028 ...\u003e,\n       @type=:backward\u003e,\n      #\u003cKaguya::AST::Node:0x007fd755a3e7e0\n       @children=[],\n       @parent=#\u003cKaguya::AST::Node:0x007fd755a3f028 ...\u003e,\n       @type=:forward\u003e,\n      #\u003cKaguya::AST::Node:0x007fd755a3e5b0\n       @children=\n        [#\u003cKaguya::AST::Node:0x007fd755a3e3f8\n          @children=[],\n          @parent=#\u003cKaguya::AST::Node:0x007fd755a3e5b0 ...\u003e,\n          @type=:increment\u003e,\n         #\u003cKaguya::AST::Node:0x007fd755a3e1f0\n          @children=[],\n          @parent=#\u003cKaguya::AST::Node:0x007fd755a3e5b0 ...\u003e,\n          @type=:decrement\u003e],\n       @parent=#\u003cKaguya::AST::Node:0x007fd755a3f028 ...\u003e,\n       @type=:while\u003e],\n    @parent=#\u003cKaguya::AST::Node:0x007fd755a3f8c0 ...\u003e,\n    @type=:while\u003e],\n @parent=nil,\n @type=:root\u003e\n=== ISEQ ===\n[[:forward, nil],\n [:forward, nil],\n [:increment, nil],\n [:branch_ifzero, 8],\n [:backward, nil],\n [:forward, nil],\n [:branch_ifzero, 4],\n [:increment, nil],\n [:decrement, nil],\n [:branch_unlesszero, -2],\n [:branch_unlesszero, -6],\n [:leave, nil]]\n=== RUN ===\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/mozamimy/kaguya.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozamimy%2Fkaguya","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmozamimy%2Fkaguya","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozamimy%2Fkaguya/lists"}