{"id":19270857,"url":"https://github.com/lebinary/compiler","last_synced_at":"2026-03-19T09:02:36.247Z","repository":{"id":261122374,"uuid":"848845565","full_name":"lebinary/compiler","owner":"lebinary","description":"A compiler written in Java for educational purposes","archived":false,"fork":false,"pushed_at":"2025-06-11T04:26:21.000Z","size":46856,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T05:26:34.143Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","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/lebinary.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":"2024-08-28T14:08:37.000Z","updated_at":"2025-06-11T04:26:24.000Z","dependencies_parsed_at":"2025-05-20T18:37:14.943Z","dependency_job_id":null,"html_url":"https://github.com/lebinary/compiler","commit_stats":null,"previous_names":["lebinary/compiler"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lebinary/compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebinary%2Fcompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebinary%2Fcompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebinary%2Fcompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebinary%2Fcompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lebinary","download_url":"https://codeload.github.com/lebinary/compiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebinary%2Fcompiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29998092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T09:59:02.300Z","status":"ssl_error","status_checked_at":"2026-03-02T09:59:02.001Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-09T20:27:47.922Z","updated_at":"2026-03-02T10:03:45.039Z","avatar_url":"https://github.com/lebinary.png","language":"Java","readme":"# A Compiler\r\n\r\nA compiler that translates a Java-like language into SaM (a JVM simulator) for educational purposes.\r\n\r\n## Example\r\n\r\nHere's an example that calculates the seventh Fibonacci number:\r\n\r\n```java\r\nclass Main() {\r\n    int main(){\r\n        FiboCalculator fibo;\r\n        {\r\n            fibo = new FiboCalculator(7);\r\n            return fibo.calculate();\r\n        }\r\n    }\r\n}\r\n\r\nclass FiboCalculator(int a;){\r\n    void FiboCalculator(int val){\r\n        {\r\n            a = val;\r\n        }\r\n    }\r\n\r\n    int calculate(){\r\n        int b;\r\n        FiboCalculator x, y;\r\n        {\r\n            if((a=1)){\r\n                b = 1;\r\n            }\r\n            else{\r\n                if((a=2)){\r\n                    b = 1;\r\n                }\r\n                else{\r\n                    x = new FiboCalculator((a-1));\r\n                    y = new FiboCalculator((a-2));\r\n                    b = (x.calculate() + y.calculate());\r\n                }\r\n            }\r\n            return b;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nThe compiler translates the above code into assembly code that can be executed on the Stack Abstract Machine:\r\n\r\n![Speedup Example](speedup_example.gif)\r\n\r\n## Table of Contents\r\n- [Built With](#built-with)\r\n- [Features](#features)\r\n- [Getting Started](#getting-started)\r\n  - [Prerequisites](#prerequisites)\r\n  - [Installation](#installation)\r\n- [Development](#development)\r\n  - [Building Jar](#building-jar)\r\n  - [Running Tests](#running-tests)\r\n- [Usage](#usage)\r\n- [Implementation Details](#implementation-details)\r\n\r\n## Built With\r\n\r\n- Java\r\n- SaM Assembly\r\n\r\n## Features\r\n\r\n- Multi-pass compilation process\r\n- Comprehensive symbol table management\r\n- Type checking and error handling\r\n- Support for:\r\n  - Basic arithmetic and logical operations\r\n  - Control flow statements (if-else, while loops)\r\n  - Method declarations and invocations\r\n  - String operations and manipulation\r\n  - Object-oriented programming constructs (no inheritance yet)\r\n\r\n## Getting Started\r\n\r\n### Prerequisites\r\n\r\n- Java JDK 8 or higher\r\n- SaM Assembler and Runtime\r\n\r\n### Installation\r\n\r\n1. Clone the repository\r\n   ```sh\r\n   git clone https://github.com/lebinary/compiler.git\r\n   ```\r\n\r\n2. Enter Directory\r\n   ```sh\r\n   cd compiler\r\n   ```\r\n\r\n## Development\r\n\r\nThis starter code package includes a gradle build configuration and JUnit test cases to help you in completing the assignment.\r\nYou should follow the gradle installation instructions for your system at [https://gradle.org/install/](https://gradle.org/install/)\r\nand make sure you have Java version 11 or later installed as the build file targets Java 11.\r\n\r\n### Building Jar\r\n\r\nYou can build the JAR file with\r\n```sh\r\ngradle build\r\n```\r\nwhich will leave the jar file at `build/libs/compiler.jar`\r\n\r\nIf you have some tests failing and want to build a jar anyway, you can skip tests using\r\n```sh\r\ngradle build -x test\r\n```\r\n\r\nOn some platforms you may need to use the included `gradlew` or `gradlew.bat` scripts instead of calling `gradle` directly.\r\n\r\n### Running Tests\r\n\r\nAny IDE with gradle support can run the test cases, but they can also be run manually from the commandline by\r\n\r\n```sh\r\ngradle test\r\n```\r\n\r\n## Usage\r\n\r\n1. Prepare a source code file (e.g., `program.lo`)\r\n   Example source code:\r\n   ```java\r\n   int main() {\r\n       String message;\r\n       message = \"Hello, World!\";\r\n       return 0;\r\n   }\r\n   ```\r\n\r\n2. Build jar file of the compiler, a `compiler.jar` file should be created in `/build/libs`\r\n   ```sh\r\n   gradle build --rerun-tasks\r\n   ```\r\n\r\n3. Run the jar file to generate a SAM file\r\n   ```sh\r\n   java -jar compiler.jar program.lo output.sam\r\n   ```\r\n\r\n4. Start the Stack Abstract Machine simulator\r\n   ```sh\r\n   java -Dfile.encoding=UTF8 -jar SaM-2.6.3.jar\r\n   ```\r\n\r\n5. Load the generated SAM file `output.sam` and run the simulator!\r\n\r\n## Implementation Details\r\n\r\n### Compiler Structure\r\n\r\nThe compiler implements a two-pass compilation strategy:\r\n\r\n1. **First Pass**: Symbol Table Population\r\n   - Collects variable and method declarations\r\n   - Performs scope analysis\r\n   - Validates declarations and signatures\r\n\r\n2. **Second Pass**: Code Generation\r\n   - Generates SaM assembly code\r\n   - Performs type checking\r\n   - Manages memory allocation\r\n   - Handles control flow\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flebinary%2Fcompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flebinary%2Fcompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flebinary%2Fcompiler/lists"}