{"id":28958729,"url":"https://github.com/shaina-gh/machine-code-generation","last_synced_at":"2025-06-23T23:06:37.178Z","repository":{"id":297581499,"uuid":"997242537","full_name":"shaina-gh/machine-code-generation","owner":"shaina-gh","description":"A C++ program that simulates compiler backend phases by converting infix expressions into postfix notation, quadruples, and machine-level code.","archived":false,"fork":false,"pushed_at":"2025-06-06T07:40:31.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-06T08:31:48.195Z","etag":null,"topics":["compiler-design","cpp","infix-to-postfix","machine-code-generation","machine-level-code","quadruples"],"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/shaina-gh.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-06T07:37:25.000Z","updated_at":"2025-06-06T07:41:55.000Z","dependencies_parsed_at":"2025-06-06T08:41:58.862Z","dependency_job_id":null,"html_url":"https://github.com/shaina-gh/machine-code-generation","commit_stats":null,"previous_names":["shaina-gh/machine-code-generation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shaina-gh/machine-code-generation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Fmachine-code-generation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Fmachine-code-generation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Fmachine-code-generation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Fmachine-code-generation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaina-gh","download_url":"https://codeload.github.com/shaina-gh/machine-code-generation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Fmachine-code-generation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261571512,"owners_count":23178768,"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-design","cpp","infix-to-postfix","machine-code-generation","machine-level-code","quadruples"],"created_at":"2025-06-23T23:06:36.450Z","updated_at":"2025-06-23T23:06:37.170Z","avatar_url":"https://github.com/shaina-gh.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Machine Code Generation \n\n---\n\n## 🎯 Aim\n\nTo develop a compiler phase that converts a given infix arithmetic expression into:\n1. Postfix notation (Reverse Polish Notation),\n2. Quadruples (Intermediate Code Representation),\n3. Three-Address / Machine Code.\n\n---\n\n## 🧠 Explanation\n\nThis program simulates the backend phase of a compiler, which is responsible for generating intermediate and target code from a high-level expression. It performs:\n\n- **Conversion from infix to postfix** using operator precedence and a stack.\n- **Generation of quadruples**, a standard intermediate representation in compilers using temporary variables.\n- **Creation of Three-Address Code (TAC)** or **Machine code-like instructions** for arithmetic operations.\n\nThis process mirrors how a real compiler breaks down high-level arithmetic into machine-executable code.\n\n---\n\n## 🔁 Logic\n\n### Step-by-step Process:\n1. **Infix to Postfix Conversion**:\n   - Use a stack to manage operators and apply precedence rules to form the postfix expression.\n\n2. **Quadruple Generation**:\n   - Traverse the postfix expression.\n   - For each operator, pop the top two operands, apply the operation, and store the result in a temporary variable `t1, t2...`.\n\n3. **Three-Address Code (TAC) / Machine Code Generation**:\n   - For each operation, generate equivalent low-level instructions:\n     - Use `MOV`, `ADD`, `MUL`, and `POW` instructions for computation.\n     - Results are stored in temporaries and finally assigned to a variable `a`.\n\n---\n\n## 📥 Sample Input \u0026 Output\n\n### ✅ Input\n```cpp\nInput an expression: a+b*c\n```\n\n### 🔁 Output\n```cpp\nPostfix Expression: abc*+\n\nQuadruples:\n(+, a, t1, t2)\n(*, b, c, t1)\n\nThree-Address Code/Machine Code:\nMOV b, R0\nMUL c, R0\nMOV R0, t1\nMOV a, R0\nADD t1, R0\nMOV R0, t2\nMOV t2, a\n```\n\n---\n\n## 🌐 Real-World Applications\n\n- **Compiler Construction**: Forms the core of backend phases in compilers like GCC or Clang.\n- **Virtual Machines**: Used in interpreters like Python (CPython) or JVM to generate bytecode.\n- **Code Optimisation Tools**: Intermediate representations, such as quadruples, are used for optimisation passes.\n- **Static Analysis Tools**: These tools utilise such representations to detect bugs, inefficiencies, or vulnerabilities.\n\n---\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaina-gh%2Fmachine-code-generation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaina-gh%2Fmachine-code-generation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaina-gh%2Fmachine-code-generation/lists"}