{"id":25733789,"url":"https://github.com/fade2black/mini-language","last_synced_at":"2026-06-11T02:31:14.918Z","repository":{"id":93678377,"uuid":"467572379","full_name":"fade2black/mini-language","owner":"fade2black","description":"A toy functional language written in Rust that generates WebAssembly text code as a target language","archived":false,"fork":false,"pushed_at":"2022-03-08T15:49:23.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T04:33:16.541Z","etag":null,"topics":["compiler-construction","rust","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/fade2black.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":"2022-03-08T15:38:03.000Z","updated_at":"2022-10-23T21:12:49.000Z","dependencies_parsed_at":"2023-05-27T02:00:43.456Z","dependency_job_id":null,"html_url":"https://github.com/fade2black/mini-language","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fade2black/mini-language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fade2black%2Fmini-language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fade2black%2Fmini-language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fade2black%2Fmini-language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fade2black%2Fmini-language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fade2black","download_url":"https://codeload.github.com/fade2black/mini-language/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fade2black%2Fmini-language/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"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":["compiler-construction","rust","webassembly"],"created_at":"2025-02-26T04:30:31.453Z","updated_at":"2026-06-11T02:31:14.914Z","avatar_url":"https://github.com/fade2black.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Compiler\nA compiler for simple toy functional language that allows to define functions, conditionals, and do math.\nI kept things simple and hence all types are 32-bit floating point and everything is expression ending with a semicolon.\nThis compiler converts the source code into WebAssembly Text (`wat`) and binary WebAssembly (`wasm`) files.\nLexer, parser, AST, and generating code are hand-written.\n\n## Requirement\nI use `wat2wasm` to generate WebAssembly binary from WebAssembly Text, so `wat2wasm` should be installed.\n\n## Examples\n```\n# Sum of first `n` integers\ndef sum(x) \n if x == 1 \n   then 1\n   else sum(x-1) + x;\n```\n```\n# Solution of a second\n# order equation with coeffients a,b,c\n\ndef root1(a b c)\n  if discr(a, b, c) \u003c 0\n  then 0 \n  else (-b + sqrt(discr(a, b, c)))/(2*a);\n\ndef root2(a b c)\n  if discr(a, b, c) \u003c 0\n  then 0 \n  else (-b - sqrt(discr(a, b, c)))/(2*a);\n```\n\n## Formal definition\n\n### Comments\nComments follows the symbol `#`\n\n### Keywords\n`def`, `if`, `then`, `else`\n\n### Lexer\n*Identifier* ::= *[a-zA-Z][a-zA-Z0-9]\\**\u003cbr\u003e\n*Number* ::= [0-9]?(.?[0-9])\n\n### Parser\n*Program* ::= **def** *Prototype Expression* ; | **def** *Prototype Expression* ; *Program*\u003cbr\u003e\n*Expression* ::= *Exp* | *IfExp*\u003cbr\u003e\n*Exp* ::= *SubExp* | *Exp* **\u003c** *SubExp* | *Exp* **\u003e** *SubExp* | *Exp* **\u003c\u003e** *SubExp* | *Exp* **==** *SubExp*\u003cbr\u003e \n*SubExp* ::= *Term* | *SubExp* **+** *Term* | *SubExp* **-** *Term* | *SubExp* **\\|** *Term*\u003cbr\u003e\n*Term* ::= *Factor* | *Term* **\\*** *Factor* | *Term* **/** *Factor* | *Term* **\u0026** *Factor*\u003cbr\u003e\n*Factor* ::= -**Exp** | ( *Exp* ) | *Identifier* |  *Number* | *FuncionCall*\u003cbr\u003e\n*FuncionCall* ::= *Identifier*(*Args*) | *Identifier*()\u003cbr\u003e\n*Args* ::= *Exp* | *Comma* *Args*\u003cbr\u003e\n*IfExp* ::= **if** *Exp* **then** *Exp* **else** *Exp*\u003cbr\u003e\n*Prototype* ::= *Identifier*(*Params*) | *Identifier*()\u003cbr\u003e\n*Params* ::= *Identifier* *Params* | *Identifier*\n\n### How to Run\n`cargo run source.txt target.wat`\nIt'll generate two files, `target.wat` and `target.wasm`.\nTo load `target.wasm` and call exported functions we could use javascript and `node.js`.\n\n\nFor example, create a source file computing the n-th Fibonacci number\n```\n# Fibbonaci\ndef fib(x)\n  if (x == 1) | (x == 2) \n    then 1 \n    else fib(x-1) + fib(x-2);\n```\n\nGenerate WebAssembly files `cargo run source.txt target.wat`. \nNext create a javascript file \n```\nconst { readFileSync } = require(\"fs\");\n\nconst run = async () =\u003e {\n  const buffer = readFileSync(\"./target.wasm\");\n  const module = await WebAssembly.compile(buffer);\n  const instance = await WebAssembly.instantiate(module);\n  console.log(instance.exports.fib(5));\n};\n\nrun();\n```\nand then run `node run.js`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffade2black%2Fmini-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffade2black%2Fmini-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffade2black%2Fmini-language/lists"}