{"id":13620866,"url":"https://github.com/SineStriker/SJTU-2021-Compilers","last_synced_at":"2025-04-14T22:32:49.692Z","repository":{"id":152861469,"uuid":"449914033","full_name":"SineStriker/SJTU-2021-Compilers","owner":"SineStriker","description":"Reference of SJTU compilers labs","archived":false,"fork":false,"pushed_at":"2022-01-20T01:32:08.000Z","size":143,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-08T07:39:02.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SineStriker.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS"}},"created_at":"2022-01-20T01:31:22.000Z","updated_at":"2023-03-11T10:32:20.000Z","dependencies_parsed_at":"2024-01-14T08:14:03.902Z","dependency_job_id":"51c19996-241d-454a-8bb1-ec96b39112c8","html_url":"https://github.com/SineStriker/SJTU-2021-Compilers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SineStriker%2FSJTU-2021-Compilers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SineStriker%2FSJTU-2021-Compilers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SineStriker%2FSJTU-2021-Compilers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SineStriker%2FSJTU-2021-Compilers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SineStriker","download_url":"https://codeload.github.com/SineStriker/SJTU-2021-Compilers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248972359,"owners_count":21191778,"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":[],"created_at":"2024-08-01T21:01:00.161Z","updated_at":"2025-04-14T22:32:44.678Z","avatar_url":"https://github.com/SineStriker.png","language":"C++","funding_links":[],"categories":["课程列表"],"sub_categories":["Compiler"],"readme":"# Tiger Compiler Labs in C++\n\n## Contents\n\n- [Tiger Compiler Labs in C++](#tiger-compiler-labs-in-c)\n  - [Contents](#contents)\n  - [Overview](#overview)\n  - [Difference Between C Labs and C++ Labs](#difference-between-c-labs-and-c-labs)\n  - [Installing Dependencies](#installing-dependencies)\n  - [Compiling and Debugging](#compiling-and-debugging)\n  - [Testing Your Labs](#testing-your-labs)\n  - [Submitting Your Labs](#submitting-your-labs)\n  - [Formatting Your Codes](#formatting-your-codes)\n  - [Other Commands](#other-commands)\n  - [Contributing to Tiger Compiler](#contributing-to-tiger-compiler)\n  - [External Documentations](#external-documentations)\n\n## Overview\n\nWe rewrote the Tiger Compiler labs using the C++ programming language because some features in C++ like inheritance and polymorphism\nare more suitable for these labs and less error-prone.\n\nWe provide you all the codes of all labs at one time. In each lab, you only\nneed to code in some of the directories.\n\n## Difference Between C Labs and C++ Labs\n\n1. Tiger compiler in C++ uses [flexc++](https://fbb-git.gitlab.io/flexcpp/manual/flexc++.html) and [bisonc++](https://fbb-git.gitlab.io/bisoncpp/manual/bisonc++.html) instead of flex and bison because flexc++ and bisonc++ is more flexc++ and bisonc++ are able to generate pure C++ codes instead of C codes wrapped in C++ files.\n\n2. Tiger compiler in C++ uses namespace for modularization and uses inheritance and polymorphism to replace unions used in the old labs.\n\n3. Tiger compiler in C++ uses CMake instead of Makefile to compile and build the target.\n\n\u003c!---4. We've introduced lots of modern C++-style codes into tiger compiler, e.g., smart pointers, RAII, RTTI. To get familiar with the features of modern C++ and get recommendations for writing code in modern C++ style, please refer to [this doc](https://ipads.se.sjtu.edu.cn/courses/compilers/tiger-compiler-cpp-style.html) on our course website.--\u003e\n\n## Installing Dependencies\n\nWe provide you a Docker image that has already installed all the dependencies. You can compile your codes directly in this Docker image.\n\n1. Install [Docker](https://docs.docker.com/).\n\n2. Run a docker container and mount the lab directory on it.\n\n```bash\n# Run this command in the root directory of the project\ndocker run -it --privileged -p 2222:22 -v $(pwd):/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest  # or make docker-run\n```\n\n## Compiling and Debugging\n\nThere are five makeable targets in total, including `test_slp`, `test_lex`, `test_parse`, `test_semant`,  and `tiger-compiler`.\n\n1. Run container environment and attach to it\n\n```bash\n# Run container and directly attach to it\ndocker run -it --privileged -p 2222:22 \\\n    -v $(pwd):/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest  # or `make docker-run`\n# Or run container in the backend and attach to it later\ndocker run -dt --privileged -p 2222:22 \\\n    -v $(pwd):/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest\ndocker attach ${YOUR_CONTAINER_ID}\n```\n\n2. Build in the container environment\n\n```bash\nmkdir build \u0026\u0026 cd build \u0026\u0026 cmake .. \u0026\u0026 make test_xxx  # or `make build`\n```\n\n3. Debug using gdb or any IDEs\n\n```bash\ngdb test_xxx # e.g. `gdb test_slp`\n```\n\n**Note: we will use `-DCMAKE_BUILD_TYPE=Release` to grade your labs, so make\nsure your lab passed the released version**\n\n## Testing Your Labs\n\nUse `make`\n```bash\nmake gradelabx\n```\nor run the script manually\n```bash\n./scripts/grade.sh [lab1|lab2|lab3|lab4|lab5|lab6|all] # e.g. `./scripts/grade.sh lab1`\n```\n\nYou can test all the labs by\n```bash\nmake gradeall\n```\n\n## Submitting Your Labs\n\n**Run `make register` and input your name in English and student ID.** You can\ncheck it in the `.info` file generated later.\n\nWe are using CI in GitLab to grade your labs automatically. **So please make\nsure the `Enable shared runners for this project`\nunder `Your GitLab repo - Settings - CI/CD` is turned on**.\n\nPush your code to your GitLab repo\n```bash\ngit add somefiles\ngit commit -m \"A message\"\ngit push\n```\n\n**Wait for a while and check the latest pipeline (`Your GitLab repo - CI/CD -\nPipelines`) passed. Otherwise, you won't get a full score in your lab.**\n\n## Formatting Your Codes\n\nWe provide an LLVM-style .clang-format file in the project directory. You can use it to format your code.\n\nUse `clang-format` command\n```\nfind . \\( -name \"*.h\" -o -iname \"*.cc\" \\) | xargs clang-format -i -style=file  # or make format\n```\n\nor config the clang-format file in your IDE and use the built-in format feature in it.\n\n## Other Commands\n\nUtility commands can be found in the `Makefile`. They can be directly run by `make xxx` in a Unix shell. Windows users cannot use the `make` command, but the contents of `Makefile` can still be used as a reference for the available commands.\n\n## Contributing to Tiger Compiler\n\nYou can post questions, issues, feedback, or even MR proposals through [our main GitLab repository](https://ipads.se.sjtu.edu.cn:2020/compilers-2021/compilers-2021/issues). We are rapidly refactoring the original C tiger compiler implementation into modern C++ style, so any suggestion to make this lab better is welcomed.\n\n## External Documentations\n\nYou can read external documentations on our course website:\n\n- [Lab Assignments](https://ipads.se.sjtu.edu.cn/courses/compilers/labs.shtml)\n- [Environment Configuration of Tiger Compiler Labs](https://ipads.se.sjtu.edu.cn/courses/compilers/tiger-compiler-environment.html)\n\u003c!---- [Tiger Compiler in Modern C++ Style](https://ipads.se.sjtu.edu.cn/courses/compilers/tiger-compiler-cpp-style.html)--\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSineStriker%2FSJTU-2021-Compilers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSineStriker%2FSJTU-2021-Compilers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSineStriker%2FSJTU-2021-Compilers/lists"}