{"id":29169369,"url":"https://github.com/amiralv82/bminor-to-c","last_synced_at":"2025-10-26T07:35:00.629Z","repository":{"id":301632665,"uuid":"1009868683","full_name":"amiralv82/bminor-to-c","owner":"amiralv82","description":"A minimal translator from the Bminor teaching language to readable C code.","archived":false,"fork":false,"pushed_at":"2025-06-27T22:16:01.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-27T22:33:03.100Z","etag":null,"topics":["c-language","compiler","compiler-construction","compiler-design","parser","transpiler"],"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/amiralv82.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,"zenodo":null}},"created_at":"2025-06-27T21:25:37.000Z","updated_at":"2025-06-27T22:16:04.000Z","dependencies_parsed_at":"2025-06-27T22:43:13.014Z","dependency_job_id":null,"html_url":"https://github.com/amiralv82/bminor-to-c","commit_stats":null,"previous_names":["amiralv82/bminor-to-c"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/amiralv82/bminor-to-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiralv82%2Fbminor-to-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiralv82%2Fbminor-to-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiralv82%2Fbminor-to-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiralv82%2Fbminor-to-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amiralv82","download_url":"https://codeload.github.com/amiralv82/bminor-to-c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiralv82%2Fbminor-to-c/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262959556,"owners_count":23391055,"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":["c-language","compiler","compiler-construction","compiler-design","parser","transpiler"],"created_at":"2025-07-01T12:00:50.720Z","updated_at":"2025-10-26T07:34:55.579Z","avatar_url":"https://github.com/amiralv82.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bminor → C Translator\n\nA lightweight **command-line compiler front-end** that converts programs written in the _Bminor_ teaching language into readable, vanilla C.\n\n\u003e **Why?**  \n\u003e Bminor is a tiny C-like language used in compiler courses (notably at the University of Wisconsin).  \n\u003e Translating Bminor to C lets you:\n\u003e 1.  run Bminor programs anywhere a C compiler exists, and  \n\u003e 2.  peek under the hood of basic compilation techniques—scanning, parsing, semantic checks, and code generation—without diving into full-blown LLVM.\n\n---\n\n## Key Features\n\n| Capability | Details |\n|------------|---------|\n| **Type-aware symbol table** | Tracks `integer`, `boolean`, `character`, and `string` identifiers for smarter translation (e.g., correct `printf` format specifiers). |\n| **Pretty C output** | Preserves indentation \u0026 comments, rewrites keywords (`True`/`False` → `true`/`false`), and converts `^` into `pow()` calls. |\n| **Function support** | Parses Bminor `function` blocks (name, parameters, return type) and emits idiomatic C signatures. |\n| **Rich `print` handling** | Builds a single `printf()` call with auto-generated format strings, handling literals \u0026 mixed arguments. |\n| **Control flow** | Translates `if`, `while`, `return`, array declarations, and assignment statements. |\n| **Zero external deps** | Pure C99—compiles with `gcc`, `clang`, or MSVC. |\n\n---\n\n## Build\n\n```bash\n# Clone\ngit clone https://github.com/\u003cyour-user\u003e/bminor-to-c.git\ncd bminor-to-c\n\n# Compile (GCC example)\ngcc -std=c99 -Wall -Wextra -o Parser Parser.c\n```\n\n---\n\nUsage\n```bash\n./Parser \u003csource.bminor\u003e \u003coutput.c\u003e\n# then compile the generated C\ngcc output.c -o program\n./program\n```\nExample\n```bminor\n// fibonacci.bminor\nn: integer = 10;\n\nfib: function integer (x: integer) = {\n    if (x \u003c 2) {\n        return x;\n    };\n    return fib(x - 1) + fib(x - 2);\n};\n\nprint \"fib(\", n, \") = \", fib(n);\n```\n```bash\n./Parser fibonacci.bminor fibonacci.c\ngcc fibonacci.c -o fib\n./fib\n# -\u003e fib(10) = 55\n```\nGenerated snippet (truncated):\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstdbool.h\u003e\n#include \u003cmath.h\u003e\n#include \u003cstring.h\u003e\n\nint n = 10;\n\nint fib(int x) {\n    if (x \u003c 2) {\n        return x;\n    }\n    return fib(x - 1) + fib(x - 2);\n}\n\nint main() {\n    printf(\"fib(%d) = %d\\n\", n, fib(n));\n    return 0;\n}\n```\n\n---\n\nProject Structure\n```\n.\n├── Parser.c         # Translator source (this repo)\n├── examples/        # Sample Bminor programs\n└── README.md\n```\n\n---\n\nCurrent Limitations / TODO:\n\n•\tNo full grammar verification—assumes well-formed Bminor input.\n\n•\tArrays are treated as int only.\n\n•\tFunctions returning non-primitive types are not yet supported.\n\n•\tNo static or dynamic semantic checks (e.g., undefined variables) beyond a simple symbol table.\n\n•\tPower operator supports only integer exponentiation via (int)pow(a,b).\n\n---\nAuthor\n\nAmir-Abbas Alvand\nFeel free to connect on GitHub or reach out with feedback!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famiralv82%2Fbminor-to-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famiralv82%2Fbminor-to-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famiralv82%2Fbminor-to-c/lists"}