{"id":28717402,"url":"https://github.com/tarekmineroyal/minipascal-compiler","last_synced_at":"2025-06-15T03:15:37.746Z","repository":{"id":296912684,"uuid":"994959243","full_name":"TarekMineRoyal/minipascal-compiler","owner":"TarekMineRoyal","description":"End-to-end compiler for MiniPascal, a simplified Pascal language. Built with C++, Flex, and Bison, it parses, semantically analyzes, and generates assembly for a custom stack-based VM.","archived":false,"fork":false,"pushed_at":"2025-06-13T15:46:49.000Z","size":18791,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-13T16:55:27.719Z","etag":null,"topics":["abstract-syntax-tree","bison","c-plus-plus","c-plus-plus-17","code-generation","compiler","compiler-construction","compiler-design","flex","lexical-analysis","minipascal","parsing","pascal","programming-language","semantic-analysis","stack-based-virtual-machine","syntax-analysis","visitor-pattern"],"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/TarekMineRoyal.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-02T18:44:30.000Z","updated_at":"2025-06-13T15:46:52.000Z","dependencies_parsed_at":"2025-06-05T07:06:42.828Z","dependency_job_id":null,"html_url":"https://github.com/TarekMineRoyal/minipascal-compiler","commit_stats":null,"previous_names":["tarekmineroyal/compiler","tarekmineroyal/minipascal-compiler"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TarekMineRoyal/minipascal-compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarekMineRoyal%2Fminipascal-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarekMineRoyal%2Fminipascal-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarekMineRoyal%2Fminipascal-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarekMineRoyal%2Fminipascal-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TarekMineRoyal","download_url":"https://codeload.github.com/TarekMineRoyal/minipascal-compiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarekMineRoyal%2Fminipascal-compiler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259914924,"owners_count":22931334,"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":["abstract-syntax-tree","bison","c-plus-plus","c-plus-plus-17","code-generation","compiler","compiler-construction","compiler-design","flex","lexical-analysis","minipascal","parsing","pascal","programming-language","semantic-analysis","stack-based-virtual-machine","syntax-analysis","visitor-pattern"],"created_at":"2025-06-15T03:15:36.824Z","updated_at":"2025-06-15T03:15:37.723Z","avatar_url":"https://github.com/TarekMineRoyal.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MiniPascal Compiler\n\nA compiler for MiniPascal, a custom, simplified Pascal-like programming language. Implemented from scratch in C++ (std=c++17) using Flex for lexical analysis and Bison for syntax analysis. This project implements all the core phases of compiler design, from tokenizing to generating executable assembly for a custom stack-based virtual machine.\n\n### Current Status (as of June 9, 2025)\n\nThe compiler is now **functionally complete**. All major phases have been implemented, allowing the compiler to process MiniPascal source code with complex features, including nested subprograms, local and global scopes, and arrays, and generate executable assembly.\n\n* **Lexical \u0026 Syntax Analysis:** The frontend correctly tokenizes source code and builds a valid Abstract Syntax Tree (AST).\n* **Semantic Analysis:** The semantic analyzer correctly validates the AST for scope resolution, type checking (including `INTEGER`, `REAL`, `BOOLEAN`, and `ARRAY` types), and declaration verification.\n* **Code Generation:** The backend successfully traverses the semantically-validated AST and generates correct, executable assembly code for the target stack-based Virtual Machine.\n\n**All major language features have been implemented and tested, including full subprogram support (procedures and functions) and built-in I/O.**\n\n**Known Issues:**\n* There is a known bug causing a \"VM error: Illegal Operand\" when accessing local arrays declared inside a procedure or function. All other features, including global arrays and local simple variables, are working correctly.\n\n### Key Features of MiniPascal Supported\n\nThe compiler currently supports the following MiniPascal language features:\n\n* **Program Structure:** `PROGRAM ... BEGIN ... END.`\n* **Declarations:**\n    * `VAR`: For both global and local variables.\n    * Data Types: `INTEGER`, `REAL`, `BOOLEAN`.\n    * `ARRAY [low..high] OF standard_type`: One-dimensional arrays with support for variable indices.\n* **Subprograms:**\n    * `PROCEDURE Name(params); local_vars; BEGIN ... END;`\n    * `FUNCTION Name(params) : return_type; local_vars; BEGIN ... RETURN value; END;`\n    * Correct handling of parameters, local variables, and global variables.\n    * Support for recursive function calls.\n* **Statements:**\n    * Assignment: `variable := expression;`\n    * Compound: `BEGIN ... END;`\n    * Procedure Calls: `ProcName;` or `ProcName(arg1, arg2);`\n    * Conditional: `IF condition THEN statement ELSE statement;`\n    * Looping: `WHILE condition DO statement;`\n    * Function Return: `RETURN expression;`\n* **Expressions:**\n    * Arithmetic: `+`, `-`, `*`, `/` (real division), `div` (integer division).\n    * Relational: `=`, `\u003c\u003e`, `\u003c`, `\u003c=`, `\u003e`, `\u003e=`.\n    * Logical: `AND`, `OR`, `NOT`.\n    * Parentheses for grouping with correct operator precedence.\n* **Literals:** Integer, Real, Boolean (`TRUE`, `FALSE`), String (e.g., `'Hello'`).\n* **Built-in I/O:** `write`, `writeln`, `read`, `readln`.\n\n### Target Virtual Machine\n\nThe compiler targets a custom stack-based virtual machine.\n\n* **Architecture:** It uses separate stacks for execution and calls, with `gp` (global pointer) and `fp` (frame pointer) registers to manage variable scopes.\n* **Instruction Set:** The generator produces text-based assembly code (e.g., `pushi`, `storeg`, `alloc`, `jump`, `call`) that the VM executes directly.\n\n### Technologies Used\n\n* **C++:** (Standard: C++17) for the AST, semantic analysis, code generator, and main compiler logic.\n* **GNU Flex:** For lexical analysis (scanner generation).\n* **GNU Bison:** For syntax analysis (parser generation).\n* **GNU Make:** For building the project.\n* **Development Environment:** MinGW64 on Windows.\n\n### Next Steps / Future Goals\n\nWith the core language features now fully implemented, the project goals have shifted to stabilization and fixing bugs.\n\n* **Future Goal:**\n    * Fix the outstanding bug related to the allocation and use of **local arrays** inside subprograms.\n\n---\nProject Lead: Tarek\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarekmineroyal%2Fminipascal-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarekmineroyal%2Fminipascal-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarekmineroyal%2Fminipascal-compiler/lists"}