{"id":21100505,"url":"https://github.com/antonioalmeida/feup-comp","last_synced_at":"2025-07-27T07:34:39.420Z","repository":{"id":68249129,"uuid":"123570461","full_name":"antonioalmeida/feup-comp","owner":"antonioalmeida","description":"Repository to host Compilers' [COMP] project.","archived":false,"fork":false,"pushed_at":"2018-06-06T22:11:09.000Z","size":1037,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-20T08:47:57.331Z","etag":null,"topics":["comp","compilers","feup","javacc","jjtree","mieic"],"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/antonioalmeida.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":"2018-03-02T11:18:04.000Z","updated_at":"2018-06-30T14:54:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"26324bc4-a9fd-4e2d-bcf6-9611a39fd068","html_url":"https://github.com/antonioalmeida/feup-comp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/antonioalmeida/feup-comp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioalmeida%2Ffeup-comp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioalmeida%2Ffeup-comp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioalmeida%2Ffeup-comp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioalmeida%2Ffeup-comp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonioalmeida","download_url":"https://codeload.github.com/antonioalmeida/feup-comp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioalmeida%2Ffeup-comp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267324409,"owners_count":24069389,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"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":["comp","compilers","feup","javacc","jjtree","mieic"],"created_at":"2024-11-19T23:13:18.793Z","updated_at":"2025-07-27T07:34:39.414Z","avatar_url":"https://github.com/antonioalmeida.png","language":"Java","readme":"## yal (yet another language)\n\n### GROUP: G27\n\nAntónio Cunha Seco Fernandes de Almeida, up201505836, Grade: 20, Contribution: 25%\n\nFrancisco Tuna Andrade, up201503481, Grade: 20, Contribution: 25%\n  \nGil Dinis Magalhães Teixeira, up201505735, Grade: 20, Contribution: 25%\n\nTiago Alexandre de Sousa Dias da Silva, up201404689, Grade: 20, Contribution: 25%\n\nGLOBAL Grade of the project: 20\n\n### SUMMARY: \n\nAs a project for the Compilers course at Porto Engineering University, we implemented a compiler capable of generating Java bytecode, a low level language capable of operation the Java Virtual Machine from Yal, a high level programing language. The main features of our compiler are its ability to perform syntatic analysis, semantic analysis and generating low level code.\n\n### EXECUTE: \n\n#### Compiling:\nInside base directory\n```\n$ sh compile.sh\n```\n\n#### Running:\n\n##### Running Files Inside `src/testsuite`\nInside base directory\n```\n$ sh run.sh \u003cDIRECTORY NAME INSIDE TESTSUITE\u003e \u003cFILENAME - without extension\u003e [-r=INT] [-o]\n\n# Example\n$ sh run.sh code_generation testArithmetic\n```\n\n##### Running Other `yal` Files\nInside base directory\n```\n$ java -jar yal2jvm.jar \u003cinput_file.yal\u003e [-r=\u003cnum\u003e] [-o] \n\n# Example\n$ java -jar yal2jvm.jar test1.yal -r=3 -o\n```\n\n#### Running Chosen Examples (`src/examples` directory):\nInside base directory\n```\n$ sh example.sh \u003cFILENAME INSIDE EXAMPLES - without extension\u003e [-r=INT] [-o]\n\n# Example\n$ sh example.sh quicksort\n```\n\n#### DEALING WITH SYNTACTIC ERRORS: \n\nOur tool shows all the syntatic errors found, so that it does not exit after the first error. For example, if it founds an error in the assignement of a variable, the parser skips to the next semicolon and starts looking for syntatic errors from there. Our tool was able to report correctly all the errors in all files of the folder \"MyFirstYalExamples_1\" that can be found in the link \"yal Examples\" in the Moodle page of this course.\n\n \n\n#### SEMANTIC ANALYSIS: \n\nIn our compiler we implemented all the semantic rules mentioned in the project description and in the slides of this course. For example:\n- We check that if a variable is going to be assigned to another, they must have the same type (note: an array can be assigned to a scalar, in that case it means fill all the array with the value of the scalar)\n- We check that if a variable is going to be used in an expression it must have been initialized to type SCALAR\n- We check that the return value of a function should be initialized\n- We check that when a function is called there should be a function with the same signature (i.e. same name and same type of arguments)\n- We check that for the value returned by a function to be used in an expression, that return value should be a SCALAR \n- We check that a variable used in a function call as parameter has been initialized\n- We attributed scopes for whiles, ifs and elses so that a variable declared inside a scope is not valid outside\n- In the specific case that a variable is declared inside an if statement and in an else statement that follows with the same type, that variable becomes valid to be used outside those if and else scopes  \n\n\n \n\n#### INTERMEDIATE REPRESENTATIONS (IRs): \n\nAlthough we did not use IRs to generate the code, we used an IR to implement optimization -r. That IR consists of an array of instructions, that contains all the instructions of a given function. Each instruction contains its uses and defs and also the id's of instructions that are its antecessor and successor.\n\n \n\n#### CODE GENERATION:\n\nThe code generation uses the AST as the basis with support from the symbol tables, mostly for variable type checks. While going through it, it the generates the appropriate code. There are special cases, such as, limits generation which happens in the end, and integer assign to all array positions which has to generate code for a loop in order to fill all positions. We tried to make code generation as modular as possible which allowed us to not repeat code unless absolutely necessary. Besides covering the normal cases, it uses low cost instructions such as \"iinc\",\"iload\",\"istore\",\"astore\",\"aload\" and the various comparisons with 0. All the .yal examples from the \"MyFirstYalExamples\" run correctly, unless an error is supposed to occur, after the jasmin conversion to .class files. Same occurs for the \"Extra yal examples\" folder.\n\n \n\n#### OVERVIEW: \n\nOur project has a total of four packages: \"parser\" that contains the code generated by jjtree, \"semantic\" that contains the classes related to Symbols and Functions Table, \"codeGeneration\" that contains the classes related to the code generation and \"utils\" that contains functions used by all packages.\nOur compiler does not use any third-party tools. We implemented the optimization -r using the graph coloring algorithm studied in class.\n\n\n \n\n#### TESTSUITE AND TEST INFRASTRUCTURE: \n\nThe tool's testsuite provides automated tests through JUnit4 for most of the given examples, as well as our own tests. Each test's purpose is specified on its filename. \n\nHow to run (inside base directory)\n```\n$ sh compile.sh # compiles code and tests\n$ sh test.sh \u003cTest Class Name\u003e\n\n# Example - running code generation tests\n$ sh test.sh CodeGenerationTests\n```\n \n#### TASK DISTRIBUTION: \n\nAntónio Almeida - Syntatic Analysis, part of Semantic Analysis, part of Code Generation - base, ifs, variable indexing, stack state controller, Automated Testing and Execution\n\nFrancisco Andrade - Syntatic Analysis, Symbol and Functions Tables implementation, Semantic Analysis, Implementation of optimization -r\n\nGil Teixeira - AST generation; Base for code generation, Function, Arithmetic expressions, Loops and Arrays code generation; Optimizations related to the \"-o\" option.\n\nTiago Silva - AST generation; Base for code generation, Function, Arithmetic expressions, Loops and Arrays code generation; Optimizations related to low cost instructions.\n \n\n#### PROS:\n\nIn addition to the requested features, our tool features a few additional optimizations:\n  - Allows overload of functions with different argument types and different number of arguments\n  - Assigns variable to the minimum number of registers possible if option -r is set\n  - Performs constant propagation if option -o is set (uses while templates by default)\n  - Lower cost ifs in case of comparisons with 0 ('ifeq', 'ifge', 'ifgt', 'ifle','iflt', 'ifne')\n\n#### CONS: \n\n   - Does not allow the return variable of a function to be a global variable\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioalmeida%2Ffeup-comp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonioalmeida%2Ffeup-comp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioalmeida%2Ffeup-comp/lists"}