├── .clang-format ├── .gitignore ├── .gitlab-ci.yml ├── .info ├── AUTHORS ├── CMakeLists.txt ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── README ├── .DS_Store ├── 2018-2-4.png ├── 2018-3-1-1.png ├── 2018-3-1-2-1.png ├── 2018-3-1-2.png ├── 2018-3-1.png ├── 2018-4-1.png ├── 2018-4-2.png ├── 2018-4-3.png ├── 2018-4-4-1.png ├── 2018-4-4-2.png ├── 2018-4-4-3.png ├── 2018-4-4.png ├── 2019-1-1.png └── 2019-1-2.png ├── VERSION ├── changelog.md ├── scripts ├── grade.sh ├── lab5_test │ ├── client.py │ ├── debugger.py │ ├── instruction.py │ ├── interpreter.py │ ├── main.py │ ├── state_table.py │ └── type.py └── register.py ├── src ├── .DS_Store ├── straightline │ ├── prog1.cc │ ├── prog1.h │ ├── slp.cc │ ├── slp.h │ └── test_slp.cc └── tiger │ ├── .DS_Store │ ├── absyn │ ├── absyn.cc │ └── absyn.h │ ├── canon │ ├── canon.cc │ └── canon.h │ ├── codegen │ ├── assem.cc │ ├── assem.h │ ├── codegen.cc │ └── codegen.h │ ├── env │ ├── env.cc │ └── env.h │ ├── errormsg │ ├── errormsg.cc │ └── errormsg.h │ ├── escape │ ├── escape.cc │ └── escape.h │ ├── frame │ ├── frame.h │ ├── temp.cc │ ├── temp.h │ ├── x64frame.cc │ └── x64frame.h │ ├── lex │ ├── scanner.h │ ├── scanner.ih │ └── tiger.lex │ ├── liveness │ ├── flowgraph.cc │ ├── flowgraph.h │ ├── liveness.cc │ └── liveness.h │ ├── main │ ├── main.cc │ ├── test_codegen.cc │ ├── test_lex.cc │ ├── test_parse.cc │ ├── test_semant.cc │ └── test_translate.cc │ ├── output │ ├── logger.h │ ├── output.cc │ └── output.h │ ├── parse │ ├── parser.h │ ├── parser.ih │ └── tiger.y │ ├── regalloc │ ├── color.cc │ ├── color.h │ ├── regalloc.cc │ └── regalloc.h │ ├── runtime │ └── runtime.c │ ├── semant │ ├── semant.cc │ ├── semant.h │ ├── types.cc │ └── types.h │ ├── symbol │ ├── symbol.cc │ └── symbol.h │ ├── translate │ ├── translate.cc │ ├── translate.h │ ├── tree.cc │ └── tree.h │ └── util │ ├── graph.h │ └── table.h ├── testdata ├── .DS_Store ├── backup │ ├── refs │ │ ├── test1.out │ │ ├── test12.out │ │ ├── test2.out │ │ ├── test27.out │ │ ├── test3.out │ │ ├── test30.out │ │ ├── test37.out │ │ ├── test4.out │ │ ├── test41.out │ │ ├── test42.out │ │ ├── test44.out │ │ ├── test46.out │ │ ├── test47.out │ │ ├── test48.out │ │ ├── test5.out │ │ ├── test6.out │ │ ├── test7.out │ │ └── test8.out │ └── testcases │ │ ├── test.tig │ │ ├── test1.tig │ │ ├── test12.tig │ │ ├── test2.tig │ │ ├── test27.tig │ │ ├── test3.tig │ │ ├── test30.tig │ │ ├── test37.tig │ │ ├── test4.tig │ │ ├── test41.tig │ │ ├── test42.tig │ │ ├── test44.tig │ │ ├── test46.tig │ │ ├── test47.tig │ │ ├── test48.tig │ │ ├── test5.tig │ │ ├── test6.tig │ │ ├── test7.tig │ │ ├── test8.tig │ │ ├── test_array.tig │ │ ├── test_extern.tig │ │ └── test_patch.tig ├── lab1 │ ├── refs │ │ ├── ref-0.txt │ │ └── ref-1.txt │ └── testcases │ │ └── .gitkeep ├── lab2 │ ├── refs │ │ ├── merge.out │ │ ├── queens.out │ │ ├── test1.out │ │ ├── test10.out │ │ ├── test11.out │ │ ├── test12.out │ │ ├── test13.out │ │ ├── test14.out │ │ ├── test15.out │ │ ├── test16.out │ │ ├── test17.out │ │ ├── test18.out │ │ ├── test19.out │ │ ├── test2.out │ │ ├── test20.out │ │ ├── test21.out │ │ ├── test22.out │ │ ├── test23.out │ │ ├── test24.out │ │ ├── test25.out │ │ ├── test26.out │ │ ├── test27.out │ │ ├── test28.out │ │ ├── test29.out │ │ ├── test3.out │ │ ├── test30.out │ │ ├── test31.out │ │ ├── test32.out │ │ ├── test33.out │ │ ├── test34.out │ │ ├── test35.out │ │ ├── test36.out │ │ ├── test37.out │ │ ├── test38.out │ │ ├── test39.out │ │ ├── test4.out │ │ ├── test40.out │ │ ├── test41.out │ │ ├── test42.out │ │ ├── test43.out │ │ ├── test44.out │ │ ├── test45.out │ │ ├── test46.out │ │ ├── test47.out │ │ ├── test48.out │ │ ├── test49.out │ │ ├── test5.out │ │ ├── test50.out │ │ ├── test51.out │ │ ├── test52.out │ │ ├── test6.out │ │ ├── test7.out │ │ ├── test8.out │ │ └── test9.out │ └── testcases │ │ ├── merge.tig │ │ ├── queens.tig │ │ ├── test1.tig │ │ ├── test10.tig │ │ ├── test11.tig │ │ ├── test12.tig │ │ ├── test13.tig │ │ ├── test14.tig │ │ ├── test15.tig │ │ ├── test16.tig │ │ ├── test17.tig │ │ ├── test18.tig │ │ ├── test19.tig │ │ ├── test2.tig │ │ ├── test20.tig │ │ ├── test21.tig │ │ ├── test22.tig │ │ ├── test23.tig │ │ ├── test24.tig │ │ ├── test25.tig │ │ ├── test26.tig │ │ ├── test27.tig │ │ ├── test28.tig │ │ ├── test29.tig │ │ ├── test3.tig │ │ ├── test30.tig │ │ ├── test31.tig │ │ ├── test32.tig │ │ ├── test33.tig │ │ ├── test34.tig │ │ ├── test35.tig │ │ ├── test36.tig │ │ ├── test37.tig │ │ ├── test38.tig │ │ ├── test39.tig │ │ ├── test4.tig │ │ ├── test40.tig │ │ ├── test41.tig │ │ ├── test42.tig │ │ ├── test43.tig │ │ ├── test44.tig │ │ ├── test45.tig │ │ ├── test46.tig │ │ ├── test47.tig │ │ ├── test48.tig │ │ ├── test49.tig │ │ ├── test5.tig │ │ ├── test50.tig │ │ ├── test51.tig │ │ ├── test52.tig │ │ ├── test6.tig │ │ ├── test7.tig │ │ ├── test8.tig │ │ └── test9.tig ├── lab3 │ ├── refs │ │ ├── merge.out │ │ ├── queens.out │ │ ├── test1.out │ │ ├── test10.out │ │ ├── test11.out │ │ ├── test12.out │ │ ├── test13.out │ │ ├── test14.out │ │ ├── test15.out │ │ ├── test16.out │ │ ├── test17.out │ │ ├── test18.out │ │ ├── test19.out │ │ ├── test2.out │ │ ├── test20.out │ │ ├── test21.out │ │ ├── test22.out │ │ ├── test23.out │ │ ├── test24.out │ │ ├── test25.out │ │ ├── test26.out │ │ ├── test27.out │ │ ├── test28.out │ │ ├── test29.out │ │ ├── test3.out │ │ ├── test30.out │ │ ├── test31.out │ │ ├── test32.out │ │ ├── test33.out │ │ ├── test34.out │ │ ├── test35.out │ │ ├── test36.out │ │ ├── test37.out │ │ ├── test38.out │ │ ├── test39.out │ │ ├── test4.out │ │ ├── test40.out │ │ ├── test41.out │ │ ├── test42.out │ │ ├── test43.out │ │ ├── test44.out │ │ ├── test45.out │ │ ├── test46.out │ │ ├── test47.out │ │ ├── test48.out │ │ ├── test49.out │ │ ├── test5.out │ │ ├── test6.out │ │ ├── test7.out │ │ ├── test8.out │ │ └── test9.out │ └── testcases │ │ ├── merge.tig │ │ ├── queens.tig │ │ ├── test1.tig │ │ ├── test10.tig │ │ ├── test11.tig │ │ ├── test12.tig │ │ ├── test13.tig │ │ ├── test14.tig │ │ ├── test15.tig │ │ ├── test16.tig │ │ ├── test17.tig │ │ ├── test18.tig │ │ ├── test19.tig │ │ ├── test2.tig │ │ ├── test20.tig │ │ ├── test21.tig │ │ ├── test22.tig │ │ ├── test23.tig │ │ ├── test24.tig │ │ ├── test25.tig │ │ ├── test26.tig │ │ ├── test27.tig │ │ ├── test28.tig │ │ ├── test29.tig │ │ ├── test3.tig │ │ ├── test30.tig │ │ ├── test31.tig │ │ ├── test32.tig │ │ ├── test33.tig │ │ ├── test34.tig │ │ ├── test35.tig │ │ ├── test36.tig │ │ ├── test37.tig │ │ ├── test38.tig │ │ ├── test39.tig │ │ ├── test4.tig │ │ ├── test40.tig │ │ ├── test41.tig │ │ ├── test42.tig │ │ ├── test43.tig │ │ ├── test44.tig │ │ ├── test45.tig │ │ ├── test46.tig │ │ ├── test47.tig │ │ ├── test48.tig │ │ ├── test49.tig │ │ ├── test5.tig │ │ ├── test6.tig │ │ ├── test7.tig │ │ ├── test8.tig │ │ └── test9.tig ├── lab4 │ ├── refs │ │ ├── merge.out │ │ ├── queens.out │ │ ├── test1.out │ │ ├── test10.out │ │ ├── test11.out │ │ ├── test12.out │ │ ├── test13.out │ │ ├── test14.out │ │ ├── test15.out │ │ ├── test16.out │ │ ├── test17.out │ │ ├── test18.out │ │ ├── test19.out │ │ ├── test2.out │ │ ├── test20.out │ │ ├── test21.out │ │ ├── test22.out │ │ ├── test23.out │ │ ├── test24.out │ │ ├── test25.out │ │ ├── test26.out │ │ ├── test27.out │ │ ├── test28.out │ │ ├── test29.out │ │ ├── test3.out │ │ ├── test30.out │ │ ├── test31.out │ │ ├── test32.out │ │ ├── test33.out │ │ ├── test34.out │ │ ├── test35.out │ │ ├── test36.out │ │ ├── test37.out │ │ ├── test38.out │ │ ├── test39.out │ │ ├── test4.out │ │ ├── test40.out │ │ ├── test41.out │ │ ├── test42.out │ │ ├── test43.out │ │ ├── test44.out │ │ ├── test45.out │ │ ├── test46.out │ │ ├── test47.out │ │ ├── test48.out │ │ ├── test49.out │ │ ├── test5.out │ │ ├── test50.out │ │ ├── test6.out │ │ ├── test7.out │ │ ├── test8.out │ │ └── test9.out │ └── testcases │ │ ├── merge.tig │ │ ├── queens.tig │ │ ├── test1.tig │ │ ├── test10.tig │ │ ├── test11.tig │ │ ├── test12.tig │ │ ├── test13.tig │ │ ├── test14.tig │ │ ├── test15.tig │ │ ├── test16.tig │ │ ├── test17.tig │ │ ├── test18.tig │ │ ├── test19.tig │ │ ├── test2.tig │ │ ├── test20.tig │ │ ├── test21.tig │ │ ├── test22.tig │ │ ├── test23.tig │ │ ├── test24.tig │ │ ├── test25.tig │ │ ├── test26.tig │ │ ├── test27.tig │ │ ├── test28.tig │ │ ├── test29.tig │ │ ├── test3.tig │ │ ├── test30.tig │ │ ├── test31.tig │ │ ├── test32.tig │ │ ├── test33.tig │ │ ├── test34.tig │ │ ├── test35.tig │ │ ├── test36.tig │ │ ├── test37.tig │ │ ├── test38.tig │ │ ├── test39.tig │ │ ├── test4.tig │ │ ├── test40.tig │ │ ├── test41.tig │ │ ├── test42.tig │ │ ├── test43.tig │ │ ├── test44.tig │ │ ├── test45.tig │ │ ├── test46.tig │ │ ├── test47.tig │ │ ├── test48.tig │ │ ├── test49.tig │ │ ├── test5.tig │ │ ├── test50.tig │ │ ├── test6.tig │ │ ├── test7.tig │ │ ├── test8.tig │ │ └── test9.tig └── lab5or6 │ ├── .DS_Store │ ├── refs-part1 │ ├── bsearch.out │ ├── dec2bin.out │ ├── merge.out │ ├── prime.out │ ├── qsort.out │ ├── queens.out │ ├── tbi.out │ ├── test_array.out │ ├── test_patch.out │ ├── tfact.out │ ├── tfo.out │ ├── tif.out │ ├── tifn.out │ ├── tlink.out │ ├── trec.out │ ├── tree.out │ └── twhi.out │ ├── refs │ ├── bsearch.out │ ├── dec2bin.out │ ├── merge │ │ ├── test1.out │ │ ├── test2.out │ │ ├── test3.out │ │ └── test4.out │ ├── prime.out │ ├── qsort.out │ ├── queens.out │ ├── tbi.out │ ├── test_array.out │ ├── test_patch.out │ ├── tfact.out │ ├── tfo.out │ ├── tif.out │ ├── tifn.out │ ├── tlink.out │ ├── trec.out │ ├── tree.out │ └── twhi.out │ └── testcases │ ├── bsearch.tig │ ├── dec2bin.tig │ ├── merge.tig │ ├── merge │ ├── test1.in │ ├── test2.in │ ├── test3.in │ └── test4.in │ ├── prime.tig │ ├── qsort.tig │ ├── queens.tig │ ├── tbi.tig │ ├── test_array.tig │ ├── test_patch.tig │ ├── tfact.tig │ ├── tfo.tig │ ├── tif.tig │ ├── tifn.tig │ ├── tlink.tig │ ├── trec.tig │ ├── tree.tig │ └── twhi.tig └── 期末整理 ├── .DS_Store ├── 垃圾收集算法——分代收集算法(Generational Collection)。_孤芳不自赏-CSDN博客_分代收集算法.pdf ├── 垃圾收集算法——复制算法(Copying)。_孤芳不自赏-CSDN博客_复制算法.pdf ├── 增量式垃圾回收_一蓑烟雨的专栏-CSDN博客.pdf ├── 引用计数_百度百科.pdf ├── 期末题型整理compiler.pdf ├── 深入了解标记-清扫回收算法_一只海滩上的贝壳-CSDN博客.pdf └── 编译原理期末整理.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | # Thumbnails 10 | ._* 11 | 12 | # Files that might appear in the root of a volume 13 | .DocumentRevisions-V100 14 | .fseventsd 15 | .Spotlight-V100 16 | .TemporaryItems 17 | .Trashes 18 | .VolumeIcon.icns 19 | .com.apple.timemachine.donotpresent 20 | 21 | # Directories potentially created on remote AFP share 22 | .AppleDB 23 | .AppleDesktop 24 | Network Trash Folder 25 | Temporary Items 26 | .apdisk 27 | 28 | # flexc++ and bisonc++ generated files 29 | lex.cc 30 | scannerbase.h 31 | parserbase.h 32 | parse.cc 33 | *.tig.s 34 | 35 | # tar files 36 | *.tar.gz 37 | 38 | # CMake build directories 39 | build/ 40 | cmake-build-debug/ 41 | 42 | # CMake 43 | CMakeLists.txt.user 44 | CMakeCache.txt 45 | CMakeFiles 46 | CMakeScripts 47 | Testing 48 | cmake_install.cmake 49 | install_manifest.txt 50 | compile_commands.json 51 | CTestTestfile.cmake 52 | _deps 53 | 54 | # vscode 55 | .vscode 56 | 57 | # idea 58 | .idea 59 | 60 | *.log 61 | 62 | # python cache 63 | *.pyc 64 | -------------------------------------------------------------------------------- /.info: -------------------------------------------------------------------------------- 1 | STUDENT_NAME=huidongxu 2 | STUDENT_ID=519021910861 -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Contributors 2 | ---------- 3 | Zulai Wang 4 | Zhe Li <18064638846@163.com> 5 | Jianbang Yang 6 | Zihang Yao 7 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | # Use aliyun registry 4 | RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list 5 | RUN apt clean 6 | RUN apt update && apt install -y sudo git cmake g++ gcc vim tar gdb flexc++ bisonc++ openssh-server rsync python3.8 python3-pip dos2unix clang-format-10 7 | RUN useradd -ms /bin/bash -G sudo stu 8 | RUN passwd -d stu 9 | RUN ln -sf /usr/bin/clang-format-10 /usr/bin/clang-format 10 | 11 | USER stu 12 | WORKDIR /home/stu 13 | CMD sudo service ssh restart && sudo usermod --password $(echo 123 | openssl passwd -1 -stdin) stu && /bin/bash 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, Zulai Wang 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: docker-build docker-pull docker-run docker-run-backend transform build gradelab1 gradelab2 gradelab3 gradelab4 gradelab5 gradelab6 gradeall clean register format 2 | 3 | docker-build: 4 | docker build -t ipadsse302/tigerlabs_env . 5 | 6 | docker-pull: 7 | docker pull ipadsse302/tigerlabs_env:latest 8 | 9 | docker-run: 10 | docker run -it --privileged -p 2222:22 \ 11 | -v /home/parallels/Desktop/compilers-2021:/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest 12 | 13 | docker-run-backend: 14 | docker run -dt --privileged -p 2222:22 \ 15 | -v /home/parallels/Desktop/compilers-2021:/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest 16 | 17 | transform: 18 | find src scripts testdata -type f | xargs -I % sh -c 'dos2unix -n % /tmp/tmp; mv -f /tmp/tmp % || true;' 19 | 20 | build:transform 21 | mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make 22 | 23 | build-debug:transform 24 | mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && make 25 | 26 | gradelab1:transform 27 | bash scripts/grade.sh lab1 28 | 29 | gradelab2:transform 30 | bash scripts/grade.sh lab2 31 | 32 | gradelab3:transform 33 | bash scripts/grade.sh lab3 34 | 35 | gradelab4:transform 36 | bash scripts/grade.sh lab4 37 | 38 | gradelab5-1:transform 39 | bash scripts/grade.sh lab5-part1 40 | 41 | gradelab5:transform 42 | bash scripts/grade.sh lab5 43 | 44 | gradelab6:transform 45 | bash scripts/grade.sh lab6 46 | 47 | gradeall:transform 48 | bash scripts/grade.sh all 49 | 50 | clean: 51 | rm -rf build/ src/tiger/lex/scannerbase.h src/tiger/lex/lex.cc \ 52 | src/tiger/parse/parserbase.h src/tiger/parse/parse.cc 53 | 54 | register: 55 | python3 scripts/register.py 56 | 57 | format: 58 | find . \( -name "*.h" -o -iname "*.cc" \) | xargs clang-format -i -style=file 59 | 60 | -------------------------------------------------------------------------------- /README/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/.DS_Store -------------------------------------------------------------------------------- /README/2018-2-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-2-4.png -------------------------------------------------------------------------------- /README/2018-3-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-3-1-1.png -------------------------------------------------------------------------------- /README/2018-3-1-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-3-1-2-1.png -------------------------------------------------------------------------------- /README/2018-3-1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-3-1-2.png -------------------------------------------------------------------------------- /README/2018-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-3-1.png -------------------------------------------------------------------------------- /README/2018-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-1.png -------------------------------------------------------------------------------- /README/2018-4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-2.png -------------------------------------------------------------------------------- /README/2018-4-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-3.png -------------------------------------------------------------------------------- /README/2018-4-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-4-1.png -------------------------------------------------------------------------------- /README/2018-4-4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-4-2.png -------------------------------------------------------------------------------- /README/2018-4-4-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-4-3.png -------------------------------------------------------------------------------- /README/2018-4-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2018-4-4.png -------------------------------------------------------------------------------- /README/2019-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2019-1-1.png -------------------------------------------------------------------------------- /README/2019-1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/README/2019-1-2.png -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.1.0 2 | 3 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Change Logs 2 | 3 | ## tiger-compiler-2021-fall(1.1.0) 4 | 5 | - Refactor into modern C++ style. 6 | - Use RAII to manage the lifetimes and GC of objects. 7 | - Replace lisp-style lists with the STL lists. 8 | - Release the lab environment on DockerHub. 9 | 10 | ## tiger-compiler-2019-fall(1.0.3) 11 | 12 | - Complement missing function in canon. 13 | - Fix compile-errors in main.cc. 14 | 15 | ## tiger-compiler-2019-fall(1.0.2) 16 | 17 | - Delete deprecated grade scripts. 18 | 19 | 20 | ## tiger-compiler-2019-fall(1.0.1) 21 | 22 | - Modify test scripts to prompt zero scores if the testcases and refs folders can't be appropriately linked. 23 | 24 | - Add change logs file. 25 | 26 | ## tiger-compiler-2019-fall(1.0.0) 27 | 28 | - The first published version. 29 | -------------------------------------------------------------------------------- /scripts/lab5_test/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from client import Client 3 | from interpreter import Interpreter 4 | 5 | class TigerInterpreter(object): 6 | 7 | def main(): 8 | if len(sys.argv) < 2: 9 | print("Usage:main.py ") 10 | elif sys.argv[1] == '-d': 11 | file = sys.argv[2] 12 | client = Client(file) 13 | client.cmdloop() 14 | else: 15 | file = sys.argv[1] 16 | interpreter = Interpreter(file) 17 | interpreter.run() 18 | 19 | 20 | if __name__ == "__main__": 21 | main() -------------------------------------------------------------------------------- /scripts/lab5_test/type.py: -------------------------------------------------------------------------------- 1 | from enum import Enum,unique 2 | @unique 3 | class InstructionEnum(Enum): 4 | Mov = '^mov.+$' 5 | Add = '^add.+$' 6 | Sub = '^sub.+$' 7 | Imul = '^imul.+$' 8 | Idiv = '^idiv.+$' 9 | Lea = '^lea.+$' 10 | Call = '^call.+$' 11 | Cmp = '^cmp.+$' 12 | Jmp = '^j[(mp)|(e)|(ne)|(g)|(ge)|(l)|(le)].+$' 13 | Ret = '^retq$' 14 | 15 | @unique 16 | class OperandEnum(Enum): 17 | Reg = '^(\%r.{1,2})|(t\d{3})$' 18 | Imm = '^\$.+$' 19 | 20 | @unique 21 | class JumpEnum(Enum): 22 | Ge = 'jge' 23 | G = 'jg' 24 | Le = 'jle' 25 | L = 'jl' 26 | E = 'je' 27 | Ne = 'jne' 28 | Jmp = 'jmp' 29 | -------------------------------------------------------------------------------- /scripts/register.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | name = input("Please enter your name: ") 4 | sid = input("Please enter your student ID: ") 5 | 6 | with open('.info', 'w') as f: 7 | f.write(f"STUDENT_NAME={name}\nSTUDENT_ID={sid}") 8 | -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/src/.DS_Store -------------------------------------------------------------------------------- /src/straightline/prog1.h: -------------------------------------------------------------------------------- 1 | #ifndef STRAIGHTLINE_PROG1_H_ 2 | #define STRAIGHTLINE_PROG1_H_ 3 | 4 | #include "straightline/slp.h" 5 | 6 | A::Stm *Prog(); 7 | A::Stm *ProgProg(); 8 | A::Stm *RightProg(); 9 | 10 | #endif // STRAIGHTLINE_PROG1_H_ 11 | -------------------------------------------------------------------------------- /src/straightline/test_slp.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "straightline/prog1.h" 6 | 7 | int main(int argc, char **argv) { 8 | int args; 9 | int test_num; 10 | 11 | assert(argc == 2); 12 | test_num = atoi(argv[1]); 13 | 14 | switch (test_num) { 15 | case 0: 16 | printf("Prog\n"); 17 | args = Prog()->MaxArgs(); 18 | printf("args: %d\n", args); 19 | Prog()->Interp(nullptr); 20 | 21 | printf("ProgProg\n"); 22 | args = ProgProg()->MaxArgs(); 23 | printf("args: %d\n", args); 24 | ProgProg()->Interp(nullptr); 25 | break; 26 | case 1: 27 | printf("ProgProg\n"); 28 | args = ProgProg()->MaxArgs(); 29 | printf("args: %d\n", args); 30 | ProgProg()->Interp(nullptr); 31 | 32 | printf("Prog\n"); 33 | args = Prog()->MaxArgs(); 34 | printf("args: %d\n", args); 35 | Prog()->Interp(nullptr); 36 | break; 37 | default: 38 | printf("unexpected case\n"); 39 | exit(-1); 40 | } 41 | printf("RightProg\n"); 42 | args = RightProg()->MaxArgs(); 43 | printf("args: %d\n", args); 44 | RightProg()->Interp(nullptr); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/tiger/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/src/tiger/.DS_Store -------------------------------------------------------------------------------- /src/tiger/codegen/codegen.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_CODEGEN_CODEGEN_H_ 2 | #define TIGER_CODEGEN_CODEGEN_H_ 3 | 4 | #include "tiger/canon/canon.h" 5 | #include "tiger/codegen/assem.h" 6 | #include "tiger/frame/x64frame.h" 7 | #include "tiger/translate/tree.h" 8 | 9 | // Forward Declarations 10 | namespace frame { 11 | class RegManager; 12 | class Frame; 13 | } // namespace frame 14 | 15 | namespace assem { 16 | class Instr; 17 | class InstrList; 18 | } // namespace assem 19 | 20 | namespace canon { 21 | class Traces; 22 | } // namespace canon 23 | 24 | namespace cg { 25 | 26 | class AssemInstr { 27 | public: 28 | AssemInstr() = delete; 29 | AssemInstr(nullptr_t) = delete; 30 | explicit AssemInstr(assem::InstrList *instr_list) : instr_list_(instr_list) {} 31 | 32 | void Print(FILE *out, temp::Map *map) const; 33 | 34 | [[nodiscard]] assem::InstrList *GetInstrList() const { return instr_list_; } 35 | 36 | private: 37 | assem::InstrList *instr_list_; 38 | }; 39 | 40 | class CodeGen { 41 | public: 42 | CodeGen(frame::Frame *frame, std::unique_ptr traces) 43 | : frame_(frame), traces_(std::move(traces)) {} 44 | 45 | void Codegen(); 46 | std::unique_ptr TransferAssemInstr() { 47 | return std::move(assem_instr_); 48 | } 49 | 50 | void PushReg(assem::InstrList &instr_list, temp::Temp *pos, temp::Temp *to_be_push); 51 | void PopReg(assem::InstrList &instr_list, temp::Temp *pos, temp::Temp *to_be_pop); 52 | 53 | void SaveCalleeRegs(assem::InstrList &instr_list, std::string_view fs); 54 | void RestoreCalleeRegs(assem::InstrList &instr_list, std::string_view fs); 55 | 56 | private: 57 | frame::Frame *frame_; 58 | std::string fs_; // Frame size label_ 59 | std::unique_ptr traces_; 60 | std::unique_ptr assem_instr_; 61 | 62 | std::vector tmp_store; 63 | }; 64 | 65 | } // namespace cg 66 | #endif 67 | -------------------------------------------------------------------------------- /src/tiger/errormsg/errormsg.cc: -------------------------------------------------------------------------------- 1 | #include "tiger/errormsg/errormsg.h" 2 | 3 | #include 4 | #include 5 | 6 | namespace err { 7 | 8 | void ErrorMsg::Newline() { 9 | line_num_++; 10 | line_pos_.push_front(tok_pos_); 11 | } 12 | 13 | void ErrorMsg::Error(int pos, std::string_view message, ...) { 14 | va_list ap; 15 | int num = line_num_; 16 | int val = -1; 17 | 18 | // Backtrace to the error line number 19 | any_errors_ = true; 20 | for (auto i : line_pos_) { 21 | val = i; 22 | if (i < pos) 23 | break; 24 | num--; 25 | } 26 | 27 | // Output error message 28 | if (!file_name_.empty()) 29 | fprintf(stderr, "%s:", file_name_.data()); 30 | if (val != -1) 31 | fprintf(stderr, "%d.%d: ", num, pos - val); 32 | va_start(ap, message); 33 | vfprintf(stderr, message.data(), ap); 34 | va_end(ap); 35 | fprintf(stderr, "\n"); 36 | } 37 | 38 | } // namespace err 39 | -------------------------------------------------------------------------------- /src/tiger/errormsg/errormsg.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_ERRORMSG_ERROMSG_H_ 2 | #define TIGER_ERRORMSG_ERROMSG_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** 9 | * Forward Declarations 10 | */ 11 | class Scanner; 12 | 13 | namespace err { 14 | class ErrorMsg { 15 | friend class ::Scanner; 16 | 17 | public: 18 | ErrorMsg() = delete; 19 | explicit ErrorMsg(std::string_view fname) 20 | : line_pos_(std::list{0}), file_name_(fname), infile_(fname.data()) { 21 | if (!infile_.good()) 22 | throw std::invalid_argument("cannot open file"); 23 | } 24 | 25 | /** 26 | * Add a new line in parser 27 | */ 28 | void Newline(); 29 | 30 | /** 31 | * Output an error 32 | * @param pos current position 33 | * @param message error message 34 | */ 35 | void Error(int pos, std::string_view message, ...); 36 | 37 | /** 38 | * Getter for `tok_pos_` 39 | */ 40 | [[nodiscard]] int GetTokPos() const { return tok_pos_; } 41 | 42 | /** 43 | * Getter for `any_errors` 44 | */ 45 | [[nodiscard]] bool AnyErrors() const { return any_errors_; } 46 | 47 | private: 48 | int tok_pos_ = 1; // current token position 49 | bool any_errors_ = false; // flag indicating if any error occurrs 50 | int line_num_ = 1; // current line number 51 | std::list line_pos_; // current token position of a line 52 | std::string file_name_; // name of input file 53 | std::ifstream infile_; // instream of the input file 54 | }; 55 | } // namespace err 56 | 57 | #endif // TIGER_ERRORMSG_ERROMSG_H_ 58 | -------------------------------------------------------------------------------- /src/tiger/escape/escape.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_ESCAPE_ESCAPE_H_ 2 | #define TIGER_ESCAPE_ESCAPE_H_ 3 | 4 | #include 5 | 6 | #include "tiger/symbol/symbol.h" 7 | 8 | // Forward Declarations 9 | namespace absyn { 10 | class AbsynTree; 11 | } // namespace absyn 12 | 13 | namespace esc { 14 | 15 | class EscapeEntry { 16 | public: 17 | int depth_; 18 | bool *escape_; 19 | 20 | EscapeEntry(int depth, bool *escape) : depth_(depth), escape_(escape) {} 21 | }; 22 | 23 | using EscEnv = sym::Table; 24 | using EscEnvPtr = sym::Table *; 25 | 26 | class EscFinder { 27 | public: 28 | EscFinder() = delete; 29 | explicit EscFinder(std::unique_ptr absyn_tree) 30 | : absyn_tree_(std::move(absyn_tree)), env_(std::make_unique()) {} 31 | 32 | /** 33 | * Escape analysis 34 | */ 35 | void FindEscape(); 36 | 37 | /** 38 | * Transfer the ownership of absyn tree to outer scope 39 | * @return unique pointer to the absyn tree 40 | */ 41 | std::unique_ptr TransferAbsynTree() { 42 | return std::move(absyn_tree_); 43 | } 44 | 45 | private: 46 | std::unique_ptr absyn_tree_; 47 | std::unique_ptr env_; 48 | }; 49 | } // namespace esc 50 | 51 | #endif -------------------------------------------------------------------------------- /src/tiger/lex/scanner.ih: -------------------------------------------------------------------------------- 1 | #include "scanner.h" 2 | -------------------------------------------------------------------------------- /src/tiger/liveness/flowgraph.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_LIVENESS_FLOWGRAPH_H_ 2 | #define TIGER_LIVENESS_FLOWGRAPH_H_ 3 | 4 | #include "tiger/codegen/assem.h" 5 | #include "tiger/frame/frame.h" 6 | #include "tiger/frame/temp.h" 7 | #include "tiger/util/graph.h" 8 | #include 9 | #include 10 | 11 | namespace fg { 12 | 13 | using FNode = graph::Node; 14 | using FNodePtr = graph::Node*; 15 | using FNodeListPtr = graph::NodeList*; 16 | using FGraph = graph::Graph; 17 | using FGraphPtr = graph::Graph*; 18 | 19 | class FlowGraphFactory { 20 | public: 21 | explicit FlowGraphFactory(assem::InstrList *instr_list) 22 | : instr_list_(instr_list), flowgraph_(new FGraph()), 23 | label_map_(std::make_unique>()) {} 24 | 25 | void AssemFlowGraph(); 26 | FGraphPtr GetFlowGraph() { return flowgraph_; } 27 | 28 | private: 29 | assem::InstrList *instr_list_; 30 | FGraphPtr flowgraph_; 31 | std::unique_ptr> label_map_; 32 | }; 33 | 34 | } // namespace fg 35 | 36 | #endif -------------------------------------------------------------------------------- /src/tiger/main/test_parse.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "tiger/absyn/absyn.h" 5 | #include "tiger/parse/parser.h" 6 | 7 | // define here to parse compilation 8 | frame::RegManager *reg_manager; 9 | frame::Frags frags; 10 | 11 | int main(int argc, char **argv) { 12 | std::unique_ptr absyn_tree; 13 | 14 | if (argc < 2) { 15 | fprintf(stderr, "usage: a.out filename\n"); 16 | exit(1); 17 | } 18 | 19 | Parser parser(argv[1], std::cerr); 20 | parser.parse(); 21 | absyn_tree = parser.TransferAbsynTree(); 22 | absyn_tree->Print(stderr); 23 | fprintf(stderr, "\n"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/tiger/main/test_semant.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "tiger/absyn/absyn.h" 5 | #include "tiger/errormsg/errormsg.h" 6 | #include "tiger/parse/parser.h" 7 | #include "tiger/semant/semant.h" 8 | 9 | // define here to pass compilation 10 | frame::RegManager *reg_manager; 11 | frame::Frags *frags; 12 | 13 | int main(int argc, char **argv) { 14 | std::unique_ptr absyn_tree; 15 | std::unique_ptr errormsg; 16 | 17 | if (argc < 2) { 18 | fprintf(stderr, "usage: a.out filename\n"); 19 | exit(1); 20 | } 21 | 22 | { 23 | Parser parser(argv[1], std::cerr); 24 | parser.parse(); 25 | errormsg = parser.TransferErrormsg(); 26 | absyn_tree = parser.TransferAbsynTree(); 27 | } 28 | 29 | { 30 | sem::ProgSem program_Semanalyzer(std::move(absyn_tree), std::move(errormsg)); 31 | program_Semanalyzer.SemAnalyze(); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/tiger/main/test_translate.cc: -------------------------------------------------------------------------------- 1 | #include "tiger/absyn/absyn.h" 2 | #include "tiger/escape/escape.h" 3 | #include "tiger/frame/x64frame.h" 4 | #include "tiger/parse/parser.h" 5 | #include "tiger/translate/translate.h" 6 | 7 | frame::RegManager *reg_manager; 8 | frame::Frags *frags; 9 | 10 | int main(int argc, char **argv) { 11 | std::string_view fname; 12 | std::unique_ptr absyn_tree; 13 | reg_manager = new frame::X64RegManager(); 14 | frags = new frame::Frags(); 15 | 16 | if (argc < 2) { 17 | fprintf(stderr, "usage: tiger-compiler file.tig\n"); 18 | exit(1); 19 | } 20 | 21 | fname = std::string_view(argv[1]); 22 | 23 | { 24 | std::unique_ptr errormsg; 25 | 26 | { 27 | // Lab 3: parsing 28 | // TigerLog("-------====Parse=====-----\n"); 29 | Parser parser(fname, std::cerr); 30 | parser.parse(); 31 | absyn_tree = parser.TransferAbsynTree(); 32 | errormsg = parser.TransferErrormsg(); 33 | } 34 | 35 | { 36 | // Lab 5: escape analysis 37 | // TigerLog("-------====Escape analysis=====-----\n"); 38 | esc::EscFinder esc_finder(std::move(absyn_tree)); 39 | esc_finder.FindEscape(); 40 | absyn_tree = esc_finder.TransferAbsynTree(); 41 | absyn_tree->Print(stderr); 42 | } 43 | 44 | { 45 | // Lab 5: translate IR tree 46 | // TigerLog("-------====Translate=====-----\n"); 47 | tr::ProgTr prog_tr(std::move(absyn_tree), std::move(errormsg)); 48 | prog_tr.Translate(); 49 | errormsg = prog_tr.TransferErrormsg(); 50 | } 51 | 52 | if (errormsg->AnyErrors()) 53 | return 1; // Don't continue if error occurrs 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/tiger/output/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_COMPILER_LOGGER_H 2 | #define TIGER_COMPILER_LOGGER_H 3 | 4 | #include 5 | 6 | #include "tiger/canon/canon.h" 7 | #include "tiger/codegen/codegen.h" 8 | 9 | class Logger { 10 | public: 11 | explicit Logger(FILE *out = stdout) : out_(out) {} 12 | 13 | inline void Log(std::string_view msg, ...) const { 14 | va_list ap; 15 | va_start(ap, msg); 16 | vfprintf(out_, msg.data(), ap); 17 | va_end(ap); 18 | } 19 | inline void Log(tree::Stm *stm) const { 20 | stm->Print(out_, 0); 21 | fprintf(out_, "\n"); 22 | } 23 | inline void Log(tree::StmList *stm_list) const { stm_list->Print(out_); } 24 | inline void Log(canon::StmListList *stm_lists) const { 25 | for (auto stm_list : stm_lists->GetList()) 26 | stm_list->Print(out_); 27 | } 28 | inline void Log(cg::AssemInstr *instr_list, temp::Map *map) const { 29 | instr_list->Print(out_, map); 30 | } 31 | 32 | private: 33 | FILE *out_; 34 | }; 35 | 36 | class NullLogger { 37 | public: 38 | constexpr NullLogger() noexcept = default; 39 | 40 | template 41 | inline void Log(T, Targs...) noexcept {} 42 | }; 43 | 44 | #ifdef NDEBUG 45 | #define TigerLog NullLogger().Log 46 | #else 47 | #define TigerLog Logger(stdout).Log 48 | #endif 49 | 50 | #endif // TIGER_COMPILER_LOGGER_H 51 | -------------------------------------------------------------------------------- /src/tiger/output/output.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_COMPILER_OUTPUT_H 2 | #define TIGER_COMPILER_OUTPUT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "tiger/canon/canon.h" 9 | #include "tiger/codegen/codegen.h" 10 | #include "tiger/frame/frame.h" 11 | #include "tiger/regalloc/regalloc.h" 12 | 13 | namespace output { 14 | 15 | class AssemGen { 16 | public: 17 | AssemGen() = delete; 18 | explicit AssemGen(std::string_view infile) { 19 | std::string outfile = static_cast(infile) + ".s"; 20 | out_ = fopen(outfile.data(), "w"); 21 | } 22 | AssemGen(const AssemGen &assem_generator) = delete; 23 | AssemGen(AssemGen &&assem_generator) = delete; 24 | AssemGen &operator=(const AssemGen &assem_generator) = delete; 25 | AssemGen &operator=(AssemGen &&assem_generator) = delete; 26 | ~AssemGen() { fclose(out_); } 27 | 28 | /** 29 | * Generate assembly 30 | */ 31 | void GenAssem(bool need_ra); 32 | 33 | private: 34 | FILE *out_; // Instream of source file 35 | }; 36 | 37 | } // namespace output 38 | 39 | #endif // TIGER_COMPILER_OUTPUT_H 40 | -------------------------------------------------------------------------------- /src/tiger/parse/parser.ih: -------------------------------------------------------------------------------- 1 | #include "tiger/parse/parser.h" 2 | -------------------------------------------------------------------------------- /src/tiger/regalloc/color.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_COMPILER_COLOR_H 2 | #define TIGER_COMPILER_COLOR_H 3 | 4 | #include "tiger/codegen/assem.h" 5 | #include "tiger/frame/temp.h" 6 | #include "tiger/liveness/liveness.h" 7 | #include "tiger/util/graph.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace col { 18 | struct Result { 19 | Result() : coloring(nullptr), spills(nullptr) {} 20 | Result(temp::Map *coloring, live::INodeListPtr spills) 21 | : coloring(coloring), spills(spills) {} 22 | temp::Map *coloring; 23 | live::INodeListPtr spills; 24 | }; 25 | 26 | template 27 | using Table = graph::Table; 28 | 29 | class Color { 30 | /* TODO: Put your lab6 code here */ 31 | public: 32 | explicit Color(live::LiveGraph live_graph) :live_graph_(live_graph) {}; 33 | Result GetResult(); 34 | private: 35 | live::LiveGraph live_graph_; 36 | }; 37 | } // namespace col 38 | 39 | #endif // TIGER_COMPILER_COLOR_H 40 | -------------------------------------------------------------------------------- /src/tiger/semant/semant.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_SEMANT_SEMANT_H_ 2 | #define TIGER_SEMANT_SEMANT_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "tiger/absyn/absyn.h" 8 | #include "tiger/env/env.h" 9 | #include "tiger/errormsg/errormsg.h" 10 | #include "tiger/semant/types.h" 11 | 12 | namespace sem { 13 | 14 | //lab4 only 15 | class ProgSem { 16 | public: 17 | ProgSem(std::unique_ptr absyn_tree, 18 | std::unique_ptr errormsg) 19 | : absyn_tree_(std::move(absyn_tree)), errormsg_(std::move(errormsg)), 20 | tenv_(std::make_unique()), 21 | venv_(std::make_unique()) {} 22 | 23 | /** 24 | * Semantic analysis 25 | */ 26 | void SemAnalyze(); 27 | 28 | /** 29 | * Transfer the ownership of errormsg to outer scope 30 | * @return unique pointer to errormsg 31 | */ 32 | std::unique_ptr TransferErrormsg() { 33 | return std::move(errormsg_); 34 | } 35 | 36 | /** 37 | * Transfer the ownership of absyn tree to outer scope 38 | * @return unique pointer to the absyn tree 39 | */ 40 | std::unique_ptr TransferAbsynTree() { 41 | return std::move(absyn_tree_); 42 | } 43 | 44 | private: 45 | std::unique_ptr absyn_tree_; 46 | std::unique_ptr errormsg_; 47 | 48 | std::unique_ptr tenv_; 49 | std::unique_ptr venv_; 50 | 51 | // Fill base symbol for var env and type env 52 | void FillBaseVEnv(); 53 | void FillBaseTEnv(); 54 | }; 55 | 56 | } // namespace sem 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/tiger/semant/types.cc: -------------------------------------------------------------------------------- 1 | #include "tiger/semant/types.h" 2 | 3 | namespace type { 4 | 5 | NilTy NilTy::nilty_; 6 | IntTy IntTy::intty_; 7 | StringTy StringTy::stringty_; 8 | VoidTy VoidTy::voidty_; 9 | 10 | Ty *Ty::ActualTy() { return this; } 11 | 12 | Ty *NameTy::ActualTy() { 13 | assert(ty_ != this); 14 | return ty_->ActualTy(); 15 | } 16 | 17 | bool Ty::IsSameType(Ty *expected) { 18 | Ty *a = ActualTy(); 19 | Ty *b = expected->ActualTy(); 20 | 21 | if ((typeid(*a) == typeid(NilTy) && typeid(*b) == typeid(RecordTy)) || 22 | (typeid(*a) == typeid(RecordTy) && typeid(*b) == typeid(NilTy))) 23 | return true; 24 | 25 | return a == b; 26 | } 27 | 28 | } // namespace type 29 | -------------------------------------------------------------------------------- /src/tiger/symbol/symbol.cc: -------------------------------------------------------------------------------- 1 | #include "tiger/symbol/symbol.h" 2 | 3 | namespace { 4 | 5 | constexpr unsigned int HASH_TABSIZE = 109; 6 | sym::Symbol *hashtable[HASH_TABSIZE]; 7 | 8 | unsigned int Hash(std::string_view str) { 9 | unsigned int h = 0; 10 | for (const char *s = str.data(); *s; s++) 11 | h = h * 65599 + *s; 12 | return h; 13 | } 14 | 15 | } // namespace 16 | 17 | namespace sym { 18 | 19 | Symbol *Symbol::UniqueSymbol(std::string_view name) { 20 | unsigned int index = Hash(name) % HASH_TABSIZE; 21 | Symbol *syms = hashtable[index], *sym; 22 | for (sym = syms; sym; sym = sym->next_) 23 | if (sym->name_ == name) 24 | return sym; 25 | sym = new Symbol(static_cast(name), syms); 26 | hashtable[index] = sym; 27 | return sym; 28 | } 29 | 30 | } // namespace sym 31 | -------------------------------------------------------------------------------- /src/tiger/symbol/symbol.h: -------------------------------------------------------------------------------- 1 | #ifndef TIGER_SYMBOL_SYMBOL_H_ 2 | #define TIGER_SYMBOL_SYMBOL_H_ 3 | 4 | #include 5 | 6 | #include "tiger/util/table.h" 7 | 8 | /** 9 | * Forward Declarations 10 | */ 11 | namespace env { 12 | class EnvEntry; 13 | } // namespace env 14 | namespace type { 15 | class Ty; 16 | } // namespace type 17 | 18 | namespace sym { 19 | class Symbol { 20 | template friend class Table; 21 | 22 | public: 23 | static Symbol *UniqueSymbol(std::string_view); 24 | [[nodiscard]] std::string Name() const { return name_; } 25 | 26 | private: 27 | Symbol(std::string name, Symbol *next) 28 | : name_(std::move(name)), next_(next) {} 29 | 30 | std::string name_; 31 | Symbol *next_; 32 | }; 33 | 34 | template 35 | class Table : public tab::Table { 36 | public: 37 | Table() : tab::Table() { in_loop_ = 0; } 38 | void BeginScope(); 39 | void EndScope(); 40 | void BeginLoop(); 41 | void EndLoop(); 42 | bool inLoop(); 43 | 44 | private: 45 | Symbol marksym_ = {"", nullptr}; 46 | int in_loop_; /* loop level */ 47 | }; 48 | 49 | template void Table::BeginScope() { 50 | this->Enter(&marksym_, nullptr); 51 | } 52 | 53 | template void Table::EndScope() { 54 | Symbol *s; 55 | do 56 | s = this->Pop(); 57 | while (s != &marksym_); 58 | } 59 | 60 | template void Table::BeginLoop() { 61 | this->in_loop_++; 62 | } 63 | 64 | template void Table::EndLoop() { 65 | this->in_loop_--; 66 | } 67 | 68 | template bool Table::inLoop() { 69 | return in_loop_ > 0; 70 | } 71 | 72 | } // namespace sym 73 | 74 | #endif // TIGER_SYMBOL_SYMBOL_H_ 75 | -------------------------------------------------------------------------------- /testdata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/.DS_Store -------------------------------------------------------------------------------- /testdata/backup/refs/test1.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test12.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test2.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test27.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test3.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test30.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test37.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test4.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test41.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test42.out: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test44.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test46.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test47.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test48.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test5.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test6.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test7.out: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /testdata/backup/refs/test8.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test.tig: -------------------------------------------------------------------------------- 1 | let 2 | function sum(v1: int, v2: int, v3: int, v4: int, v5: int, v6: int, v7: int) : int = 3 | let 4 | var sum := v1 + v2 + v3 + v4 + v5 + v6 + v7 5 | in 6 | sum 7 | end 8 | in 9 | printi(sum(1, 2, 3, 4, 5, 6, 7)) 10 | end -------------------------------------------------------------------------------- /testdata/backup/testcases/test1.tig: -------------------------------------------------------------------------------- 1 | /* an array type and an array variable */ 2 | let 3 | type arrtype = array of int 4 | var arr1:arrtype := arrtype [10] of 0 5 | in 6 | arr1 7 | end 8 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test12.tig: -------------------------------------------------------------------------------- 1 | /* valid for and let */ 2 | 3 | let 4 | var a:= 0 5 | in 6 | for i:=0 to 100 do (a:=a+1;()) 7 | end 8 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test2.tig: -------------------------------------------------------------------------------- 1 | /* arr1 is valid since expression 0 is int = myint */ 2 | let 3 | type myint = int 4 | type arrtype = array of myint 5 | 6 | var arr1:arrtype := arrtype [10] of 0 7 | in 8 | arr1 9 | end 10 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test27.tig: -------------------------------------------------------------------------------- 1 | /* locals hide globals */ 2 | let 3 | var a:=0 4 | 5 | function g(a:int):int = a 6 | in 7 | g(2) 8 | end 9 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test3.tig: -------------------------------------------------------------------------------- 1 | /* a record type and a record variable */ 2 | let 3 | type rectype = {name:string, age:int} 4 | var rec1:rectype := rectype {name="Nobody", age=1000} 5 | in 6 | rec1.name := "Somebody"; 7 | rec1 8 | end 9 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test30.tig: -------------------------------------------------------------------------------- 1 | /* synonyms are fine */ 2 | 3 | let 4 | type a = array of int 5 | type b = a 6 | 7 | var arr1:a := b [10] of 0 8 | in 9 | arr1[2] 10 | end 11 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test37.tig: -------------------------------------------------------------------------------- 1 | /* redeclaration of variable; this is legal, there are two different 2 | variables with the same name. The second one hides the first. */ 3 | let 4 | var a := 0 5 | var a := " " 6 | in 7 | 0 8 | end 9 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test4.tig: -------------------------------------------------------------------------------- 1 | /* define a recursive function */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int): int = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | nfactor(10) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test41.tig: -------------------------------------------------------------------------------- 1 | /* local types hide global */ 2 | let 3 | type a = int 4 | in 5 | let 6 | type a = string 7 | in 8 | 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test42.tig: -------------------------------------------------------------------------------- 1 | /* correct declarations */ 2 | let 3 | 4 | type arrtype1 = array of int 5 | type rectype1 = {name:string, address:string, id: int , age: int} 6 | type arrtype2 = array of rectype1 7 | type rectype2 = {name : string, dates: arrtype1} 8 | 9 | type arrtype3 = array of string 10 | 11 | var arr1 := arrtype1 [10] of 0 12 | var arr2 := arrtype2 [5] of rectype1 {name="aname", address="somewhere", id=0, age=0} 13 | var arr3:arrtype3 := arrtype3 [100] of "" 14 | 15 | var rec1 := rectype1 {name="Kapoios", address="Kapou", id=02432, age=44} 16 | var rec2 := rectype2 {name="Allos", dates= arrtype1 [3] of 1900} 17 | 18 | in 19 | 20 | arr1[0] := 1; 21 | arr1[9] := 3; 22 | arr2[3].name := "kati"; 23 | arr2[1].age := 23; 24 | arr3[34] := "sfd"; 25 | 26 | rec1.name := "sdf"; 27 | rec2.dates[0] := 2323; 28 | rec2.dates[2] := 2323 29 | 30 | end 31 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test44.tig: -------------------------------------------------------------------------------- 1 | /* valid nil initialization and assignment */ 2 | let 3 | 4 | type rectype = {name:string, id:int} 5 | var b:rectype := nil 6 | 7 | in 8 | 9 | b := nil 10 | 11 | end 12 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test46.tig: -------------------------------------------------------------------------------- 1 | /* valid rec comparisons */ 2 | let 3 | type rectype = {name:string, id:int} 4 | var b:rectype := nil 5 | in 6 | b = nil; 7 | b <> nil 8 | end 9 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test47.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second type "a" simply hides the first one. 2 | Because of the intervening variable declaration, the two "a" types 3 | are not in the same batch of mutually recursive types. 4 | See also test38 */ 5 | let 6 | type a = int 7 | var b := 4 8 | type a = string 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test48.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second function "g" simply hides the first one. 2 | Because of the intervening variable declaration, the two "g" functions 3 | are not in the same batch of mutually recursive functions. 4 | See also test39 */ 5 | let 6 | function g(a:int):int = a 7 | type t = int 8 | function g(a:int):int = a 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test5.tig: -------------------------------------------------------------------------------- 1 | /* define valid recursive types */ 2 | let 3 | /* define a list */ 4 | type intlist = {hd: int, tl: intlist} 5 | 6 | /* define a tree */ 7 | type tree ={key: int, children: treelist} 8 | type treelist = {hd: tree, tl: treelist} 9 | 10 | var lis:intlist := intlist { hd=0, tl= nil } 11 | 12 | in 13 | lis 14 | end 15 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test6.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive procedures */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string)= 5 | do_nothing2(a+1) 6 | 7 | function do_nothing2(d: int) = 8 | do_nothing1(d, "str") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test7.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive functions */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(d, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test8.tig: -------------------------------------------------------------------------------- 1 | /* correct if */ 2 | if (10 > 20) then 30 else 40 3 | -------------------------------------------------------------------------------- /testdata/backup/testcases/test_array.tig: -------------------------------------------------------------------------------- 1 | let 2 | var N := 8 3 | 4 | type t = {a:int, b:int} 5 | type strArray = array of string 6 | type recArray = array of t 7 | 8 | var row := strArray [ N ] of "a" 9 | var x := recArray [ N ] of t{a=1,b=2} 10 | 11 | in 12 | print(row[0]); 13 | printi(x[0].a); 14 | printi(x[1].b) 15 | end -------------------------------------------------------------------------------- /testdata/backup/testcases/test_extern.tig: -------------------------------------------------------------------------------- 1 | printi(sum_seven(1, 2, 3, 4, 5, 6, 7)) -------------------------------------------------------------------------------- /testdata/backup/testcases/test_patch.tig: -------------------------------------------------------------------------------- 1 | let 2 | function g(a:int, b:int, c:int, d:int) : int = 3 | if a > b | c < d 4 | then a + d 5 | else c + b 6 | in 7 | printi(g(9,4,3,2)) 8 | end -------------------------------------------------------------------------------- /testdata/lab1/refs/ref-0.txt: -------------------------------------------------------------------------------- 1 | Prog 2 | args: 2 3 | 8 7 4 | 80 5 | ProgProg 6 | args: 3 7 | 8 7 8 | 80 9 | 85 85 84 10 | 850 11 | RightProg 12 | args: 3 13 | 8 7 14 | 80 15 | 85 85 84 16 | 850 17 | -------------------------------------------------------------------------------- /testdata/lab1/refs/ref-1.txt: -------------------------------------------------------------------------------- 1 | ProgProg 2 | args: 3 3 | 8 7 4 | 80 5 | 85 85 84 6 | 850 7 | Prog 8 | args: 2 9 | 8 7 10 | 80 11 | RightProg 12 | args: 3 13 | 8 7 14 | 80 15 | 85 85 84 16 | 850 17 | -------------------------------------------------------------------------------- /testdata/lab1/testcases/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab1/testcases/.gitkeep -------------------------------------------------------------------------------- /testdata/lab2/refs/test1.out: -------------------------------------------------------------------------------- 1 | LET 43 2 | TYPE 48 3 | ID 54 arrtype 4 | EQ 62 5 | ARRAY 64 6 | OF 70 7 | ID 73 int 8 | VAR 78 9 | ID 82 arr1 10 | COLON 86 11 | ID 87 arrtype 12 | ASSIGN 95 13 | ID 98 arrtype 14 | LBRACK 106 15 | INT 107 10 16 | RBRACK 109 17 | OF 111 18 | INT 114 0 19 | IN 116 20 | ID 120 arr1 21 | END 125 22 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test10.out: -------------------------------------------------------------------------------- 1 | WHILE 38 2 | LPAREN 43 3 | INT 44 10 4 | GT 47 5 | INT 49 5 6 | RPAREN 50 7 | DO 52 8 | INT 55 5 9 | PLUS 56 10 | INT 57 6 11 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test11.out: -------------------------------------------------------------------------------- 1 | FOR 78 2 | ID 82 i 3 | ASSIGN 83 4 | INT 85 10 5 | TO 88 6 | STRING 91 7 | DO 95 8 | ID 100 i 9 | ASSIGN 102 10 | ID 105 i 11 | MINUS 107 12 | INT 109 1 13 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test12.out: -------------------------------------------------------------------------------- 1 | LET 26 2 | VAR 31 3 | ID 35 a 4 | ASSIGN 36 5 | INT 39 0 6 | IN 41 7 | FOR 46 8 | ID 50 i 9 | ASSIGN 51 10 | INT 53 0 11 | TO 55 12 | INT 58 100 13 | DO 62 14 | LPAREN 65 15 | ID 66 a 16 | ASSIGN 67 17 | ID 69 a 18 | PLUS 70 19 | INT 71 1 20 | SEMICOLON 72 21 | LPAREN 73 22 | RPAREN 74 23 | RPAREN 75 24 | END 77 25 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test13.out: -------------------------------------------------------------------------------- 1 | INT 48 3 2 | GT 50 3 | STRING 52 df 4 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test14.out: -------------------------------------------------------------------------------- 1 | LET 39 2 | TYPE 45 3 | ID 50 arrtype 4 | EQ 58 5 | ARRAY 60 6 | OF 66 7 | ID 69 int 8 | TYPE 74 9 | ID 79 rectype 10 | EQ 87 11 | LBRACE 89 12 | ID 90 name 13 | COLON 94 14 | ID 95 string 15 | COMMA 101 16 | ID 103 id 17 | COLON 105 18 | ID 107 int 19 | RBRACE 110 20 | VAR 114 21 | ID 118 rec 22 | ASSIGN 122 23 | ID 125 rectype 24 | LBRACE 133 25 | ID 134 name 26 | EQ 138 27 | STRING 139 aname 28 | COMMA 146 29 | ID 148 id 30 | EQ 150 31 | INT 151 0 32 | RBRACE 152 33 | VAR 155 34 | ID 159 arr 35 | ASSIGN 163 36 | ID 166 arrtype 37 | LBRACK 174 38 | INT 175 3 39 | RBRACK 176 40 | OF 178 41 | INT 181 0 42 | IN 184 43 | IF 188 44 | ID 191 rec 45 | NEQ 195 46 | ID 198 arr 47 | THEN 202 48 | INT 207 3 49 | ELSE 209 50 | INT 214 4 51 | END 216 52 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test15.out: -------------------------------------------------------------------------------- 1 | IF 41 2 | INT 44 20 3 | THEN 47 4 | INT 52 3 5 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test16.out: -------------------------------------------------------------------------------- 1 | LET 80 2 | TYPE 86 3 | ID 91 a 4 | EQ 92 5 | ID 93 c 6 | TYPE 95 7 | ID 100 b 8 | EQ 101 9 | ID 102 a 10 | TYPE 104 11 | ID 109 c 12 | EQ 110 13 | ID 111 d 14 | TYPE 113 15 | ID 118 d 16 | EQ 119 17 | ID 120 a 18 | IN 123 19 | STRING 127 (null) 20 | END 130 21 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test17.out: -------------------------------------------------------------------------------- 1 | LET 59 2 | TYPE 83 3 | ID 88 tree 4 | EQ 93 5 | LBRACE 94 6 | ID 95 key 7 | COLON 98 8 | ID 100 int 9 | COMMA 103 10 | ID 105 children 11 | COLON 113 12 | ID 115 treelist 13 | RBRACE 123 14 | VAR 125 15 | ID 129 d 16 | COLON 130 17 | ID 131 int 18 | ASSIGN 135 19 | INT 137 0 20 | TYPE 139 21 | ID 144 treelist 22 | EQ 153 23 | LBRACE 155 24 | ID 156 hd 25 | COLON 158 26 | ID 160 tree 27 | COMMA 164 28 | ID 166 tl 29 | COLON 168 30 | ID 170 treelist 31 | RBRACE 178 32 | IN 181 33 | ID 185 d 34 | END 187 35 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test18.out: -------------------------------------------------------------------------------- 1 | LET 64 2 | FUNCTION 69 3 | ID 78 do_nothing1 4 | LPAREN 89 5 | ID 90 a 6 | COLON 91 7 | ID 93 int 8 | COMMA 96 9 | ID 98 b 10 | COLON 99 11 | ID 101 string 12 | RPAREN 107 13 | COLON 108 14 | ID 109 int 15 | EQ 112 16 | LPAREN 116 17 | ID 117 do_nothing2 18 | LPAREN 128 19 | ID 129 a 20 | PLUS 130 21 | INT 131 1 22 | RPAREN 132 23 | SEMICOLON 133 24 | INT 134 0 25 | RPAREN 135 26 | VAR 138 27 | ID 142 d 28 | ASSIGN 143 29 | INT 145 0 30 | FUNCTION 148 31 | ID 157 do_nothing2 32 | LPAREN 168 33 | ID 169 d 34 | COLON 170 35 | ID 172 int 36 | RPAREN 175 37 | COLON 176 38 | ID 177 string 39 | EQ 184 40 | LPAREN 188 41 | ID 189 do_nothing1 42 | LPAREN 200 43 | ID 201 d 44 | COMMA 202 45 | STRING 204 str 46 | RPAREN 209 47 | SEMICOLON 210 48 | STRING 211 49 | RPAREN 214 50 | IN 217 51 | ID 221 do_nothing1 52 | LPAREN 232 53 | INT 233 0 54 | COMMA 234 55 | STRING 236 str2 56 | RPAREN 242 57 | END 244 58 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test19.out: -------------------------------------------------------------------------------- 1 | LET 90 2 | FUNCTION 95 3 | ID 104 do_nothing1 4 | LPAREN 115 5 | ID 116 a 6 | COLON 117 7 | ID 119 int 8 | COMMA 122 9 | ID 124 b 10 | COLON 125 11 | ID 127 string 12 | RPAREN 133 13 | COLON 134 14 | ID 135 int 15 | EQ 138 16 | LPAREN 142 17 | ID 143 do_nothing2 18 | LPAREN 154 19 | ID 155 a 20 | PLUS 156 21 | INT 157 1 22 | RPAREN 158 23 | SEMICOLON 159 24 | INT 160 0 25 | RPAREN 161 26 | FUNCTION 164 27 | ID 173 do_nothing2 28 | LPAREN 184 29 | ID 185 d 30 | COLON 186 31 | ID 188 int 32 | RPAREN 191 33 | COLON 192 34 | ID 193 string 35 | EQ 200 36 | LPAREN 204 37 | ID 205 do_nothing1 38 | LPAREN 216 39 | ID 217 a 40 | COMMA 218 41 | STRING 220 str 42 | RPAREN 225 43 | SEMICOLON 226 44 | STRING 227 45 | RPAREN 230 46 | IN 233 47 | ID 237 do_nothing1 48 | LPAREN 248 49 | INT 249 0 50 | COMMA 250 51 | STRING 252 str2 52 | RPAREN 258 53 | END 260 54 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test2.out: -------------------------------------------------------------------------------- 1 | LET 55 2 | TYPE 60 3 | ID 65 myint 4 | EQ 71 5 | ID 73 int 6 | TYPE 78 7 | ID 84 arrtype 8 | EQ 92 9 | ARRAY 94 10 | OF 100 11 | ID 103 myint 12 | VAR 111 13 | ID 115 arr1 14 | COLON 119 15 | ID 120 arrtype 16 | ASSIGN 128 17 | ID 131 arrtype 18 | LBRACK 139 19 | INT 140 10 20 | RBRACK 142 21 | OF 144 22 | INT 147 0 23 | IN 149 24 | ID 153 arr1 25 | END 158 26 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test20.out: -------------------------------------------------------------------------------- 1 | WHILE 37 2 | INT 43 10 3 | GT 46 4 | INT 48 5 5 | DO 50 6 | LPAREN 53 7 | ID 54 i 8 | PLUS 55 9 | INT 56 1 10 | SEMICOLON 57 11 | LPAREN 58 12 | RPAREN 59 13 | RPAREN 60 14 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test21.out: -------------------------------------------------------------------------------- 1 | LET 72 2 | FUNCTION 96 3 | ID 105 nfactor 4 | LPAREN 112 5 | ID 113 n 6 | COLON 114 7 | ID 116 int 8 | RPAREN 119 9 | EQ 121 10 | IF 125 11 | ID 129 n 12 | EQ 131 13 | INT 133 0 14 | THEN 139 15 | INT 144 1 16 | ELSE 149 17 | ID 154 n 18 | TIMES 156 19 | ID 158 nfactor 20 | LPAREN 165 21 | ID 166 n 22 | MINUS 167 23 | INT 168 1 24 | RPAREN 169 25 | IN 172 26 | ID 176 nfactor 27 | LPAREN 183 28 | INT 184 10 29 | RPAREN 186 30 | END 188 31 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test22.out: -------------------------------------------------------------------------------- 1 | LET 41 2 | TYPE 47 3 | ID 52 rectype 4 | EQ 60 5 | LBRACE 62 6 | ID 63 name 7 | COLON 67 8 | ID 68 string 9 | COMMA 75 10 | ID 77 id 11 | COLON 79 12 | ID 80 int 13 | RBRACE 83 14 | VAR 86 15 | ID 90 rec1 16 | ASSIGN 95 17 | ID 98 rectype 18 | LBRACE 106 19 | ID 107 name 20 | EQ 111 21 | STRING 112 Name 22 | COMMA 118 23 | ID 120 id 24 | EQ 122 25 | INT 123 0 26 | RBRACE 124 27 | IN 126 28 | ID 130 rec1 29 | DOT 134 30 | ID 135 nam 31 | ASSIGN 139 32 | STRING 142 asd 33 | END 148 34 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test23.out: -------------------------------------------------------------------------------- 1 | LET 30 2 | TYPE 36 3 | ID 41 rectype 4 | EQ 49 5 | LBRACE 51 6 | ID 52 name 7 | COLON 56 8 | ID 57 string 9 | COMMA 64 10 | ID 66 id 11 | COLON 68 12 | ID 69 int 13 | RBRACE 72 14 | VAR 75 15 | ID 79 rec1 16 | ASSIGN 84 17 | ID 87 rectype 18 | LBRACE 95 19 | ID 96 name 20 | EQ 100 21 | STRING 101 aname 22 | COMMA 108 23 | ID 110 id 24 | EQ 112 25 | INT 113 0 26 | RBRACE 114 27 | IN 116 28 | ID 120 rec1 29 | DOT 124 30 | ID 125 name 31 | ASSIGN 130 32 | INT 133 3 33 | SEMICOLON 134 34 | ID 137 rec1 35 | DOT 141 36 | ID 142 id 37 | ASSIGN 145 38 | STRING 148 (null) 39 | END 152 40 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test24.out: -------------------------------------------------------------------------------- 1 | LET 34 2 | VAR 40 3 | ID 44 d 4 | ASSIGN 45 5 | INT 47 0 6 | IN 49 7 | ID 53 d 8 | LBRACK 54 9 | INT 55 3 10 | RBRACK 56 11 | END 58 12 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test25.out: -------------------------------------------------------------------------------- 1 | LET 35 2 | VAR 41 3 | ID 45 d 4 | ASSIGN 46 5 | INT 48 0 6 | IN 50 7 | ID 54 d 8 | DOT 55 9 | ID 56 f 10 | END 59 11 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test26.out: -------------------------------------------------------------------------------- 1 | INT 33 3 2 | PLUS 35 3 | STRING 37 var 4 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test27.out: -------------------------------------------------------------------------------- 1 | LET 27 2 | VAR 32 3 | ID 36 a 4 | ASSIGN 37 5 | INT 39 0 6 | FUNCTION 43 7 | ID 52 g 8 | LPAREN 53 9 | ID 54 a 10 | COLON 55 11 | ID 56 int 12 | RPAREN 59 13 | COLON 60 14 | ID 61 int 15 | EQ 65 16 | ID 67 a 17 | IN 70 18 | ID 74 g 19 | LPAREN 75 20 | INT 76 2 21 | RPAREN 77 22 | END 79 23 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test28.out: -------------------------------------------------------------------------------- 1 | LET 39 2 | TYPE 44 3 | ID 49 rectype1 4 | EQ 58 5 | LBRACE 60 6 | ID 61 name 7 | COLON 65 8 | ID 66 string 9 | COMMA 73 10 | ID 75 id 11 | COLON 77 12 | ID 78 int 13 | RBRACE 81 14 | TYPE 84 15 | ID 89 rectype2 16 | EQ 98 17 | LBRACE 100 18 | ID 101 name 19 | COLON 105 20 | ID 106 string 21 | COMMA 113 22 | ID 115 id 23 | COLON 117 24 | ID 118 int 25 | RBRACE 121 26 | VAR 125 27 | ID 129 rec1 28 | COLON 133 29 | ID 135 rectype1 30 | ASSIGN 144 31 | ID 147 rectype2 32 | LBRACE 156 33 | ID 157 name 34 | EQ 161 35 | STRING 162 Name 36 | COMMA 168 37 | ID 170 id 38 | EQ 172 39 | INT 173 0 40 | RBRACE 174 41 | IN 176 42 | ID 180 rec1 43 | END 185 44 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test29.out: -------------------------------------------------------------------------------- 1 | LET 38 2 | TYPE 43 3 | ID 48 arrtype1 4 | EQ 57 5 | ARRAY 59 6 | OF 65 7 | ID 68 int 8 | TYPE 73 9 | ID 78 arrtype2 10 | EQ 87 11 | ARRAY 89 12 | OF 95 13 | ID 98 int 14 | VAR 104 15 | ID 108 arr1 16 | COLON 112 17 | ID 114 arrtype1 18 | ASSIGN 123 19 | ID 126 arrtype2 20 | LBRACK 135 21 | INT 136 10 22 | RBRACK 138 23 | OF 140 24 | INT 143 0 25 | IN 145 26 | ID 149 arr1 27 | END 154 28 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test3.out: -------------------------------------------------------------------------------- 1 | LET 43 2 | TYPE 48 3 | ID 54 rectype 4 | EQ 62 5 | LBRACE 64 6 | ID 65 name 7 | COLON 69 8 | ID 70 string 9 | COMMA 76 10 | ID 78 age 11 | COLON 81 12 | ID 82 int 13 | RBRACE 85 14 | VAR 88 15 | ID 92 rec1 16 | COLON 96 17 | ID 97 rectype 18 | ASSIGN 105 19 | ID 108 rectype 20 | LBRACE 116 21 | ID 117 name 22 | EQ 121 23 | STRING 122 Nobody 24 | COMMA 130 25 | ID 132 age 26 | EQ 135 27 | INT 136 1000 28 | RBRACE 140 29 | IN 142 30 | ID 146 rec1 31 | DOT 150 32 | ID 151 name 33 | ASSIGN 156 34 | STRING 159 Somebody 35 | SEMICOLON 169 36 | ID 172 rec1 37 | END 177 38 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test30.out: -------------------------------------------------------------------------------- 1 | LET 26 2 | TYPE 33 3 | ID 38 a 4 | EQ 40 5 | ARRAY 42 6 | OF 48 7 | ID 51 int 8 | TYPE 57 9 | ID 62 b 10 | EQ 64 11 | ID 66 a 12 | VAR 71 13 | ID 75 arr1 14 | COLON 79 15 | ID 80 a 16 | ASSIGN 82 17 | ID 85 b 18 | LBRACK 87 19 | INT 88 10 20 | RBRACK 90 21 | OF 92 22 | INT 95 0 23 | IN 97 24 | ID 102 arr1 25 | LBRACK 106 26 | INT 107 2 27 | RBRACK 108 28 | END 110 29 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test31.out: -------------------------------------------------------------------------------- 1 | LET 53 2 | VAR 59 3 | ID 63 a 4 | COLON 64 5 | ID 65 int 6 | ASSIGN 69 7 | STRING 72 8 | IN 76 9 | ID 80 a 10 | END 82 11 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test32.out: -------------------------------------------------------------------------------- 1 | LET 55 2 | TYPE 60 3 | ID 65 arrayty 4 | EQ 73 5 | ARRAY 75 6 | OF 81 7 | ID 84 int 8 | VAR 90 9 | ID 94 a 10 | ASSIGN 96 11 | ID 99 arrayty 12 | LBRACK 107 13 | INT 108 10 14 | RBRACK 110 15 | OF 112 16 | STRING 115 17 | IN 119 18 | INT 123 0 19 | END 125 20 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test33.out: -------------------------------------------------------------------------------- 1 | LET 28 2 | VAR 33 3 | ID 37 a 4 | ASSIGN 38 5 | ID 41 rectype 6 | LBRACE 49 7 | RBRACE 50 8 | IN 52 9 | INT 56 0 10 | END 58 11 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test34.out: -------------------------------------------------------------------------------- 1 | LET 56 2 | FUNCTION 61 3 | ID 70 g 4 | LPAREN 72 5 | ID 73 a 6 | COLON 74 7 | ID 75 int 8 | COMMA 79 9 | ID 81 b 10 | COLON 82 11 | ID 83 string 12 | RPAREN 89 13 | COLON 90 14 | ID 91 int 15 | EQ 95 16 | ID 97 a 17 | IN 99 18 | ID 103 g 19 | LPAREN 104 20 | STRING 105 one 21 | COMMA 110 22 | STRING 112 two 23 | RPAREN 117 24 | END 119 25 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test35.out: -------------------------------------------------------------------------------- 1 | LET 45 2 | FUNCTION 50 3 | ID 59 g 4 | LPAREN 61 5 | ID 62 a 6 | COLON 63 7 | ID 64 int 8 | COMMA 68 9 | ID 70 b 10 | COLON 71 11 | ID 72 string 12 | RPAREN 78 13 | COLON 79 14 | ID 80 int 15 | EQ 84 16 | ID 86 a 17 | IN 88 18 | ID 92 g 19 | LPAREN 93 20 | STRING 94 one 21 | RPAREN 99 22 | END 101 23 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test36.out: -------------------------------------------------------------------------------- 1 | LET 46 2 | FUNCTION 51 3 | ID 60 g 4 | LPAREN 62 5 | ID 63 a 6 | COLON 64 7 | ID 65 int 8 | COMMA 69 9 | ID 71 b 10 | COLON 72 11 | ID 73 string 12 | RPAREN 79 13 | COLON 80 14 | ID 81 int 15 | EQ 85 16 | ID 87 a 17 | IN 89 18 | ID 93 g 19 | LPAREN 94 20 | INT 95 3 21 | COMMA 96 22 | STRING 97 one 23 | COMMA 102 24 | INT 103 5 25 | RPAREN 104 26 | END 106 27 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test37.out: -------------------------------------------------------------------------------- 1 | LET 140 2 | VAR 145 3 | ID 149 a 4 | ASSIGN 151 5 | INT 154 0 6 | VAR 157 7 | ID 161 a 8 | ASSIGN 163 9 | STRING 166 10 | IN 170 11 | INT 174 0 12 | END 176 13 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test38.out: -------------------------------------------------------------------------------- 1 | LET 156 2 | TYPE 161 3 | ID 166 a 4 | EQ 168 5 | ID 170 int 6 | TYPE 175 7 | ID 180 a 8 | EQ 182 9 | ID 184 string 10 | IN 191 11 | INT 195 0 12 | END 197 13 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test39.out: -------------------------------------------------------------------------------- 1 | LET 161 2 | FUNCTION 166 3 | ID 175 g 4 | LPAREN 176 5 | ID 177 a 6 | COLON 178 7 | ID 179 int 8 | RPAREN 182 9 | COLON 183 10 | ID 184 int 11 | EQ 188 12 | ID 190 a 13 | FUNCTION 193 14 | ID 202 g 15 | LPAREN 203 16 | ID 204 a 17 | COLON 205 18 | ID 206 int 19 | RPAREN 209 20 | COLON 210 21 | ID 211 int 22 | EQ 215 23 | ID 217 a 24 | IN 219 25 | INT 223 0 26 | END 225 27 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test4.out: -------------------------------------------------------------------------------- 1 | LET 35 2 | FUNCTION 59 3 | ID 68 nfactor 4 | LPAREN 75 5 | ID 76 n 6 | COLON 77 7 | ID 79 int 8 | RPAREN 82 9 | COLON 83 10 | ID 85 int 11 | EQ 89 12 | IF 93 13 | ID 97 n 14 | EQ 99 15 | INT 101 0 16 | THEN 107 17 | INT 112 1 18 | ELSE 117 19 | ID 122 n 20 | TIMES 124 21 | ID 126 nfactor 22 | LPAREN 133 23 | ID 134 n 24 | MINUS 135 25 | INT 136 1 26 | RPAREN 137 27 | IN 140 28 | ID 144 nfactor 29 | LPAREN 151 30 | INT 152 10 31 | RPAREN 154 32 | END 156 33 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test40.out: -------------------------------------------------------------------------------- 1 | LET 39 2 | FUNCTION 44 3 | ID 53 g 4 | LPAREN 54 5 | ID 55 a 6 | COLON 56 7 | ID 57 int 8 | RPAREN 60 9 | EQ 62 10 | ID 64 a 11 | IN 66 12 | ID 71 g 13 | LPAREN 72 14 | INT 73 2 15 | RPAREN 74 16 | END 76 17 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test41.out: -------------------------------------------------------------------------------- 1 | LET 31 2 | TYPE 36 3 | ID 41 a 4 | EQ 43 5 | ID 45 int 6 | IN 49 7 | LET 53 8 | TYPE 59 9 | ID 64 a 10 | EQ 66 11 | ID 68 string 12 | IN 76 13 | INT 81 0 14 | END 84 15 | END 88 16 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test43.out: -------------------------------------------------------------------------------- 1 | LET 67 2 | VAR 73 3 | ID 77 a 4 | ASSIGN 79 5 | LPAREN 82 6 | RPAREN 83 7 | IN 85 8 | ID 89 a 9 | PLUS 91 10 | INT 93 3 11 | END 95 12 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test44.out: -------------------------------------------------------------------------------- 1 | LET 47 2 | TYPE 54 3 | ID 59 rectype 4 | EQ 67 5 | LBRACE 69 6 | ID 70 name 7 | COLON 74 8 | ID 75 string 9 | COMMA 81 10 | ID 83 id 11 | COLON 85 12 | ID 86 int 13 | RBRACE 89 14 | VAR 92 15 | ID 96 b 16 | COLON 97 17 | ID 98 rectype 18 | ASSIGN 106 19 | NIL 109 20 | IN 114 21 | ID 119 b 22 | ASSIGN 121 23 | NIL 124 24 | END 129 25 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test45.out: -------------------------------------------------------------------------------- 1 | LET 74 2 | TYPE 80 3 | ID 85 rectype 4 | EQ 93 5 | LBRACE 95 6 | ID 96 name 7 | COLON 100 8 | ID 101 string 9 | COMMA 107 10 | ID 109 id 11 | COLON 111 12 | ID 112 int 13 | RBRACE 115 14 | VAR 119 15 | ID 123 a 16 | ASSIGN 124 17 | NIL 127 18 | IN 131 19 | ID 135 a 20 | END 137 21 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test46.out: -------------------------------------------------------------------------------- 1 | LET 29 2 | TYPE 35 3 | ID 40 rectype 4 | EQ 48 5 | LBRACE 50 6 | ID 51 name 7 | COLON 55 8 | ID 56 string 9 | COMMA 62 10 | ID 64 id 11 | COLON 66 12 | ID 67 int 13 | RBRACE 70 14 | VAR 73 15 | ID 77 b 16 | COLON 78 17 | ID 79 rectype 18 | ASSIGN 87 19 | NIL 90 20 | IN 94 21 | ID 98 b 22 | EQ 100 23 | NIL 102 24 | SEMICOLON 105 25 | ID 108 b 26 | NEQ 110 27 | NIL 113 28 | END 117 29 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test47.out: -------------------------------------------------------------------------------- 1 | LET 219 2 | TYPE 224 3 | ID 229 a 4 | EQ 231 5 | ID 233 int 6 | VAR 238 7 | ID 242 b 8 | ASSIGN 244 9 | INT 247 4 10 | TYPE 250 11 | ID 255 a 12 | EQ 257 13 | ID 259 string 14 | IN 266 15 | INT 270 0 16 | END 272 17 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test48.out: -------------------------------------------------------------------------------- 1 | LET 232 2 | FUNCTION 237 3 | ID 246 g 4 | LPAREN 247 5 | ID 248 a 6 | COLON 249 7 | ID 250 int 8 | RPAREN 253 9 | COLON 254 10 | ID 255 int 11 | EQ 259 12 | ID 261 a 13 | TYPE 264 14 | ID 269 t 15 | EQ 271 16 | ID 273 int 17 | FUNCTION 278 18 | ID 287 g 19 | LPAREN 288 20 | ID 289 a 21 | COLON 290 22 | ID 291 int 23 | RPAREN 294 24 | COLON 295 25 | ID 296 int 26 | EQ 300 27 | ID 302 a 28 | IN 304 29 | INT 308 0 30 | END 310 31 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test49.out: -------------------------------------------------------------------------------- 1 | LET 68 2 | TYPE 74 3 | ID 79 rectype 4 | EQ 87 5 | LBRACE 89 6 | ID 90 name 7 | COLON 94 8 | ID 95 string 9 | COMMA 101 10 | ID 103 id 11 | COLON 105 12 | ID 106 int 13 | RBRACE 109 14 | VAR 113 15 | ID 117 a 16 | ASSIGN 118 17 | ID 121 rectype 18 | NIL 129 19 | IN 133 20 | ID 137 a 21 | END 139 22 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test5.out: -------------------------------------------------------------------------------- 1 | LET 36 2 | TYPE 60 3 | ID 65 intlist 4 | EQ 73 5 | LBRACE 75 6 | ID 76 hd 7 | COLON 78 8 | ID 80 int 9 | COMMA 83 10 | ID 85 tl 11 | COLON 87 12 | ID 89 intlist 13 | RBRACE 96 14 | TYPE 120 15 | ID 125 tree 16 | EQ 130 17 | LBRACE 131 18 | ID 132 key 19 | COLON 135 20 | ID 137 int 21 | COMMA 140 22 | ID 142 children 23 | COLON 150 24 | ID 152 treelist 25 | RBRACE 160 26 | TYPE 162 27 | ID 167 treelist 28 | EQ 176 29 | LBRACE 178 30 | ID 179 hd 31 | COLON 181 32 | ID 183 tree 33 | COMMA 187 34 | ID 189 tl 35 | COLON 191 36 | ID 193 treelist 37 | RBRACE 201 38 | VAR 204 39 | ID 208 lis 40 | COLON 211 41 | ID 212 intlist 42 | ASSIGN 220 43 | ID 223 intlist 44 | LBRACE 231 45 | ID 233 hd 46 | EQ 235 47 | INT 236 0 48 | COMMA 237 49 | ID 239 tl 50 | EQ 241 51 | NIL 243 52 | RBRACE 247 53 | IN 251 54 | ID 255 lis 55 | END 259 56 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test50.out: -------------------------------------------------------------------------------- 1 | LET 83 2 | TYPE 89 3 | ID 103 rectype 4 | EQ 111 5 | LBRACE 113 6 | ID 114 name 7 | COLON 118 8 | ID 119 string 9 | COMMA 125 10 | ID 127 id 11 | COLON 129 12 | ID 130 int 13 | RBRACE 133 14 | VAR 137 15 | ID 141 a 16 | ASSIGN 142 17 | ID 145 rectype 18 | NIL 153 19 | IN 157 20 | ID 161 a 21 | END 163 22 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test51.out: -------------------------------------------------------------------------------- 1 | LET 98 2 | TYPE 104 3 | ID 109 rectype 4 | EQ 117 5 | LBRACE 119 6 | ID 120 name 7 | COLON 124 8 | ID 125 string 9 | COMMA 131 10 | ID 133 id 11 | COLON 135 12 | ID 136 int 13 | RBRACE 139 14 | VAR 143 15 | ID 147 a 16 | ASSIGN 148 17 | ID 151 rectype 18 | NIL 159 19 | IN 163 20 | ID 167 a 21 | END 169 22 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test52.out: -------------------------------------------------------------------------------- 1 | LET 1 2 | VAR 6 3 | ID 10 a 4 | ASSIGN 12 5 | STRING 15 compilers 6 | 7 | VAR 30 8 | ID 34 b 9 | ASSIGN 36 10 | STRING 39 compilers 11 | 12 | VAR 81 13 | ID 85 c 14 | ASSIGN 87 15 | STRING 90 c o m p i l e r s 16 | 17 | VAR 123 18 | ID 127 d 19 | ASSIGN 129 20 | STRING 132 "compilers" 21 | 22 | VAR 151 23 | ID 155 e 24 | ASSIGN 157 25 | STRING 160 \compilers\ 26 | 27 | VAR 179 28 | ID 183 f 29 | ASSIGN 185 30 | STRING 188 commmmmmmmmmmmmlerssssssssssss 31 | 32 | VAR 237 33 | ID 241 g 34 | ASSIGN 243 35 | STRING 246    36 | 37 | IN 278 38 | INT 282 0 39 | END 284 40 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test6.out: -------------------------------------------------------------------------------- 1 | LET 50 2 | FUNCTION 55 3 | ID 64 do_nothing1 4 | LPAREN 75 5 | ID 76 a 6 | COLON 77 7 | ID 79 int 8 | COMMA 82 9 | ID 84 b 10 | COLON 85 11 | ID 87 string 12 | RPAREN 93 13 | EQ 94 14 | ID 98 do_nothing2 15 | LPAREN 109 16 | ID 110 a 17 | PLUS 111 18 | INT 112 1 19 | RPAREN 113 20 | FUNCTION 116 21 | ID 125 do_nothing2 22 | LPAREN 136 23 | ID 137 d 24 | COLON 138 25 | ID 140 int 26 | RPAREN 143 27 | EQ 145 28 | ID 149 do_nothing1 29 | LPAREN 160 30 | ID 161 d 31 | COMMA 162 32 | STRING 164 str 33 | RPAREN 169 34 | IN 172 35 | ID 176 do_nothing1 36 | LPAREN 187 37 | INT 188 0 38 | COMMA 189 39 | STRING 191 str2 40 | RPAREN 197 41 | END 199 42 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test7.out: -------------------------------------------------------------------------------- 1 | LET 49 2 | FUNCTION 54 3 | ID 63 do_nothing1 4 | LPAREN 74 5 | ID 75 a 6 | COLON 76 7 | ID 78 int 8 | COMMA 81 9 | ID 83 b 10 | COLON 84 11 | ID 86 string 12 | RPAREN 92 13 | COLON 93 14 | ID 94 int 15 | EQ 97 16 | LPAREN 101 17 | ID 102 do_nothing2 18 | LPAREN 113 19 | ID 114 a 20 | PLUS 115 21 | INT 116 1 22 | RPAREN 117 23 | SEMICOLON 118 24 | INT 119 0 25 | RPAREN 120 26 | FUNCTION 123 27 | ID 132 do_nothing2 28 | LPAREN 143 29 | ID 144 d 30 | COLON 145 31 | ID 147 int 32 | RPAREN 150 33 | COLON 151 34 | ID 152 string 35 | EQ 159 36 | LPAREN 163 37 | ID 164 do_nothing1 38 | LPAREN 175 39 | ID 176 d 40 | COMMA 177 41 | STRING 179 str 42 | RPAREN 184 43 | SEMICOLON 185 44 | STRING 186 45 | RPAREN 189 46 | IN 192 47 | ID 196 do_nothing1 48 | LPAREN 207 49 | INT 208 0 50 | COMMA 209 51 | STRING 211 str2 52 | RPAREN 217 53 | END 219 54 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test8.out: -------------------------------------------------------------------------------- 1 | IF 18 2 | LPAREN 21 3 | INT 22 10 4 | GT 25 5 | INT 27 20 6 | RPAREN 29 7 | THEN 31 8 | INT 36 30 9 | ELSE 39 10 | INT 44 40 11 | -------------------------------------------------------------------------------- /testdata/lab2/refs/test9.out: -------------------------------------------------------------------------------- 1 | IF 44 2 | LPAREN 47 3 | INT 48 5 4 | GT 49 5 | INT 50 4 6 | RPAREN 51 7 | THEN 53 8 | INT 58 13 9 | ELSE 61 10 | STRING 67 11 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/merge.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | type any = {any : int} 4 | var buffer := getchar() 5 | 6 | function readint(any: any) : int = 7 | let var i := 0 8 | function isdigit(s : string) : int = 9 | ord(buffer)>=ord("0") & ord(buffer)<=ord("9") 10 | function skipto() = 11 | while buffer=" " | buffer="\n" 12 | do buffer := getchar() 13 | in skipto(); 14 | any.any := isdigit(buffer); 15 | while isdigit(buffer) 16 | do (i := i*10+ord(buffer)-ord("0"); buffer := getchar()); 17 | i 18 | end 19 | 20 | type list = {first: int, rest: list} 21 | 22 | function readlist() : list = 23 | let var any := any{any=0} 24 | var i := readint(any) 25 | in if any.any 26 | then list{first=i,rest=readlist()} 27 | else nil 28 | end 29 | 30 | function merge(a: list, b: list) : list = 31 | if a=nil then b 32 | else if b=nil then a 33 | else if a.first < b.first 34 | then list{first=a.first,rest=merge(a.rest,b)} 35 | else list{first=b.first,rest=merge(a,b.rest)} 36 | 37 | function printint(i: int) = 38 | let function f(i:int) = if i>0 39 | then (f(i/10); print(chr(i-i/10*10+ord("0")))) 40 | in if i<0 then (print("-"); f(-i)) 41 | else if i>0 then f(i) 42 | else print("0") 43 | end 44 | 45 | function printlist(l: list) = 46 | if l=nil then print("\n") 47 | else (printint(l.first); print(" "); printlist(l.rest)) 48 | 49 | var list1 := readlist() 50 | var list2 := (buffer:=getchar(); readlist()) 51 | 52 | 53 | /* BODY OF MAIN PROGRAM */ 54 | in printlist(merge(list1,list2)) 55 | end 56 | 57 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/queens.tig: -------------------------------------------------------------------------------- 1 | /* A program to solve the 8-queens problem */ 2 | 3 | let 4 | var N := 8 5 | 6 | type intArray = array of int 7 | 8 | var row := intArray [ N ] of 0 9 | var col := intArray [ N ] of 0 10 | var diag1 := intArray [N+N-1] of 0 11 | var diag2 := intArray [N+N-1] of 0 12 | 13 | function printboard() = 14 | (for i := 0 to N-1 15 | do (for j := 0 to N-1 16 | do print(if col[i]=j then " O" else " ."); 17 | print("\n")); 18 | print("\n")) 19 | 20 | function try(c:int) = 21 | ( /* for i:= 0 to c do print("."); print("\n"); flush();*/ 22 | if c=N 23 | then printboard() 24 | else for r := 0 to N-1 25 | do if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0 26 | then (row[r]:=1; diag1[r+c]:=1; diag2[r+7-c]:=1; 27 | col[c]:=r; 28 | try(c+1); 29 | row[r]:=0; diag1[r+c]:=0; diag2[r+7-c]:=0) 30 | 31 | ) 32 | in try(0) 33 | end 34 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test1.tig: -------------------------------------------------------------------------------- 1 | /* an array type and an array variable */ 2 | let 3 | type arrtype = array of int 4 | var arr1:arrtype := arrtype [10] of 0 5 | in 6 | arr1 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test10.tig: -------------------------------------------------------------------------------- 1 | /* error : body of while not unit */ 2 | while(10 > 5) do 5+6 3 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test11.tig: -------------------------------------------------------------------------------- 1 | /* error hi expr is not int, and index variable erroneously assigned to. */ 2 | for i:=10 to " " do 3 | i := i - 1 4 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test12.tig: -------------------------------------------------------------------------------- 1 | /* valid for and let */ 2 | 3 | let 4 | var a:= 0 5 | in 6 | for i:=0 to 100 do (a:=a+1;()) 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test13.tig: -------------------------------------------------------------------------------- 1 | /* error: comparison of incompatible types */ 2 | 3 | 3 > "df" 4 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test14.tig: -------------------------------------------------------------------------------- 1 | /* error : compare rec with array */ 2 | 3 | let 4 | 5 | type arrtype = array of int 6 | type rectype = {name:string, id: int} 7 | 8 | var rec := rectype {name="aname", id=0} 9 | var arr := arrtype [3] of 0 10 | 11 | in 12 | if rec <> arr then 3 else 4 13 | end 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test15.tig: -------------------------------------------------------------------------------- 1 | /* error : if-then returns non unit */ 2 | 3 | if 20 then 3 4 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test16.tig: -------------------------------------------------------------------------------- 1 | /* error: mutually recursive types thet do not pass through record or array */ 2 | let 3 | 4 | type a=c 5 | type b=a 6 | type c=d 7 | type d=a 8 | 9 | in 10 | "" 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test17.tig: -------------------------------------------------------------------------------- 1 | /* error: definition of recursive types is interrupted */ 2 | let 3 | /* define a tree */ 4 | type tree ={key: int, children: treelist} 5 | var d:int :=0 6 | type treelist = {hd: tree, tl: treelist} 7 | 8 | in 9 | d 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test18.tig: -------------------------------------------------------------------------------- 1 | /* error : definition of recursive functions is interrupted */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | var d:=0 8 | 9 | function do_nothing2(d: int):string = 10 | (do_nothing1(d, "str");" ") 11 | 12 | in 13 | do_nothing1(0, "str2") 14 | end 15 | 16 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test19.tig: -------------------------------------------------------------------------------- 1 | /* error : second function uses variables local to the first one, undeclared variable */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(a, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test2.tig: -------------------------------------------------------------------------------- 1 | /* arr1 is valid since expression 0 is int = myint */ 2 | let 3 | type myint = int 4 | type arrtype = array of myint 5 | 6 | var arr1:arrtype := arrtype [10] of 0 7 | in 8 | arr1 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test20.tig: -------------------------------------------------------------------------------- 1 | /* error: undeclared variable i */ 2 | 3 | while 10 > 5 do (i+1;()) 4 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test21.tig: -------------------------------------------------------------------------------- 1 | /* error : procedure returns value and procedure is used in arexpr */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int) = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | nfactor(10) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test22.tig: -------------------------------------------------------------------------------- 1 | /* error : field not in record type */ 2 | 3 | let 4 | type rectype = {name:string , id:int} 5 | var rec1 := rectype {name="Name", id=0} 6 | in 7 | rec1.nam := "asd" 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test23.tig: -------------------------------------------------------------------------------- 1 | /* error : type mismatch */ 2 | 3 | let 4 | type rectype = {name:string , id:int} 5 | var rec1 := rectype {name="aname", id=0} 6 | in 7 | rec1.name := 3; 8 | rec1.id := "" 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test24.tig: -------------------------------------------------------------------------------- 1 | /* error : variable not array */ 2 | let 3 | var d:=0 4 | in 5 | d[3] 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test25.tig: -------------------------------------------------------------------------------- 1 | /* error : variable not record */ 2 | let 3 | var d:=0 4 | in 5 | d.f 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test26.tig: -------------------------------------------------------------------------------- 1 | /* error : integer required */ 2 | 3 | 3 + "var" 4 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test27.tig: -------------------------------------------------------------------------------- 1 | /* locals hide globals */ 2 | let 3 | var a:=0 4 | 5 | function g(a:int):int = a 6 | in 7 | g(2) 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test28.tig: -------------------------------------------------------------------------------- 1 | /* error : different record types */ 2 | 3 | let 4 | type rectype1 = {name:string , id:int} 5 | type rectype2 = {name:string , id:int} 6 | 7 | var rec1: rectype1 := rectype2 {name="Name", id=0} 8 | in 9 | rec1 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test29.tig: -------------------------------------------------------------------------------- 1 | /* error : different array types */ 2 | 3 | let 4 | type arrtype1 = array of int 5 | type arrtype2 = array of int 6 | 7 | var arr1: arrtype1 := arrtype2 [10] of 0 8 | in 9 | arr1 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test3.tig: -------------------------------------------------------------------------------- 1 | /* a record type and a record variable */ 2 | let 3 | type rectype = {name:string, age:int} 4 | var rec1:rectype := rectype {name="Nobody", age=1000} 5 | in 6 | rec1.name := "Somebody"; 7 | rec1 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test30.tig: -------------------------------------------------------------------------------- 1 | /* synonyms are fine */ 2 | 3 | let 4 | type a = array of int 5 | type b = a 6 | 7 | var arr1:a := b [10] of 0 8 | in 9 | arr1[2] 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test31.tig: -------------------------------------------------------------------------------- 1 | /* error : type constraint and init value differ */ 2 | let 3 | var a:int := " " 4 | in 5 | a 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test32.tig: -------------------------------------------------------------------------------- 1 | /* error : initializing exp and array type differ */ 2 | 3 | let 4 | type arrayty = array of int 5 | 6 | var a := arrayty [10] of " " 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test33.tig: -------------------------------------------------------------------------------- 1 | /* error : unknown type */ 2 | let 3 | var a:= rectype {} 4 | in 5 | 0 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test34.tig: -------------------------------------------------------------------------------- 1 | /* error : formals and actuals have different types */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g("one", "two") 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test35.tig: -------------------------------------------------------------------------------- 1 | /* error : formals are more then actuals */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g("one") 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test36.tig: -------------------------------------------------------------------------------- 1 | /* error : formals are fewer then actuals */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g(3,"one",5) 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test37.tig: -------------------------------------------------------------------------------- 1 | /* redeclaration of variable; this is legal, there are two different 2 | variables with the same name. The second one hides the first. */ 3 | let 4 | var a := 0 5 | var a := " " 6 | in 7 | 0 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test38.tig: -------------------------------------------------------------------------------- 1 | /* This is illegal, since there are two types with the same name 2 | in the same (consecutive) batch of mutually recursive types. 3 | See also test47 */ 4 | let 5 | type a = int 6 | type a = string 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test39.tig: -------------------------------------------------------------------------------- 1 | /* This is illegal, since there are two functions with the same name 2 | in the same (consecutive) batch of mutually recursive functions. 3 | See also test48 */ 4 | let 5 | function g(a:int):int = a 6 | function g(a:int):int = a 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test4.tig: -------------------------------------------------------------------------------- 1 | /* define a recursive function */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int): int = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | nfactor(10) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test40.tig: -------------------------------------------------------------------------------- 1 | /* error : procedure returns value */ 2 | let 3 | function g(a:int) = a 4 | in 5 | g(2) 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test41.tig: -------------------------------------------------------------------------------- 1 | /* local types hide global */ 2 | let 3 | type a = int 4 | in 5 | let 6 | type a = string 7 | in 8 | 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test42.tig: -------------------------------------------------------------------------------- 1 | /* correct declarations */ 2 | let 3 | 4 | type arrtype1 = array of int 5 | type rectype1 = {name:string, address:string, id: int , age: int} 6 | type arrtype2 = array of rectype1 7 | type rectype2 = {name : string, dates: arrtype1} 8 | 9 | type arrtype3 = array of string 10 | 11 | var arr1 := arrtype1 [10] of 0 12 | var arr2 := arrtype2 [5] of rectype1 {name="aname", address="somewhere", id=0, age=0} 13 | var arr3:arrtype3 := arrtype3 [100] of "" 14 | 15 | var rec1 := rectype1 {name="Kapoios", address="Kapou", id=02432, age=44} 16 | var rec2 := rectype2 {name="Allos", dates= arrtype1 [3] of 1900} 17 | 18 | in 19 | 20 | arr1[0] := 1; 21 | arr1[9] := 3; 22 | arr2[3].name := "kati"; 23 | arr2[1].age := 23; 24 | arr3[34] := "sfd"; 25 | 26 | rec1.name := "sdf"; 27 | rec2.dates[0] := 2323; 28 | rec2.dates[2] := 2323 29 | 30 | end 31 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test43.tig: -------------------------------------------------------------------------------- 1 | /* initialize with unit and causing type mismatch in addition */ 2 | 3 | let 4 | var a := () 5 | in 6 | a + 3 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test44.tig: -------------------------------------------------------------------------------- 1 | /* valid nil initialization and assignment */ 2 | let 3 | 4 | type rectype = {name:string, id:int} 5 | var b:rectype := nil 6 | 7 | in 8 | 9 | b := nil 10 | 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test45.tig: -------------------------------------------------------------------------------- 1 | /* error: initializing nil expressions not constrained by record type */ 2 | let 3 | type rectype = {name:string, id:int} 4 | 5 | var a:= nil 6 | in 7 | a 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test46.tig: -------------------------------------------------------------------------------- 1 | /* valid rec comparisons */ 2 | let 3 | type rectype = {name:string, id:int} 4 | var b:rectype := nil 5 | in 6 | b = nil; 7 | b <> nil 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test47.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second type "a" simply hides the first one. 2 | Because of the intervening variable declaration, the two "a" types 3 | are not in the same batch of mutually recursive types. 4 | See also test38 */ 5 | let 6 | type a = int 7 | var b := 4 8 | type a = string 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test48.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second function "g" simply hides the first one. 2 | Because of the intervening variable declaration, the two "g" functions 3 | are not in the same batch of mutually recursive functions. 4 | See also test39 */ 5 | let 6 | function g(a:int):int = a 7 | type t = int 8 | function g(a:int):int = a 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test49.tig: -------------------------------------------------------------------------------- 1 | /* error: syntax error, nil should not be preceded by type-id. */ 2 | let 3 | type rectype = {name:string, id:int} 4 | 5 | var a:= rectype nil 6 | in 7 | a 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test5.tig: -------------------------------------------------------------------------------- 1 | /* define valid recursive types */ 2 | let 3 | /* define a list */ 4 | type intlist = {hd: int, tl: intlist} 5 | 6 | /* define a tree */ 7 | type tree ={key: int, children: treelist} 8 | type treelist = {hd: tree, tl: treelist} 9 | 10 | var lis:intlist := intlist { hd=0, tl= nil } 11 | 12 | in 13 | lis 14 | end 15 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test50.tig: -------------------------------------------------------------------------------- 1 | /* error: syntax error, * 2 | nil *should not be 3 | 4 | 5 | prece/ded by type-id. */ 6 | 7 | let 8 | type /*!@#$%*/rectype = {name:string, id:int} 9 | 10 | var a:= rectype nil 11 | in 12 | a 13 | end 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test51.tig: -------------------------------------------------------------------------------- 1 | /* error: 2 | /**/ /**/ 3 | syntax /*error*/, 4 | /*nil should not be preceded by type-id. */*/ 5 | let 6 | type rectype = {name:string, id:int} 7 | 8 | var a:= rectype nil 9 | in 10 | a 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test52.tig: -------------------------------------------------------------------------------- 1 | let 2 | var a := "compilers\n" 3 | var b := "\099\111\109\112\105\108\101\114\115\n" 4 | var c := "c\to\tm\tp\ti\tl\te\tr\ts\t\n" 5 | var d := "\"compilers\"\n" 6 | var e := "\\compilers\\\n" 7 | var f := "commmmmmmmmmmmm\ 8 | \lerssssssssssss\n" 9 | var g := "\^C\^O\^M\^P\^I\^L\^E\^R\^S\n" 10 | in 11 | 0 12 | end 13 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test6.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive procedures */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string)= 5 | do_nothing2(a+1) 6 | 7 | function do_nothing2(d: int) = 8 | do_nothing1(d, "str") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test7.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive functions */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(d, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test8.tig: -------------------------------------------------------------------------------- 1 | /* correct if */ 2 | if (10 > 20) then 30 else 40 3 | -------------------------------------------------------------------------------- /testdata/lab2/testcases/test9.tig: -------------------------------------------------------------------------------- 1 | /* error : types of then - else differ */ 2 | 3 | if (5>4) then 13 else " " 4 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test1.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(arrtype, 6 | arrayTy(int)), 7 | nameAndTyList())), 8 | decList( 9 | varDec(arr1, 10 | arrtype, 11 | arrayExp(arrtype, 12 | intExp(10), 13 | intExp(0)), 14 | TRUE), 15 | decList())), 16 | seqExp( 17 | expList( 18 | varExp( 19 | simpleVar(arr1)), 20 | expList()))) 21 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test10.out: -------------------------------------------------------------------------------- 1 | whileExp( 2 | opExp( 3 | GREAT, 4 | intExp(10), 5 | intExp(5)), 6 | opExp( 7 | PLUS, 8 | intExp(5), 9 | intExp(6))) 10 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test11.out: -------------------------------------------------------------------------------- 1 | forExp(i, 2 | intExp(10), 3 | stringExp( ), 4 | assignExp( 5 | simpleVar(i), 6 | opExp( 7 | MINUS, 8 | varExp( 9 | simpleVar(i)), 10 | intExp(1))), 11 | TRUE) 12 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test12.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | intExp(0), 5 | TRUE), 6 | decList()), 7 | seqExp( 8 | expList( 9 | forExp(i, 10 | intExp(0), 11 | intExp(100), 12 | seqExp( 13 | expList( 14 | assignExp( 15 | simpleVar(a), 16 | opExp( 17 | PLUS, 18 | varExp( 19 | simpleVar(a)), 20 | intExp(1))), 21 | expList( 22 | voidExp(), 23 | expList()))), 24 | TRUE), 25 | expList()))) 26 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test13.out: -------------------------------------------------------------------------------- 1 | opExp( 2 | GREAT, 3 | intExp(3), 4 | stringExp(df)) 5 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test14.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(arrtype, 6 | arrayTy(int)), 7 | nameAndTyList( 8 | nameAndTy(rectype, 9 | recordTy( 10 | fieldList( 11 | field(name, 12 | string, 13 | TRUE), 14 | fieldList( 15 | field(id, 16 | int, 17 | TRUE), 18 | fieldList())))), 19 | nameAndTyList()))), 20 | decList( 21 | varDec(rec, 22 | recordExp(rectype, 23 | efieldList( 24 | efield(name, 25 | stringExp(aname)), 26 | efieldList( 27 | efield(id, 28 | intExp(0)), 29 | efieldList()))), 30 | TRUE), 31 | decList( 32 | varDec(arr, 33 | arrayExp(arrtype, 34 | intExp(3), 35 | intExp(0)), 36 | TRUE), 37 | decList()))), 38 | seqExp( 39 | expList( 40 | iffExp( 41 | opExp( 42 | NOTEQUAL, 43 | varExp( 44 | simpleVar(rec)), 45 | varExp( 46 | simpleVar(arr))), 47 | intExp(3), 48 | intExp(4)), 49 | expList()))) 50 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test15.out: -------------------------------------------------------------------------------- 1 | iffExp( 2 | intExp(20), 3 | intExp(3)) 4 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test16.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(a, 6 | nameTy(c)), 7 | nameAndTyList( 8 | nameAndTy(b, 9 | nameTy(a)), 10 | nameAndTyList( 11 | nameAndTy(c, 12 | nameTy(d)), 13 | nameAndTyList( 14 | nameAndTy(d, 15 | nameTy(a)), 16 | nameAndTyList()))))), 17 | decList()), 18 | seqExp( 19 | expList( 20 | stringExp(), 21 | expList()))) 22 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test17.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(tree, 6 | recordTy( 7 | fieldList( 8 | field(key, 9 | int, 10 | TRUE), 11 | fieldList( 12 | field(children, 13 | treelist, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(d, 19 | int, 20 | intExp(0), 21 | TRUE), 22 | decList( 23 | typeDec( 24 | nameAndTyList( 25 | nameAndTy(treelist, 26 | recordTy( 27 | fieldList( 28 | field(hd, 29 | tree, 30 | TRUE), 31 | fieldList( 32 | field(tl, 33 | treelist, 34 | TRUE), 35 | fieldList())))), 36 | nameAndTyList())), 37 | decList()))), 38 | seqExp( 39 | expList( 40 | varExp( 41 | simpleVar(d)), 42 | expList()))) 43 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test18.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(do_nothing1, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | int, 16 | seqExp( 17 | expList( 18 | callExp(do_nothing2, 19 | expList( 20 | opExp( 21 | PLUS, 22 | varExp( 23 | simpleVar(a)), 24 | intExp(1)), 25 | expList())), 26 | expList( 27 | intExp(0), 28 | expList())))), 29 | fundecList())), 30 | decList( 31 | varDec(d, 32 | intExp(0), 33 | TRUE), 34 | decList( 35 | functionDec( 36 | fundecList( 37 | fundec(do_nothing2, 38 | fieldList( 39 | field(d, 40 | int, 41 | TRUE), 42 | fieldList()), 43 | string, 44 | seqExp( 45 | expList( 46 | callExp(do_nothing1, 47 | expList( 48 | varExp( 49 | simpleVar(d)), 50 | expList( 51 | stringExp(str), 52 | expList()))), 53 | expList( 54 | stringExp( ), 55 | expList())))), 56 | fundecList())), 57 | decList()))), 58 | seqExp( 59 | expList( 60 | callExp(do_nothing1, 61 | expList( 62 | intExp(0), 63 | expList( 64 | stringExp(str2), 65 | expList()))), 66 | expList()))) 67 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test19.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(do_nothing1, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | int, 16 | seqExp( 17 | expList( 18 | callExp(do_nothing2, 19 | expList( 20 | opExp( 21 | PLUS, 22 | varExp( 23 | simpleVar(a)), 24 | intExp(1)), 25 | expList())), 26 | expList( 27 | intExp(0), 28 | expList())))), 29 | fundecList( 30 | fundec(do_nothing2, 31 | fieldList( 32 | field(d, 33 | int, 34 | TRUE), 35 | fieldList()), 36 | string, 37 | seqExp( 38 | expList( 39 | callExp(do_nothing1, 40 | expList( 41 | varExp( 42 | simpleVar(a)), 43 | expList( 44 | stringExp(str), 45 | expList()))), 46 | expList( 47 | stringExp( ), 48 | expList())))), 49 | fundecList()))), 50 | decList()), 51 | seqExp( 52 | expList( 53 | callExp(do_nothing1, 54 | expList( 55 | intExp(0), 56 | expList( 57 | stringExp(str2), 58 | expList()))), 59 | expList()))) 60 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test2.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(myint, 6 | nameTy(int)), 7 | nameAndTyList( 8 | nameAndTy(arrtype, 9 | arrayTy(myint)), 10 | nameAndTyList()))), 11 | decList( 12 | varDec(arr1, 13 | arrtype, 14 | arrayExp(arrtype, 15 | intExp(10), 16 | intExp(0)), 17 | TRUE), 18 | decList())), 19 | seqExp( 20 | expList( 21 | varExp( 22 | simpleVar(arr1)), 23 | expList()))) 24 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test20.out: -------------------------------------------------------------------------------- 1 | whileExp( 2 | opExp( 3 | GREAT, 4 | intExp(10), 5 | intExp(5)), 6 | seqExp( 7 | expList( 8 | opExp( 9 | PLUS, 10 | varExp( 11 | simpleVar(i)), 12 | intExp(1)), 13 | expList( 14 | voidExp(), 15 | expList())))) 16 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test21.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(nfactor, 6 | fieldList( 7 | field(n, 8 | int, 9 | TRUE), 10 | fieldList()), 11 | iffExp( 12 | opExp( 13 | EQUAL, 14 | varExp( 15 | simpleVar(n)), 16 | intExp(0)), 17 | intExp(1), 18 | opExp( 19 | TIMES, 20 | varExp( 21 | simpleVar(n)), 22 | callExp(nfactor, 23 | expList( 24 | opExp( 25 | MINUS, 26 | varExp( 27 | simpleVar(n)), 28 | intExp(1)), 29 | expList()))))), 30 | fundecList())), 31 | decList()), 32 | seqExp( 33 | expList( 34 | callExp(nfactor, 35 | expList( 36 | intExp(10), 37 | expList())), 38 | expList()))) 39 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test22.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(id, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(rec1, 19 | recordExp(rectype, 20 | efieldList( 21 | efield(name, 22 | stringExp(Name)), 23 | efieldList( 24 | efield(id, 25 | intExp(0)), 26 | efieldList()))), 27 | TRUE), 28 | decList())), 29 | seqExp( 30 | expList( 31 | assignExp( 32 | fieldVar( 33 | simpleVar(rec1), 34 | nam), 35 | stringExp(asd)), 36 | expList()))) 37 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test23.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(id, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(rec1, 19 | recordExp(rectype, 20 | efieldList( 21 | efield(name, 22 | stringExp(aname)), 23 | efieldList( 24 | efield(id, 25 | intExp(0)), 26 | efieldList()))), 27 | TRUE), 28 | decList())), 29 | seqExp( 30 | expList( 31 | assignExp( 32 | fieldVar( 33 | simpleVar(rec1), 34 | name), 35 | intExp(3)), 36 | expList( 37 | assignExp( 38 | fieldVar( 39 | simpleVar(rec1), 40 | id), 41 | stringExp()), 42 | expList())))) 43 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test24.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(d, 4 | intExp(0), 5 | TRUE), 6 | decList()), 7 | seqExp( 8 | expList( 9 | varExp( 10 | subscriptVar( 11 | simpleVar(d), 12 | intExp(3))), 13 | expList()))) 14 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test25.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(d, 4 | intExp(0), 5 | TRUE), 6 | decList()), 7 | seqExp( 8 | expList( 9 | varExp( 10 | fieldVar( 11 | simpleVar(d), 12 | f)), 13 | expList()))) 14 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test26.out: -------------------------------------------------------------------------------- 1 | opExp( 2 | PLUS, 3 | intExp(3), 4 | stringExp(var)) 5 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test27.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | intExp(0), 5 | TRUE), 6 | decList( 7 | functionDec( 8 | fundecList( 9 | fundec(g, 10 | fieldList( 11 | field(a, 12 | int, 13 | TRUE), 14 | fieldList()), 15 | int, 16 | varExp( 17 | simpleVar(a))), 18 | fundecList())), 19 | decList())), 20 | seqExp( 21 | expList( 22 | callExp(g, 23 | expList( 24 | intExp(2), 25 | expList())), 26 | expList()))) 27 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test28.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype1, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(id, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList( 17 | nameAndTy(rectype2, 18 | recordTy( 19 | fieldList( 20 | field(name, 21 | string, 22 | TRUE), 23 | fieldList( 24 | field(id, 25 | int, 26 | TRUE), 27 | fieldList())))), 28 | nameAndTyList()))), 29 | decList( 30 | varDec(rec1, 31 | rectype1, 32 | recordExp(rectype2, 33 | efieldList( 34 | efield(name, 35 | stringExp(Name)), 36 | efieldList( 37 | efield(id, 38 | intExp(0)), 39 | efieldList()))), 40 | TRUE), 41 | decList())), 42 | seqExp( 43 | expList( 44 | varExp( 45 | simpleVar(rec1)), 46 | expList()))) 47 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test29.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(arrtype1, 6 | arrayTy(int)), 7 | nameAndTyList( 8 | nameAndTy(arrtype2, 9 | arrayTy(int)), 10 | nameAndTyList()))), 11 | decList( 12 | varDec(arr1, 13 | arrtype1, 14 | arrayExp(arrtype2, 15 | intExp(10), 16 | intExp(0)), 17 | TRUE), 18 | decList())), 19 | seqExp( 20 | expList( 21 | varExp( 22 | simpleVar(arr1)), 23 | expList()))) 24 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test3.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(age, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(rec1, 19 | rectype, 20 | recordExp(rectype, 21 | efieldList( 22 | efield(name, 23 | stringExp(Nobody)), 24 | efieldList( 25 | efield(age, 26 | intExp(1000)), 27 | efieldList()))), 28 | TRUE), 29 | decList())), 30 | seqExp( 31 | expList( 32 | assignExp( 33 | fieldVar( 34 | simpleVar(rec1), 35 | name), 36 | stringExp(Somebody)), 37 | expList( 38 | varExp( 39 | simpleVar(rec1)), 40 | expList())))) 41 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test30.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(a, 6 | arrayTy(int)), 7 | nameAndTyList( 8 | nameAndTy(b, 9 | nameTy(a)), 10 | nameAndTyList()))), 11 | decList( 12 | varDec(arr1, 13 | a, 14 | arrayExp(b, 15 | intExp(10), 16 | intExp(0)), 17 | TRUE), 18 | decList())), 19 | seqExp( 20 | expList( 21 | varExp( 22 | subscriptVar( 23 | simpleVar(arr1), 24 | intExp(2))), 25 | expList()))) 26 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test31.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | int, 5 | stringExp( ), 6 | TRUE), 7 | decList()), 8 | seqExp( 9 | expList( 10 | varExp( 11 | simpleVar(a)), 12 | expList()))) 13 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test32.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(arrayty, 6 | arrayTy(int)), 7 | nameAndTyList())), 8 | decList( 9 | varDec(a, 10 | arrayExp(arrayty, 11 | intExp(10), 12 | stringExp( )), 13 | TRUE), 14 | decList())), 15 | seqExp( 16 | expList( 17 | intExp(0), 18 | expList()))) 19 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test33.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | recordExp(rectype, 5 | efieldList()), 6 | TRUE), 7 | decList()), 8 | seqExp( 9 | expList( 10 | intExp(0), 11 | expList()))) 12 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test34.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | int, 16 | varExp( 17 | simpleVar(a))), 18 | fundecList())), 19 | decList()), 20 | seqExp( 21 | expList( 22 | callExp(g, 23 | expList( 24 | stringExp(one), 25 | expList( 26 | stringExp(two), 27 | expList()))), 28 | expList()))) 29 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test35.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | int, 16 | varExp( 17 | simpleVar(a))), 18 | fundecList())), 19 | decList()), 20 | seqExp( 21 | expList( 22 | callExp(g, 23 | expList( 24 | stringExp(one), 25 | expList())), 26 | expList()))) 27 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test36.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | int, 16 | varExp( 17 | simpleVar(a))), 18 | fundecList())), 19 | decList()), 20 | seqExp( 21 | expList( 22 | callExp(g, 23 | expList( 24 | intExp(3), 25 | expList( 26 | stringExp(one), 27 | expList( 28 | intExp(5), 29 | expList())))), 30 | expList()))) 31 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test37.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | intExp(0), 5 | TRUE), 6 | decList( 7 | varDec(a, 8 | stringExp( ), 9 | TRUE), 10 | decList())), 11 | seqExp( 12 | expList( 13 | intExp(0), 14 | expList()))) 15 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test38.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(a, 6 | nameTy(int)), 7 | nameAndTyList( 8 | nameAndTy(a, 9 | nameTy(string)), 10 | nameAndTyList()))), 11 | decList()), 12 | seqExp( 13 | expList( 14 | intExp(0), 15 | expList()))) 16 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test39.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList()), 11 | int, 12 | varExp( 13 | simpleVar(a))), 14 | fundecList( 15 | fundec(g, 16 | fieldList( 17 | field(a, 18 | int, 19 | TRUE), 20 | fieldList()), 21 | int, 22 | varExp( 23 | simpleVar(a))), 24 | fundecList()))), 25 | decList()), 26 | seqExp( 27 | expList( 28 | intExp(0), 29 | expList()))) 30 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test4.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(nfactor, 6 | fieldList( 7 | field(n, 8 | int, 9 | TRUE), 10 | fieldList()), 11 | int, 12 | iffExp( 13 | opExp( 14 | EQUAL, 15 | varExp( 16 | simpleVar(n)), 17 | intExp(0)), 18 | intExp(1), 19 | opExp( 20 | TIMES, 21 | varExp( 22 | simpleVar(n)), 23 | callExp(nfactor, 24 | expList( 25 | opExp( 26 | MINUS, 27 | varExp( 28 | simpleVar(n)), 29 | intExp(1)), 30 | expList()))))), 31 | fundecList())), 32 | decList()), 33 | seqExp( 34 | expList( 35 | callExp(nfactor, 36 | expList( 37 | intExp(10), 38 | expList())), 39 | expList()))) 40 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test40.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList()), 11 | varExp( 12 | simpleVar(a))), 13 | fundecList())), 14 | decList()), 15 | seqExp( 16 | expList( 17 | callExp(g, 18 | expList( 19 | intExp(2), 20 | expList())), 21 | expList()))) 22 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test41.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(a, 6 | nameTy(int)), 7 | nameAndTyList())), 8 | decList()), 9 | seqExp( 10 | expList( 11 | letExp( 12 | decList( 13 | typeDec( 14 | nameAndTyList( 15 | nameAndTy(a, 16 | nameTy(string)), 17 | nameAndTyList())), 18 | decList()), 19 | seqExp( 20 | expList( 21 | intExp(0), 22 | expList()))), 23 | expList()))) 24 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test43.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | voidExp(), 5 | TRUE), 6 | decList()), 7 | seqExp( 8 | expList( 9 | opExp( 10 | PLUS, 11 | varExp( 12 | simpleVar(a)), 13 | intExp(3)), 14 | expList()))) 15 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test44.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(id, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(b, 19 | rectype, 20 | nilExp(), 21 | TRUE), 22 | decList())), 23 | seqExp( 24 | expList( 25 | assignExp( 26 | simpleVar(b), 27 | nilExp()), 28 | expList()))) 29 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test45.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(id, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(a, 19 | nilExp(), 20 | TRUE), 21 | decList())), 22 | seqExp( 23 | expList( 24 | varExp( 25 | simpleVar(a)), 26 | expList()))) 27 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test46.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(rectype, 6 | recordTy( 7 | fieldList( 8 | field(name, 9 | string, 10 | TRUE), 11 | fieldList( 12 | field(id, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(b, 19 | rectype, 20 | nilExp(), 21 | TRUE), 22 | decList())), 23 | seqExp( 24 | expList( 25 | opExp( 26 | EQUAL, 27 | varExp( 28 | simpleVar(b)), 29 | nilExp()), 30 | expList( 31 | opExp( 32 | NOTEQUAL, 33 | varExp( 34 | simpleVar(b)), 35 | nilExp()), 36 | expList())))) 37 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test47.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(a, 6 | nameTy(int)), 7 | nameAndTyList())), 8 | decList( 9 | varDec(b, 10 | intExp(4), 11 | TRUE), 12 | decList( 13 | typeDec( 14 | nameAndTyList( 15 | nameAndTy(a, 16 | nameTy(string)), 17 | nameAndTyList())), 18 | decList()))), 19 | seqExp( 20 | expList( 21 | intExp(0), 22 | expList()))) 23 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test48.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList()), 11 | int, 12 | varExp( 13 | simpleVar(a))), 14 | fundecList())), 15 | decList( 16 | typeDec( 17 | nameAndTyList( 18 | nameAndTy(t, 19 | nameTy(int)), 20 | nameAndTyList())), 21 | decList( 22 | functionDec( 23 | fundecList( 24 | fundec(g, 25 | fieldList( 26 | field(a, 27 | int, 28 | TRUE), 29 | fieldList()), 30 | int, 31 | varExp( 32 | simpleVar(a))), 33 | fundecList())), 34 | decList()))), 35 | seqExp( 36 | expList( 37 | intExp(0), 38 | expList()))) 39 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test49.out: -------------------------------------------------------------------------------- 1 | testcases/test49.tig:5.18: syntax error 2 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test5.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(intlist, 6 | recordTy( 7 | fieldList( 8 | field(hd, 9 | int, 10 | TRUE), 11 | fieldList( 12 | field(tl, 13 | intlist, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList( 17 | nameAndTy(tree, 18 | recordTy( 19 | fieldList( 20 | field(key, 21 | int, 22 | TRUE), 23 | fieldList( 24 | field(children, 25 | treelist, 26 | TRUE), 27 | fieldList())))), 28 | nameAndTyList( 29 | nameAndTy(treelist, 30 | recordTy( 31 | fieldList( 32 | field(hd, 33 | tree, 34 | TRUE), 35 | fieldList( 36 | field(tl, 37 | treelist, 38 | TRUE), 39 | fieldList())))), 40 | nameAndTyList())))), 41 | decList( 42 | varDec(lis, 43 | intlist, 44 | recordExp(intlist, 45 | efieldList( 46 | efield(hd, 47 | intExp(0)), 48 | efieldList( 49 | efield(tl, 50 | nilExp()), 51 | efieldList()))), 52 | TRUE), 53 | decList())), 54 | seqExp( 55 | expList( 56 | varExp( 57 | simpleVar(lis)), 58 | expList()))) 59 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test6.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(do_nothing1, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | callExp(do_nothing2, 16 | expList( 17 | opExp( 18 | PLUS, 19 | varExp( 20 | simpleVar(a)), 21 | intExp(1)), 22 | expList()))), 23 | fundecList( 24 | fundec(do_nothing2, 25 | fieldList( 26 | field(d, 27 | int, 28 | TRUE), 29 | fieldList()), 30 | callExp(do_nothing1, 31 | expList( 32 | varExp( 33 | simpleVar(d)), 34 | expList( 35 | stringExp(str), 36 | expList())))), 37 | fundecList()))), 38 | decList()), 39 | seqExp( 40 | expList( 41 | callExp(do_nothing1, 42 | expList( 43 | intExp(0), 44 | expList( 45 | stringExp(str2), 46 | expList()))), 47 | expList()))) 48 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test7.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(do_nothing1, 6 | fieldList( 7 | field(a, 8 | int, 9 | TRUE), 10 | fieldList( 11 | field(b, 12 | string, 13 | TRUE), 14 | fieldList())), 15 | int, 16 | seqExp( 17 | expList( 18 | callExp(do_nothing2, 19 | expList( 20 | opExp( 21 | PLUS, 22 | varExp( 23 | simpleVar(a)), 24 | intExp(1)), 25 | expList())), 26 | expList( 27 | intExp(0), 28 | expList())))), 29 | fundecList( 30 | fundec(do_nothing2, 31 | fieldList( 32 | field(d, 33 | int, 34 | TRUE), 35 | fieldList()), 36 | string, 37 | seqExp( 38 | expList( 39 | callExp(do_nothing1, 40 | expList( 41 | varExp( 42 | simpleVar(d)), 43 | expList( 44 | stringExp(str), 45 | expList()))), 46 | expList( 47 | stringExp( ), 48 | expList())))), 49 | fundecList()))), 50 | decList()), 51 | seqExp( 52 | expList( 53 | callExp(do_nothing1, 54 | expList( 55 | intExp(0), 56 | expList( 57 | stringExp(str2), 58 | expList()))), 59 | expList()))) 60 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test8.out: -------------------------------------------------------------------------------- 1 | iffExp( 2 | opExp( 3 | GREAT, 4 | intExp(10), 5 | intExp(20)), 6 | intExp(30), 7 | intExp(40)) 8 | -------------------------------------------------------------------------------- /testdata/lab3/refs/test9.out: -------------------------------------------------------------------------------- 1 | iffExp( 2 | opExp( 3 | GREAT, 4 | intExp(5), 5 | intExp(4)), 6 | intExp(13), 7 | stringExp( )) 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/merge.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | type any = {any : int} 4 | var buffer := getchar() 5 | 6 | function readint(any: any) : int = 7 | let var i := 0 8 | function isdigit(s : string) : int = 9 | ord(buffer)>=ord("0") & ord(buffer)<=ord("9") 10 | function skipto() = 11 | while buffer=" " | buffer="\n" 12 | do buffer := getchar() 13 | in skipto(); 14 | any.any := isdigit(buffer); 15 | while isdigit(buffer) 16 | do (i := i*10+ord(buffer)-ord("0"); buffer := getchar()); 17 | i 18 | end 19 | 20 | type list = {first: int, rest: list} 21 | 22 | function readlist() : list = 23 | let var any := any{any=0} 24 | var i := readint(any) 25 | in if any.any 26 | then list{first=i,rest=readlist()} 27 | else nil 28 | end 29 | 30 | function merge(a: list, b: list) : list = 31 | if a=nil then b 32 | else if b=nil then a 33 | else if a.first < b.first 34 | then list{first=a.first,rest=merge(a.rest,b)} 35 | else list{first=b.first,rest=merge(a,b.rest)} 36 | 37 | function printint(i: int) = 38 | let function f(i:int) = if i>0 39 | then (f(i/10); print(chr(i-i/10*10+ord("0")))) 40 | in if i<0 then (print("-"); f(-i)) 41 | else if i>0 then f(i) 42 | else print("0") 43 | end 44 | 45 | function printlist(l: list) = 46 | if l=nil then print("\n") 47 | else (printint(l.first); print(" "); printlist(l.rest)) 48 | 49 | var list1 := readlist() 50 | var list2 := (buffer:=getchar(); readlist()) 51 | 52 | 53 | /* BODY OF MAIN PROGRAM */ 54 | in printlist(merge(list1,list2)) 55 | end 56 | 57 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/queens.tig: -------------------------------------------------------------------------------- 1 | /* A program to solve the 8-queens problem */ 2 | 3 | let 4 | var N := 8 5 | 6 | type intArray = array of int 7 | 8 | var row := intArray [ N ] of 0 9 | var col := intArray [ N ] of 0 10 | var diag1 := intArray [N+N-1] of 0 11 | var diag2 := intArray [N+N-1] of 0 12 | 13 | function printboard() = 14 | (for i := 0 to N-1 15 | do (for j := 0 to N-1 16 | do print(if col[i]=j then " O" else " ."); 17 | print("\n")); 18 | print("\n")) 19 | 20 | function try(c:int) = 21 | ( /* for i:= 0 to c do print("."); print("\n"); flush();*/ 22 | if c=N 23 | then printboard() 24 | else for r := 0 to N-1 25 | do if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0 26 | then (row[r]:=1; diag1[r+c]:=1; diag2[r+7-c]:=1; 27 | col[c]:=r; 28 | try(c+1); 29 | row[r]:=0; diag1[r+c]:=0; diag2[r+7-c]:=0) 30 | 31 | ) 32 | in try(0) 33 | end 34 | 35 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test1.tig: -------------------------------------------------------------------------------- 1 | /* an array type and an array variable */ 2 | let 3 | type arrtype = array of int 4 | var arr1:arrtype := arrtype [10] of 0 5 | in 6 | arr1 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test10.tig: -------------------------------------------------------------------------------- 1 | /* error : body of while not unit */ 2 | while(10 > 5) do 5+6 3 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test11.tig: -------------------------------------------------------------------------------- 1 | /* error hi expr is not int, and index variable erroneously assigned to. */ 2 | for i:=10 to " " do 3 | i := i - 1 4 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test12.tig: -------------------------------------------------------------------------------- 1 | /* valid for and let */ 2 | 3 | let 4 | var a:= 0 5 | in 6 | for i:=0 to 100 do (a:=a+1;()) 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test13.tig: -------------------------------------------------------------------------------- 1 | /* error: comparison of incompatible types */ 2 | 3 | 3 > "df" 4 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test14.tig: -------------------------------------------------------------------------------- 1 | /* error : compare rec with array */ 2 | 3 | let 4 | 5 | type arrtype = array of int 6 | type rectype = {name:string, id: int} 7 | 8 | var rec := rectype {name="aname", id=0} 9 | var arr := arrtype [3] of 0 10 | 11 | in 12 | if rec <> arr then 3 else 4 13 | end 14 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test15.tig: -------------------------------------------------------------------------------- 1 | /* error : if-then returns non unit */ 2 | 3 | if 20 then 3 4 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test16.tig: -------------------------------------------------------------------------------- 1 | /* error: mutually recursive types thet do not pass through record or array */ 2 | let 3 | 4 | type a=c 5 | type b=a 6 | type c=d 7 | type d=a 8 | 9 | in 10 | "" 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test17.tig: -------------------------------------------------------------------------------- 1 | /* error: definition of recursive types is interrupted */ 2 | let 3 | /* define a tree */ 4 | type tree ={key: int, children: treelist} 5 | var d:int :=0 6 | type treelist = {hd: tree, tl: treelist} 7 | 8 | in 9 | d 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test18.tig: -------------------------------------------------------------------------------- 1 | /* error : definition of recursive functions is interrupted */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | var d:=0 8 | 9 | function do_nothing2(d: int):string = 10 | (do_nothing1(d, "str");" ") 11 | 12 | in 13 | do_nothing1(0, "str2") 14 | end 15 | 16 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test19.tig: -------------------------------------------------------------------------------- 1 | /* error : second function uses variables local to the first one, undeclared variable */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(a, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test2.tig: -------------------------------------------------------------------------------- 1 | /* arr1 is valid since expression 0 is int = myint */ 2 | let 3 | type myint = int 4 | type arrtype = array of myint 5 | 6 | var arr1:arrtype := arrtype [10] of 0 7 | in 8 | arr1 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test20.tig: -------------------------------------------------------------------------------- 1 | /* error: undeclared variable i */ 2 | 3 | while 10 > 5 do (i+1;()) 4 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test21.tig: -------------------------------------------------------------------------------- 1 | /* error : procedure returns value and procedure is used in arexpr */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int) = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | nfactor(10) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test22.tig: -------------------------------------------------------------------------------- 1 | /* error : field not in record type */ 2 | 3 | let 4 | type rectype = {name:string , id:int} 5 | var rec1 := rectype {name="Name", id=0} 6 | in 7 | rec1.nam := "asd" 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test23.tig: -------------------------------------------------------------------------------- 1 | /* error : type mismatch */ 2 | 3 | let 4 | type rectype = {name:string , id:int} 5 | var rec1 := rectype {name="aname", id=0} 6 | in 7 | rec1.name := 3; 8 | rec1.id := "" 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test24.tig: -------------------------------------------------------------------------------- 1 | /* error : variable not array */ 2 | let 3 | var d:=0 4 | in 5 | d[3] 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test25.tig: -------------------------------------------------------------------------------- 1 | /* error : variable not record */ 2 | let 3 | var d:=0 4 | in 5 | d.f 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test26.tig: -------------------------------------------------------------------------------- 1 | /* error : integer required */ 2 | 3 | 3 + "var" 4 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test27.tig: -------------------------------------------------------------------------------- 1 | /* locals hide globals */ 2 | let 3 | var a:=0 4 | 5 | function g(a:int):int = a 6 | in 7 | g(2) 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test28.tig: -------------------------------------------------------------------------------- 1 | /* error : different record types */ 2 | 3 | let 4 | type rectype1 = {name:string , id:int} 5 | type rectype2 = {name:string , id:int} 6 | 7 | var rec1: rectype1 := rectype2 {name="Name", id=0} 8 | in 9 | rec1 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test29.tig: -------------------------------------------------------------------------------- 1 | /* error : different array types */ 2 | 3 | let 4 | type arrtype1 = array of int 5 | type arrtype2 = array of int 6 | 7 | var arr1: arrtype1 := arrtype2 [10] of 0 8 | in 9 | arr1 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test3.tig: -------------------------------------------------------------------------------- 1 | /* a record type and a record variable */ 2 | let 3 | type rectype = {name:string, age:int} 4 | var rec1:rectype := rectype {name="Nobody", age=1000} 5 | in 6 | rec1.name := "Somebody"; 7 | rec1 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test30.tig: -------------------------------------------------------------------------------- 1 | /* synonyms are fine */ 2 | 3 | let 4 | type a = array of int 5 | type b = a 6 | 7 | var arr1:a := b [10] of 0 8 | in 9 | arr1[2] 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test31.tig: -------------------------------------------------------------------------------- 1 | /* error : type constraint and init value differ */ 2 | let 3 | var a:int := " " 4 | in 5 | a 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test32.tig: -------------------------------------------------------------------------------- 1 | /* error : initializing exp and array type differ */ 2 | 3 | let 4 | type arrayty = array of int 5 | 6 | var a := arrayty [10] of " " 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test33.tig: -------------------------------------------------------------------------------- 1 | /* error : unknown type */ 2 | let 3 | var a:= rectype {} 4 | in 5 | 0 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test34.tig: -------------------------------------------------------------------------------- 1 | /* error : formals and actuals have different types */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g("one", "two") 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test35.tig: -------------------------------------------------------------------------------- 1 | /* error : formals are more then actuals */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g("one") 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test36.tig: -------------------------------------------------------------------------------- 1 | /* error : formals are fewer then actuals */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g(3,"one",5) 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test37.tig: -------------------------------------------------------------------------------- 1 | /* redeclaration of variable; this is legal, there are two different 2 | variables with the same name. The second one hides the first. */ 3 | let 4 | var a := 0 5 | var a := " " 6 | in 7 | 0 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test38.tig: -------------------------------------------------------------------------------- 1 | /* This is illegal, since there are two types with the same name 2 | in the same (consecutive) batch of mutually recursive types. 3 | See also test47 */ 4 | let 5 | type a = int 6 | type a = string 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test39.tig: -------------------------------------------------------------------------------- 1 | /* This is illegal, since there are two functions with the same name 2 | in the same (consecutive) batch of mutually recursive functions. 3 | See also test48 */ 4 | let 5 | function g(a:int):int = a 6 | function g(a:int):int = a 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test4.tig: -------------------------------------------------------------------------------- 1 | /* define a recursive function */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int): int = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | nfactor(10) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test40.tig: -------------------------------------------------------------------------------- 1 | /* error : procedure returns value */ 2 | let 3 | function g(a:int) = a 4 | in 5 | g(2) 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test41.tig: -------------------------------------------------------------------------------- 1 | /* local types hide global */ 2 | let 3 | type a = int 4 | in 5 | let 6 | type a = string 7 | in 8 | 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test42.tig: -------------------------------------------------------------------------------- 1 | /* correct declarations */ 2 | let 3 | 4 | type arrtype1 = array of int 5 | type rectype1 = {name:string, address:string, id: int , age: int} 6 | type arrtype2 = array of rectype1 7 | type rectype2 = {name : string, dates: arrtype1} 8 | 9 | type arrtype3 = array of string 10 | 11 | var arr1 := arrtype1 [10] of 0 12 | var arr2 := arrtype2 [5] of rectype1 {name="aname", address="somewhere", id=0, age=0} 13 | var arr3:arrtype3 := arrtype3 [100] of "" 14 | 15 | var rec1 := rectype1 {name="Kapoios", address="Kapou", id=02432, age=44} 16 | var rec2 := rectype2 {name="Allos", dates= arrtype1 [3] of 1900} 17 | 18 | in 19 | 20 | arr1[0] := 1; 21 | arr1[9] := 3; 22 | arr2[3].name := "kati"; 23 | arr2[1].age := 23; 24 | arr3[34] := "sfd"; 25 | 26 | rec1.name := "sdf"; 27 | rec2.dates[0] := 2323; 28 | rec2.dates[2] := 2323 29 | 30 | end 31 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test43.tig: -------------------------------------------------------------------------------- 1 | /* initialize with unit and causing type mismatch in addition */ 2 | 3 | let 4 | var a := () 5 | in 6 | a + 3 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test44.tig: -------------------------------------------------------------------------------- 1 | /* valid nil initialization and assignment */ 2 | let 3 | 4 | type rectype = {name:string, id:int} 5 | var b:rectype := nil 6 | 7 | in 8 | 9 | b := nil 10 | 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test45.tig: -------------------------------------------------------------------------------- 1 | /* error: initializing nil expressions not constrained by record type */ 2 | let 3 | type rectype = {name:string, id:int} 4 | 5 | var a:= nil 6 | in 7 | a 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test46.tig: -------------------------------------------------------------------------------- 1 | /* valid rec comparisons */ 2 | let 3 | type rectype = {name:string, id:int} 4 | var b:rectype := nil 5 | in 6 | b = nil; 7 | b <> nil 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test47.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second type "a" simply hides the first one. 2 | Because of the intervening variable declaration, the two "a" types 3 | are not in the same batch of mutually recursive types. 4 | See also test38 */ 5 | let 6 | type a = int 7 | var b := 4 8 | type a = string 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test48.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second function "g" simply hides the first one. 2 | Because of the intervening variable declaration, the two "g" functions 3 | are not in the same batch of mutually recursive functions. 4 | See also test39 */ 5 | let 6 | function g(a:int):int = a 7 | type t = int 8 | function g(a:int):int = a 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test49.tig: -------------------------------------------------------------------------------- 1 | /* error: syntax error, nil should not be preceded by type-id. */ 2 | let 3 | type rectype = {name:string, id:int} 4 | 5 | var a:= rectype nil 6 | in 7 | a 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test5.tig: -------------------------------------------------------------------------------- 1 | /* define valid recursive types */ 2 | let 3 | /* define a list */ 4 | type intlist = {hd: int, tl: intlist} 5 | 6 | /* define a tree */ 7 | type tree ={key: int, children: treelist} 8 | type treelist = {hd: tree, tl: treelist} 9 | 10 | var lis:intlist := intlist { hd=0, tl= nil } 11 | 12 | in 13 | lis 14 | end 15 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test6.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive procedures */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string)= 5 | do_nothing2(a+1) 6 | 7 | function do_nothing2(d: int) = 8 | do_nothing1(d, "str") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test7.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive functions */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(d, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test8.tig: -------------------------------------------------------------------------------- 1 | /* correct if */ 2 | if (10 > 20) then 30 else 40 3 | -------------------------------------------------------------------------------- /testdata/lab3/testcases/test9.tig: -------------------------------------------------------------------------------- 1 | /* error : types of then - else differ */ 2 | 3 | if (5>4) then 13 else " " 4 | -------------------------------------------------------------------------------- /testdata/lab4/refs/merge.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/merge.out -------------------------------------------------------------------------------- /testdata/lab4/refs/queens.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/queens.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test1.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test1.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test10.out: -------------------------------------------------------------------------------- 1 | test10.tig:2.21:while body must produce no value 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test11.out: -------------------------------------------------------------------------------- 1 | test11.tig:2.16:for exp's range type is not integer 2 | test11.tig:3.12:loop variable can't be assigned 3 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test12.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test12.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test13.out: -------------------------------------------------------------------------------- 1 | test13.tig:3.9:same type required 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test14.out: -------------------------------------------------------------------------------- 1 | test14.tig:12.16:same type required 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test15.out: -------------------------------------------------------------------------------- 1 | test15.tig:3.12:if-then exp's body must produce no value 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test16.out: -------------------------------------------------------------------------------- 1 | test16.tig:4.8:illegal type cycle 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test17.out: -------------------------------------------------------------------------------- 1 | test17.tig:4.31: undefined type treelist 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test18.out: -------------------------------------------------------------------------------- 1 | test18.tig:5.19:undefined function do_nothing2 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test19.out: -------------------------------------------------------------------------------- 1 | test19.tig:8.17:undefined variable a 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test2.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test2.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test20.out: -------------------------------------------------------------------------------- 1 | test20.tig:3.19:undefined variable i 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test21.out: -------------------------------------------------------------------------------- 1 | test21.tig:8.24:integer required 2 | test21.tig:10.1:procedure returns value 3 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test22.out: -------------------------------------------------------------------------------- 1 | test22.tig:7.7:field nam doesn't exist 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test23.out: -------------------------------------------------------------------------------- 1 | test23.tig:7.16:unmatched assign exp 2 | test23.tig:9.1:unmatched assign exp 3 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test24.out: -------------------------------------------------------------------------------- 1 | test24.tig:6.1:array type required 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test25.out: -------------------------------------------------------------------------------- 1 | test25.tig:5.4:not a record type 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test26.out: -------------------------------------------------------------------------------- 1 | test26.tig:3.9:integer required 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test27.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test27.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test28.out: -------------------------------------------------------------------------------- 1 | test28.tig:7.51:type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test29.out: -------------------------------------------------------------------------------- 1 | test29.tig:8.1:type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test3.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test3.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test30.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test30.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test31.out: -------------------------------------------------------------------------------- 1 | test31.tig:3.17:type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test32.out: -------------------------------------------------------------------------------- 1 | test32.tig:6.29:type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test33.out: -------------------------------------------------------------------------------- 1 | test33.tig:3.19:undefined type rectype 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test34.out: -------------------------------------------------------------------------------- 1 | test34.tig:5.8:para type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test35.out: -------------------------------------------------------------------------------- 1 | test35.tig:5.8:para type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test36.out: -------------------------------------------------------------------------------- 1 | test36.tig:5.10:too many params in function g 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test37.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test37.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test38.out: -------------------------------------------------------------------------------- 1 | test38.tig:5.11:two types have the same name 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test39.out: -------------------------------------------------------------------------------- 1 | test39.tig:6.2:two functions have the same name 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test4.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test4.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test40.out: -------------------------------------------------------------------------------- 1 | test40.tig:4.1:procedure returns value 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test41.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test41.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test42.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test42.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test43.out: -------------------------------------------------------------------------------- 1 | test43.tig:6.4:integer required 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test44.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test44.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test45.out: -------------------------------------------------------------------------------- 1 | test45.tig:6.1:init should not be nil without type specified 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test46.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test46.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test47.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test47.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test48.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test48.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test49.out: -------------------------------------------------------------------------------- 1 | test49.tig::syntax error 2 | -------------------------------------------------------------------------------- /testdata/lab4/refs/test5.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test5.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test50.out: -------------------------------------------------------------------------------- 1 | test50.tig:8.4: break is not inside any loop -------------------------------------------------------------------------------- /testdata/lab4/refs/test6.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test6.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test7.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test7.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test8.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab4/refs/test8.out -------------------------------------------------------------------------------- /testdata/lab4/refs/test9.out: -------------------------------------------------------------------------------- 1 | test9.tig:3.26:then exp and else exp type mismatch 2 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/merge.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | type any = {any : int} 4 | var buffer := getchar() 5 | 6 | function readint(any: any) : int = 7 | let var i := 0 8 | function isdigit(s : string) : int = 9 | ord(buffer)>=ord("0") & ord(buffer)<=ord("9") 10 | function skipto() = 11 | while buffer=" " | buffer="\n" 12 | do buffer := getchar() 13 | in skipto(); 14 | any.any := isdigit(buffer); 15 | while isdigit(buffer) 16 | do (i := i*10+ord(buffer)-ord("0"); buffer := getchar()); 17 | i 18 | end 19 | 20 | type list = {first: int, rest: list} 21 | 22 | function readlist() : list = 23 | let var any := any{any=0} 24 | var i := readint(any) 25 | in if any.any 26 | then list{first=i,rest=readlist()} 27 | else nil 28 | end 29 | 30 | function merge(a: list, b: list) : list = 31 | if a=nil then b 32 | else if b=nil then a 33 | else if a.first < b.first 34 | then list{first=a.first,rest=merge(a.rest,b)} 35 | else list{first=b.first,rest=merge(a,b.rest)} 36 | 37 | function printint(i: int) = 38 | let function f(i:int) = if i>0 39 | then (f(i/10); print(chr(i-i/10*10+ord("0")))) 40 | in if i<0 then (print("-"); f(-i)) 41 | else if i>0 then f(i) 42 | else print("0") 43 | end 44 | 45 | function printlist(l: list) = 46 | if l=nil then print("\n") 47 | else (printint(l.first); print(" "); printlist(l.rest)) 48 | 49 | var list1 := readlist() 50 | var list2 := (buffer:=getchar(); readlist()) 51 | 52 | 53 | /* BODY OF MAIN PROGRAM */ 54 | in printlist(merge(list1,list2)) 55 | end 56 | 57 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/queens.tig: -------------------------------------------------------------------------------- 1 | /* A program to solve the 8-queens problem */ 2 | 3 | let 4 | var N := 8 5 | 6 | type intArray = array of int 7 | 8 | var row := intArray [ N ] of 0 9 | var col := intArray [ N ] of 0 10 | var diag1 := intArray [N+N-1] of 0 11 | var diag2 := intArray [N+N-1] of 0 12 | 13 | function printboard() = 14 | (for i := 0 to N-1 15 | do (for j := 0 to N-1 16 | do print(if col[i]=j then " O" else " ."); 17 | print("\n")); 18 | print("\n")) 19 | 20 | function try(c:int) = 21 | ( /* for i:= 0 to c do print("."); print("\n"); flush();*/ 22 | if c=N 23 | then printboard() 24 | else for r := 0 to N-1 25 | do if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0 26 | then (row[r]:=1; diag1[r+c]:=1; diag2[r+7-c]:=1; 27 | col[c]:=r; 28 | try(c+1); 29 | row[r]:=0; diag1[r+c]:=0; diag2[r+7-c]:=0) 30 | 31 | ) 32 | in try(0) 33 | end 34 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test1.tig: -------------------------------------------------------------------------------- 1 | /* an array type and an array variable */ 2 | let 3 | type arrtype = array of int 4 | var arr1:arrtype := arrtype [10] of 0 5 | in 6 | arr1 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test10.tig: -------------------------------------------------------------------------------- 1 | /* error : body of while not unit */ 2 | while(10 > 5) do 5+6 3 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test11.tig: -------------------------------------------------------------------------------- 1 | /* error hi expr is not int, and index variable erroneously assigned to. */ 2 | for i:=10 to " " do 3 | i := i - 1 4 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test12.tig: -------------------------------------------------------------------------------- 1 | /* valid for and let */ 2 | 3 | let 4 | var a:= 0 5 | in 6 | for i:=0 to 100 do (a:=a+1;()) 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test13.tig: -------------------------------------------------------------------------------- 1 | /* error: comparison of incompatible types */ 2 | 3 | 3 > "df" 4 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test14.tig: -------------------------------------------------------------------------------- 1 | /* error : compare rec with array */ 2 | 3 | let 4 | 5 | type arrtype = array of int 6 | type rectype = {name:string, id: int} 7 | 8 | var rec := rectype {name="aname", id=0} 9 | var arr := arrtype [3] of 0 10 | 11 | in 12 | if rec <> arr then 3 else 4 13 | end 14 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test15.tig: -------------------------------------------------------------------------------- 1 | /* error : if-then returns non unit */ 2 | 3 | if 20 then 3 4 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test16.tig: -------------------------------------------------------------------------------- 1 | /* error: mutually recursive types thet do not pass through record or array */ 2 | let 3 | 4 | type a=c 5 | type b=a 6 | type c=d 7 | type d=a 8 | 9 | in 10 | "" 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test17.tig: -------------------------------------------------------------------------------- 1 | /* error: definition of recursive types is interrupted */ 2 | let 3 | /* define a tree */ 4 | type tree ={key: int, children: treelist} 5 | var d:int :=0 6 | type treelist = {hd: tree, tl: treelist} 7 | 8 | in 9 | d 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test18.tig: -------------------------------------------------------------------------------- 1 | /* error : definition of recursive functions is interrupted */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | var d:=0 8 | 9 | function do_nothing2(d: int):string = 10 | (do_nothing1(d, "str");" ") 11 | 12 | in 13 | do_nothing1(0, "str2") 14 | end 15 | 16 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test19.tig: -------------------------------------------------------------------------------- 1 | /* error : second function uses variables local to the first one, undeclared variable */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(a, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test2.tig: -------------------------------------------------------------------------------- 1 | /* arr1 is valid since expression 0 is int = myint */ 2 | let 3 | type myint = int 4 | type arrtype = array of myint 5 | 6 | var arr1:arrtype := arrtype [10] of 0 7 | in 8 | arr1 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test20.tig: -------------------------------------------------------------------------------- 1 | /* error: undeclared variable i */ 2 | 3 | while 10 > 5 do (i+1;()) 4 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test21.tig: -------------------------------------------------------------------------------- 1 | /* error : procedure returns value and procedure is used in arexpr */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int) = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | nfactor(10) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test22.tig: -------------------------------------------------------------------------------- 1 | /* error : field not in record type */ 2 | 3 | let 4 | type rectype = {name:string , id:int} 5 | var rec1 := rectype {name="Name", id=0} 6 | in 7 | rec1.nam := "asd" 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test23.tig: -------------------------------------------------------------------------------- 1 | /* error : type mismatch */ 2 | 3 | let 4 | type rectype = {name:string , id:int} 5 | var rec1 := rectype {name="aname", id=0} 6 | in 7 | rec1.name := 3; 8 | rec1.id := "" 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test24.tig: -------------------------------------------------------------------------------- 1 | /* error : variable not array */ 2 | let 3 | var d:=0 4 | in 5 | d[3] 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test25.tig: -------------------------------------------------------------------------------- 1 | /* error : variable not record */ 2 | let 3 | var d:=0 4 | in 5 | d.f 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test26.tig: -------------------------------------------------------------------------------- 1 | /* error : integer required */ 2 | 3 | 3 + "var" 4 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test27.tig: -------------------------------------------------------------------------------- 1 | /* locals hide globals */ 2 | let 3 | var a:=0 4 | 5 | function g(a:int):int = a 6 | in 7 | g(2) 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test28.tig: -------------------------------------------------------------------------------- 1 | /* error : different record types */ 2 | 3 | let 4 | type rectype1 = {name:string , id:int} 5 | type rectype2 = {name:string , id:int} 6 | 7 | var rec1: rectype1 := rectype2 {name="Name", id=0} 8 | in 9 | rec1 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test29.tig: -------------------------------------------------------------------------------- 1 | /* error : different array types */ 2 | 3 | let 4 | type arrtype1 = array of int 5 | type arrtype2 = array of int 6 | 7 | var arr1: arrtype1 := arrtype2 [10] of 0 8 | in 9 | arr1 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test3.tig: -------------------------------------------------------------------------------- 1 | /* a record type and a record variable */ 2 | let 3 | type rectype = {name:string, age:int} 4 | var rec1:rectype := rectype {name="Nobody", age=1000} 5 | in 6 | rec1.name := "Somebody"; 7 | rec1 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test30.tig: -------------------------------------------------------------------------------- 1 | /* synonyms are fine */ 2 | 3 | let 4 | type a = array of int 5 | type b = a 6 | 7 | var arr1:a := b [10] of 0 8 | in 9 | arr1[2] 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test31.tig: -------------------------------------------------------------------------------- 1 | /* error : type constraint and init value differ */ 2 | let 3 | var a:int := " " 4 | in 5 | a 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test32.tig: -------------------------------------------------------------------------------- 1 | /* error : initializing exp and array type differ */ 2 | 3 | let 4 | type arrayty = array of int 5 | 6 | var a := arrayty [10] of " " 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test33.tig: -------------------------------------------------------------------------------- 1 | /* error : unknown type */ 2 | let 3 | var a:= rectype {} 4 | in 5 | 0 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test34.tig: -------------------------------------------------------------------------------- 1 | /* error : formals and actuals have different types */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g("one", "two") 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test35.tig: -------------------------------------------------------------------------------- 1 | /* error : formals are more then actuals */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g("one") 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test36.tig: -------------------------------------------------------------------------------- 1 | /* error : formals are fewer then actuals */ 2 | let 3 | function g (a:int , b:string):int = a 4 | in 5 | g(3,"one",5) 6 | end 7 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test37.tig: -------------------------------------------------------------------------------- 1 | /* redeclaration of variable; this is legal, there are two different 2 | variables with the same name. The second one hides the first. */ 3 | let 4 | var a := 0 5 | var a := " " 6 | in 7 | 0 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test38.tig: -------------------------------------------------------------------------------- 1 | /* This is illegal, since there are two types with the same name 2 | in the same (consecutive) batch of mutually recursive types. 3 | See also test47 */ 4 | let 5 | type a = int 6 | type a = string 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test39.tig: -------------------------------------------------------------------------------- 1 | /* This is illegal, since there are two functions with the same name 2 | in the same (consecutive) batch of mutually recursive functions. 3 | See also test48 */ 4 | let 5 | function g(a:int):int = a 6 | function g(a:int):int = a 7 | in 8 | 0 9 | end 10 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test4.tig: -------------------------------------------------------------------------------- 1 | /* define a recursive function */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int): int = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | in 10 | nfactor(10) 11 | end 12 | 13 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test40.tig: -------------------------------------------------------------------------------- 1 | /* error : procedure returns value */ 2 | let 3 | function g(a:int) = a 4 | in 5 | g(2) 6 | end 7 | 8 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test41.tig: -------------------------------------------------------------------------------- 1 | /* local types hide global */ 2 | let 3 | type a = int 4 | in 5 | let 6 | type a = string 7 | in 8 | 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test42.tig: -------------------------------------------------------------------------------- 1 | /* correct declarations */ 2 | let 3 | 4 | type arrtype1 = array of int 5 | type rectype1 = {name:string, address:string, id: int , age: int} 6 | type arrtype2 = array of rectype1 7 | type rectype2 = {name : string, dates: arrtype1} 8 | 9 | type arrtype3 = array of string 10 | 11 | var arr1 := arrtype1 [10] of 0 12 | var arr2 := arrtype2 [5] of rectype1 {name="aname", address="somewhere", id=0, age=0} 13 | var arr3:arrtype3 := arrtype3 [100] of "" 14 | 15 | var rec1 := rectype1 {name="Kapoios", address="Kapou", id=02432, age=44} 16 | var rec2 := rectype2 {name="Allos", dates= arrtype1 [3] of 1900} 17 | 18 | in 19 | 20 | arr1[0] := 1; 21 | arr1[9] := 3; 22 | arr2[3].name := "kati"; 23 | arr2[1].age := 23; 24 | arr3[34] := "sfd"; 25 | 26 | rec1.name := "sdf"; 27 | rec2.dates[0] := 2323; 28 | rec2.dates[2] := 2323 29 | 30 | end 31 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test43.tig: -------------------------------------------------------------------------------- 1 | /* initialize with unit and causing type mismatch in addition */ 2 | 3 | let 4 | var a := () 5 | in 6 | a + 3 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test44.tig: -------------------------------------------------------------------------------- 1 | /* valid nil initialization and assignment */ 2 | let 3 | 4 | type rectype = {name:string, id:int} 5 | var b:rectype := nil 6 | 7 | in 8 | 9 | b := nil 10 | 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test45.tig: -------------------------------------------------------------------------------- 1 | /* error: initializing nil expressions not constrained by record type */ 2 | let 3 | type rectype = {name:string, id:int} 4 | 5 | var a:= nil 6 | in 7 | a 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test46.tig: -------------------------------------------------------------------------------- 1 | /* valid rec comparisons */ 2 | let 3 | type rectype = {name:string, id:int} 4 | var b:rectype := nil 5 | in 6 | b = nil; 7 | b <> nil 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test47.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second type "a" simply hides the first one. 2 | Because of the intervening variable declaration, the two "a" types 3 | are not in the same batch of mutually recursive types. 4 | See also test38 */ 5 | let 6 | type a = int 7 | var b := 4 8 | type a = string 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test48.tig: -------------------------------------------------------------------------------- 1 | /* This is legal. The second function "g" simply hides the first one. 2 | Because of the intervening variable declaration, the two "g" functions 3 | are not in the same batch of mutually recursive functions. 4 | See also test39 */ 5 | let 6 | function g(a:int):int = a 7 | type t = int 8 | function g(a:int):int = a 9 | in 10 | 0 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test49.tig: -------------------------------------------------------------------------------- 1 | /* error: syntax error, nil should not be preceded by type-id. */ 2 | let 3 | type rectype = {name:string, id:int} 4 | 5 | var a:= rectype nil 6 | in 7 | a 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test5.tig: -------------------------------------------------------------------------------- 1 | /* define valid recursive types */ 2 | let 3 | /* define a list */ 4 | type intlist = {hd: int, tl: intlist} 5 | 6 | /* define a tree */ 7 | type tree ={key: int, children: treelist} 8 | type treelist = {hd: tree, tl: treelist} 9 | 10 | var lis:intlist := intlist { hd=0, tl= nil } 11 | 12 | in 13 | lis 14 | end 15 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test50.tig: -------------------------------------------------------------------------------- 1 | /* valid for and let */ 2 | 3 | let 4 | var a:= 0 5 | in 6 | ( 7 | for i:=0 to 100 do (a:=a+1;break); 8 | break 9 | ) 10 | end 11 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test6.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive procedures */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string)= 5 | do_nothing2(a+1) 6 | 7 | function do_nothing2(d: int) = 8 | do_nothing1(d, "str") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test7.tig: -------------------------------------------------------------------------------- 1 | /* define valid mutually recursive functions */ 2 | let 3 | 4 | function do_nothing1(a: int, b: string):int= 5 | (do_nothing2(a+1);0) 6 | 7 | function do_nothing2(d: int):string = 8 | (do_nothing1(d, "str");" ") 9 | 10 | in 11 | do_nothing1(0, "str2") 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test8.tig: -------------------------------------------------------------------------------- 1 | /* correct if */ 2 | if (10 > 20) then 30 else 40 3 | -------------------------------------------------------------------------------- /testdata/lab4/testcases/test9.tig: -------------------------------------------------------------------------------- 1 | /* error : types of then - else differ */ 2 | 3 | if (5>4) then 13 else " " 4 | -------------------------------------------------------------------------------- /testdata/lab5or6/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/testdata/lab5or6/.DS_Store -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/tbi.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(N, 4 | intExp(8), 5 | TRUE), 6 | decList( 7 | functionDec( 8 | fundecList( 9 | fundec(printb, 10 | fieldList(), 11 | seqExp( 12 | expList( 13 | forExp(i, 14 | intExp(0), 15 | opExp( 16 | MINUS, 17 | varExp( 18 | simpleVar(N)), 19 | intExp(1)), 20 | seqExp( 21 | expList( 22 | forExp(j, 23 | intExp(0), 24 | opExp( 25 | MINUS, 26 | varExp( 27 | simpleVar(N)), 28 | intExp(1)), 29 | callExp(print, 30 | expList( 31 | iffExp( 32 | opExp( 33 | GREAT, 34 | varExp( 35 | simpleVar(i)), 36 | varExp( 37 | simpleVar(j))), 38 | stringExp(x), 39 | stringExp(y)), 40 | expList())), 41 | FALSE), 42 | expList( 43 | callExp(print, 44 | expList( 45 | stringExp( 46 | ), 47 | expList())), 48 | expList()))), 49 | FALSE), 50 | expList( 51 | callExp(print, 52 | expList( 53 | stringExp( 54 | ), 55 | expList())), 56 | expList())))), 57 | fundecList())), 58 | decList())), 59 | seqExp( 60 | expList( 61 | callExp(printb, 62 | expList()), 63 | expList()))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/test_array.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(N, 4 | intExp(8), 5 | FALSE), 6 | decList( 7 | typeDec( 8 | nameAndTyList( 9 | nameAndTy(t, 10 | recordTy( 11 | fieldList( 12 | field(a, 13 | int, 14 | TRUE), 15 | fieldList( 16 | field(b, 17 | int, 18 | TRUE), 19 | fieldList())))), 20 | nameAndTyList( 21 | nameAndTy(strArray, 22 | arrayTy(string)), 23 | nameAndTyList( 24 | nameAndTy(recArray, 25 | arrayTy(t)), 26 | nameAndTyList())))), 27 | decList( 28 | varDec(row, 29 | arrayExp(strArray, 30 | varExp( 31 | simpleVar(N)), 32 | stringExp(a)), 33 | FALSE), 34 | decList( 35 | varDec(x, 36 | arrayExp(recArray, 37 | varExp( 38 | simpleVar(N)), 39 | recordExp(t, 40 | efieldList( 41 | efield(a, 42 | intExp(1)), 43 | efieldList( 44 | efield(b, 45 | intExp(2)), 46 | efieldList())))), 47 | FALSE), 48 | decList())))), 49 | seqExp( 50 | expList( 51 | callExp(print, 52 | expList( 53 | varExp( 54 | subscriptVar( 55 | simpleVar(row), 56 | intExp(0))), 57 | expList())), 58 | expList( 59 | callExp(printi, 60 | expList( 61 | varExp( 62 | fieldVar( 63 | subscriptVar( 64 | simpleVar(x), 65 | intExp(0)), 66 | a)), 67 | expList())), 68 | expList( 69 | callExp(printi, 70 | expList( 71 | varExp( 72 | fieldVar( 73 | subscriptVar( 74 | simpleVar(x), 75 | intExp(1)), 76 | b)), 77 | expList())), 78 | expList()))))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/tfact.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(nfactor, 6 | fieldList( 7 | field(n, 8 | int, 9 | FALSE), 10 | fieldList()), 11 | int, 12 | iffExp( 13 | opExp( 14 | EQUAL, 15 | varExp( 16 | simpleVar(n)), 17 | intExp(0)), 18 | intExp(1), 19 | opExp( 20 | TIMES, 21 | varExp( 22 | simpleVar(n)), 23 | callExp(nfactor, 24 | expList( 25 | opExp( 26 | MINUS, 27 | varExp( 28 | simpleVar(n)), 29 | intExp(1)), 30 | expList()))))), 31 | fundecList())), 32 | decList()), 33 | seqExp( 34 | expList( 35 | callExp(printi, 36 | expList( 37 | callExp(nfactor, 38 | expList( 39 | intExp(10), 40 | expList())), 41 | expList())), 42 | expList()))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/tfo.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | intExp(4), 5 | FALSE), 6 | decList()), 7 | seqExp( 8 | expList( 9 | forExp(i, 10 | intExp(0), 11 | varExp( 12 | simpleVar(a)), 13 | seqExp( 14 | expList( 15 | callExp(printi, 16 | expList( 17 | varExp( 18 | simpleVar(i)), 19 | expList())), 20 | expList( 21 | iffExp( 22 | opExp( 23 | EQUAL, 24 | varExp( 25 | simpleVar(i)), 26 | intExp(3)), 27 | breakExp()), 28 | expList()))), 29 | FALSE), 30 | expList()))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/tif.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(g, 6 | fieldList( 7 | field(a, 8 | int, 9 | FALSE), 10 | fieldList( 11 | field(b, 12 | int, 13 | FALSE), 14 | fieldList())), 15 | int, 16 | iffExp( 17 | opExp( 18 | GREAT, 19 | varExp( 20 | simpleVar(a)), 21 | varExp( 22 | simpleVar(b))), 23 | varExp( 24 | simpleVar(a)), 25 | varExp( 26 | simpleVar(b)))), 27 | fundecList())), 28 | decList()), 29 | seqExp( 30 | expList( 31 | callExp(printi, 32 | expList( 33 | callExp(g, 34 | expList( 35 | intExp(9), 36 | expList( 37 | intExp(4), 38 | expList()))), 39 | expList())), 40 | expList()))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/tifn.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(b, 4 | int, 5 | intExp(5), 6 | TRUE), 7 | decList( 8 | functionDec( 9 | fundecList( 10 | fundec(g, 11 | fieldList( 12 | field(a, 13 | int, 14 | FALSE), 15 | fieldList()), 16 | iffExp( 17 | opExp( 18 | GREAT, 19 | varExp( 20 | simpleVar(a)), 21 | intExp(3)), 22 | callExp(print, 23 | expList( 24 | stringExp(hey! Bigger than 3! 25 | ), 26 | expList())), 27 | assignExp( 28 | simpleVar(b), 29 | intExp(4)))), 30 | fundecList())), 31 | decList())), 32 | seqExp( 33 | expList( 34 | callExp(printi, 35 | expList( 36 | varExp( 37 | simpleVar(b)), 38 | expList())), 39 | expList( 40 | callExp(print, 41 | expList( 42 | stringExp( 43 | ), 44 | expList())), 45 | expList( 46 | callExp(g, 47 | expList( 48 | intExp(2), 49 | expList())), 50 | expList( 51 | callExp(printi, 52 | expList( 53 | varExp( 54 | simpleVar(b)), 55 | expList())), 56 | expList())))))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/tlink.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | functionDec( 4 | fundecList( 5 | fundec(a, 6 | fieldList( 7 | field(x, 8 | int, 9 | TRUE), 10 | fieldList()), 11 | int, 12 | letExp( 13 | decList( 14 | functionDec( 15 | fundecList( 16 | fundec(b, 17 | fieldList( 18 | field(y, 19 | int, 20 | FALSE), 21 | fieldList()), 22 | int, 23 | opExp( 24 | PLUS, 25 | varExp( 26 | simpleVar(x)), 27 | varExp( 28 | simpleVar(y)))), 29 | fundecList())), 30 | decList()), 31 | seqExp( 32 | expList( 33 | callExp(b, 34 | expList( 35 | intExp(3), 36 | expList())), 37 | expList())))), 38 | fundecList())), 39 | decList()), 40 | seqExp( 41 | expList( 42 | callExp(printi, 43 | expList( 44 | callExp(a, 45 | expList( 46 | intExp(2), 47 | expList())), 48 | expList())), 49 | expList()))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/trec.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | typeDec( 4 | nameAndTyList( 5 | nameAndTy(t, 6 | recordTy( 7 | fieldList( 8 | field(a, 9 | int, 10 | TRUE), 11 | fieldList( 12 | field(b, 13 | int, 14 | TRUE), 15 | fieldList())))), 16 | nameAndTyList())), 17 | decList( 18 | varDec(x, 19 | recordExp(t, 20 | efieldList( 21 | efield(a, 22 | intExp(3)), 23 | efieldList( 24 | efield(b, 25 | intExp(4)), 26 | efieldList()))), 27 | FALSE), 28 | decList())), 29 | seqExp( 30 | expList( 31 | callExp(printi, 32 | expList( 33 | varExp( 34 | fieldVar( 35 | simpleVar(x), 36 | a)), 37 | expList())), 38 | expList( 39 | callExp(printi, 40 | expList( 41 | varExp( 42 | fieldVar( 43 | simpleVar(x), 44 | b)), 45 | expList())), 46 | expList())))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs-part1/twhi.out: -------------------------------------------------------------------------------- 1 | letExp( 2 | decList( 3 | varDec(a, 4 | intExp(10), 5 | FALSE), 6 | decList()), 7 | seqExp( 8 | expList( 9 | whileExp( 10 | opExp( 11 | GREATEQ, 12 | varExp( 13 | simpleVar(a)), 14 | intExp(0)), 15 | seqExp( 16 | expList( 17 | callExp(printi, 18 | expList( 19 | varExp( 20 | simpleVar(a)), 21 | expList())), 22 | expList( 23 | assignExp( 24 | simpleVar(a), 25 | opExp( 26 | MINUS, 27 | varExp( 28 | simpleVar(a)), 29 | intExp(1))), 30 | expList( 31 | iffExp( 32 | opExp( 33 | EQUAL, 34 | varExp( 35 | simpleVar(a)), 36 | intExp(2)), 37 | breakExp()), 38 | expList()))))), 39 | expList()))) -------------------------------------------------------------------------------- /testdata/lab5or6/refs/bsearch.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/dec2bin.out: -------------------------------------------------------------------------------- 1 | 100 -> 1100100 2 | 200 -> 11001000 3 | 789 -> 1100010101 4 | 567 -> 1000110111 5 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/merge/test1.out: -------------------------------------------------------------------------------- 1 | 1 23 2 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/merge/test2.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/merge/test3.out: -------------------------------------------------------------------------------- 1 | 3 4 17 19 20 20 12 22 3 6 341 2 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/merge/test4.out: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/prime.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 1 4 | 0 5 | 1 6 | 1 7 | 1 8 | 1 9 | 0 10 | 1 11 | 0 12 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/qsort.out: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tbi.out: -------------------------------------------------------------------------------- 1 | yyyyyyyy 2 | xyyyyyyy 3 | xxyyyyyy 4 | xxxyyyyy 5 | xxxxyyyy 6 | xxxxxyyy 7 | xxxxxxyy 8 | xxxxxxxy 9 | 10 | -------------------------------------------------------------------------------- /testdata/lab5or6/refs/test_array.out: -------------------------------------------------------------------------------- 1 | a12 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/test_patch.out: -------------------------------------------------------------------------------- 1 | 67 2 | 46 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tfact.out: -------------------------------------------------------------------------------- 1 | 3628800 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tfo.out: -------------------------------------------------------------------------------- 1 | 0123 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tif.out: -------------------------------------------------------------------------------- 1 | 9 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tifn.out: -------------------------------------------------------------------------------- 1 | 5 2 | 4 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tlink.out: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/trec.out: -------------------------------------------------------------------------------- 1 | 34 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/tree.out: -------------------------------------------------------------------------------- 1 | 5 2 | 25 3 | 33 4 | 40 5 | 50 6 | 55 7 | 60 8 | 75 9 | 80 -------------------------------------------------------------------------------- /testdata/lab5or6/refs/twhi.out: -------------------------------------------------------------------------------- 1 | 109876543 -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/bsearch.tig: -------------------------------------------------------------------------------- 1 | /* Binary Search */ 2 | 3 | let 4 | var N := 16 5 | 6 | type intArray = array of int 7 | 8 | var list := intArray [N] of 0 9 | function nop() =(print("")) 10 | function init() = 11 | (for i := 0 to N-1 12 | do (list[i]:=i*2+1;nop()) 13 | ) 14 | 15 | function bsearch(left:int,right:int,c:int): int= 16 | if left=right then left 17 | else 18 | let 19 | var mid := (left + right) / 2 20 | in 21 | if list[mid]0 7 | do ( 8 | printi(num-num/2*2); 9 | num:=num/2 10 | ); 11 | print("\n") 12 | ) 13 | */ 14 | function dec2bin(num:int) = 15 | ( if num>0 then 16 | (dec2bin(num/2); 17 | printi(num-num/2*2)) 18 | ) 19 | 20 | function try() = 21 | ( 22 | printi(100); 23 | print("\t->\t"); 24 | dec2bin(100); 25 | print("\n"); 26 | printi(200); 27 | print("\t->\t"); 28 | dec2bin(200); 29 | print("\n"); 30 | printi(789); 31 | print("\t->\t"); 32 | dec2bin(789); 33 | print("\n"); 34 | printi(567); 35 | print("\t->\t"); 36 | dec2bin(567); 37 | print("\n") 38 | ) 39 | in try() 40 | end 41 | 42 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/merge.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | type any = {any : int} 4 | var buffer := getchar() 5 | 6 | function readint(any: any) : int = 7 | let var i := 0 8 | function isdigit(s : string) : int = 9 | ord(buffer)>=ord("0") & ord(buffer)<=ord("9") 10 | function skipto() = 11 | while buffer=" " | buffer="\n" 12 | do buffer := getchar() 13 | in skipto(); 14 | any.any := isdigit(buffer); 15 | while isdigit(buffer) 16 | do (i := i*10+ord(buffer)-ord("0"); buffer := getchar()); 17 | i 18 | end 19 | 20 | type list = {first: int, rest: list} 21 | 22 | function readlist() : list = 23 | let var any := any{any=0} 24 | var i := readint(any) 25 | in if any.any 26 | then list{first=i,rest=readlist()} 27 | else nil 28 | end 29 | 30 | function merge(a: list, b: list) : list = 31 | if a=nil then b 32 | else if b=nil then a 33 | else if a.first < b.first 34 | then list{first=a.first,rest=merge(a.rest,b)} 35 | else list{first=b.first,rest=merge(a,b.rest)} 36 | 37 | function printint(i: int) = 38 | let function f(i:int) = if i>0 39 | then (f(i/10); print(chr(i-i/10*10+ord("0")))) 40 | in if i<0 then (print("-"); f(-i)) 41 | else if i>0 then f(i) 42 | else print("0") 43 | end 44 | 45 | function printlist(l: list) = 46 | if l=nil then print("\n") 47 | else (printint(l.first); print(" "); printlist(l.rest)) 48 | 49 | var list1 := readlist() 50 | var list2 := (buffer:=getchar(); readlist()) 51 | 52 | 53 | /* BODY OF MAIN PROGRAM */ 54 | in printlist(merge(list1,list2)) 55 | end 56 | 57 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/merge/test1.in: -------------------------------------------------------------------------------- 1 | 1 a 2 | 23 b 3 | 4 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/merge/test2.in: -------------------------------------------------------------------------------- 1 | a 2 | 2 b 3 | 4 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/merge/test3.in: -------------------------------------------------------------------------------- 1 | 20 12 22 3 6 341 a 2 | 3 4 17 19 20 b 3 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/merge/test4.in: -------------------------------------------------------------------------------- 1 | c 2 | e 3 | 4 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/prime.tig: -------------------------------------------------------------------------------- 1 | /* Prime Check */ 2 | 3 | let 4 | function check(num:int) : int= 5 | let 6 | var flag := 1 7 | in 8 | (for i :=2 to num/2 9 | do 10 | if num/i*i=num 11 | then (flag:=0; break); 12 | flag) 13 | end 14 | 15 | function try() = 16 | ( 17 | printi(check(56)); /*expect: 0*/ 18 | print("\n"); 19 | printi(check(23)); /*expect: 1*/ 20 | print("\n"); 21 | printi(check(71)); /*expect: 1*/ 22 | print("\n"); 23 | printi(check(72)); /*expect: 0*/ 24 | print("\n"); 25 | printi(check(173)); /*expect: 1*/ 26 | print("\n"); 27 | printi(check(181)); /*expect: 1*/ 28 | print("\n"); 29 | printi(check(281)); /*expect: 1*/ 30 | print("\n"); 31 | printi(check(659)); /*expect: 1*/ 32 | print("\n"); 33 | printi(check(729)); /*expect: 0*/ 34 | print("\n"); 35 | printi(check(947)); /*expect: 1*/ 36 | print("\n"); 37 | printi(check(945)); /*expect: 0*/ 38 | print("\n") 39 | ) 40 | in try() 41 | end 42 | 43 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/qsort.tig: -------------------------------------------------------------------------------- 1 | /* Quick Sort*/ 2 | 3 | let 4 | var N := 16 5 | type intArray = array of int 6 | 7 | var list := intArray [N] of 0 8 | 9 | function nop() = (print("")) 10 | function init() = 11 | (for i := 0 to N-1 12 | do (list[i]:=N-i;nop()) 13 | ) 14 | 15 | function quicksort(left:int, right:int) = 16 | let var i:= left 17 | var j:= right 18 | var key:= list[left] 19 | in if left < right then 20 | (while i=list[i] 28 | do i := i+1; 29 | 30 | list[j] := list[i]); 31 | list[i] := key; 32 | quicksort(left,i-1); 33 | quicksort(i+1,right)) 34 | end 35 | function dosort() = 36 | ( 37 | init(); 38 | quicksort(0,N-1); 39 | for i:=0 to N-1 40 | do (printi(list[i]);print(" ")); 41 | print("\n") 42 | ) 43 | in dosort() 44 | end 45 | 46 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/queens.tig: -------------------------------------------------------------------------------- 1 | /* A program to solve the 8-queens problem */ 2 | 3 | let 4 | var N := 8 5 | 6 | type intArray = array of int 7 | 8 | var row := intArray [ N ] of 0 9 | var col := intArray [ N ] of 0 10 | var diag1 := intArray [N+N-1] of 0 11 | var diag2 := intArray [N+N-1] of 0 12 | 13 | function printboard() = 14 | (for i := 0 to N-1 15 | do (for j := 0 to N-1 16 | do print(if col[i]=j then " O" else " ."); 17 | print("\n")); 18 | print("\n")) 19 | 20 | function try(c:int) = 21 | ( /* for i:= 0 to c do print("."); print("\n"); flush();*/ 22 | if c=N 23 | then printboard() 24 | else for r := 0 to N-1 25 | do if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0 26 | then (row[r]:=1; diag1[r+c]:=1; diag2[r+7-c]:=1; 27 | col[c]:=r; 28 | try(c+1); 29 | row[r]:=0; diag1[r+c]:=0; diag2[r+7-c]:=0) 30 | 31 | ) 32 | in try(0) 33 | end 34 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tbi.tig: -------------------------------------------------------------------------------- 1 | let 2 | var N := 8 3 | 4 | function printb() = 5 | (for i := 0 to N - 1 6 | do (for j := 0 to N - 1 7 | do print(if i > j then "x" else "y"); 8 | print("\n")); 9 | print("\n")) 10 | in 11 | printb() 12 | end 13 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/test_array.tig: -------------------------------------------------------------------------------- 1 | let 2 | var N := 8 3 | 4 | type t = {a:int, b:int} 5 | type strArray = array of string 6 | type recArray = array of t 7 | 8 | var row := strArray [ N ] of "a" 9 | var x := recArray [ N ] of t{a=1,b=2} 10 | 11 | in 12 | print(row[0]); 13 | printi(x[0].a); 14 | printi(x[1].b) 15 | end -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/test_patch.tig: -------------------------------------------------------------------------------- 1 | let 2 | function patchtest(a:int, b:int, c:int, d:int, e:int, f:int, g:int, h:int) : int = 3 | if a > b | c < d & e = f | g <> h 4 | then a + d + e + h 5 | else c + b + g + f 6 | in 7 | ( 8 | printi(patchtest(9,4,3,2,11,11,23,45)); /* 67 */ 9 | print("\n"); 10 | printi(patchtest(4,9,3,2,11,11,23,23)) /* 46 */ 11 | ) 12 | end -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tfact.tig: -------------------------------------------------------------------------------- 1 | /* define a recursive function */ 2 | let 3 | 4 | /* calculate n! */ 5 | function nfactor(n: int): int = 6 | if n = 0 7 | then 1 8 | else n * nfactor(n-1) 9 | 10 | in 11 | printi(nfactor(10)) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tfo.tig: -------------------------------------------------------------------------------- 1 | let 2 | var a := 4 3 | in 4 | for i := 0 to a 5 | do (printi(i); 6 | if i = 3 7 | then break) 8 | end 9 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tif.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | function g(a:int, b:int) : int = 4 | if a > b 5 | then a 6 | else b 7 | in 8 | printi(g(9,4)) 9 | end 10 | 11 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tifn.tig: -------------------------------------------------------------------------------- 1 | let 2 | var b : int := 5 3 | function g(a:int) = 4 | if( a > 3 ) 5 | then print("hey! Bigger than 3!\n") 6 | else b := 4 7 | 8 | 9 | in 10 | printi(b);print("\n");g(2);printi(b) 11 | end 12 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tlink.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | function a(x:int) : int = 4 | let 5 | function b(y:int) : int = x + y 6 | in 7 | b(3) 8 | end 9 | in 10 | printi(a(2)) 11 | end 12 | 13 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/trec.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | type t = {a:int, b:int} 4 | var x := t{a = 3, b = 4} 5 | in 6 | printi(x.a);printi(x.b) 7 | end 8 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/tree.tig: -------------------------------------------------------------------------------- 1 | let 2 | 3 | type node = { key: int, left: node, right: node } 4 | 5 | /* Insert t2 as t1's children */ 6 | function insert(t1: node, t2: node) : node = 7 | if t1 = nil 8 | then t2 9 | else 10 | if t1.key > t2.key 11 | then node { key = t1.key, left = insert(t1.left, t2), right = t1.right } 12 | else node { key = t1.key, left = t1.left, right = insert(t1.right, t2) } 13 | 14 | function printint(i: int) = 15 | let 16 | function f(i: int) = 17 | if i > 0 then 18 | (f(i/10); print(chr(i - i / 10 * 10 + ord("0")))) 19 | in 20 | (if i < 0 then (print("-"); f(-i)) 21 | else if i > 0 then f(i) 22 | else print("0"); 23 | print("\n") 24 | ) 25 | end 26 | 27 | /* Inorder Traversal to print the bst three */ 28 | function printtree(t: node) = 29 | if t <> nil then 30 | (printtree(t.left); printint(t.key); printtree(t.right)) 31 | 32 | function getnode(i: int) : node = 33 | node {key= i, left= nil, right= nil} 34 | 35 | var root : node := nil 36 | var node25 : node := getnode(25) 37 | 38 | in 39 | (root := insert(root, getnode(50)); 40 | root := insert(root, getnode(75)); 41 | node25 := insert(node25, getnode(5)); 42 | node25 := insert(node25, getnode(40)); 43 | root := insert(root, node25); 44 | root := insert(root, getnode(80)); 45 | root := insert(root, getnode(60)); 46 | root := insert(root, getnode(55)); 47 | root := insert(root, getnode(33)); 48 | printtree(root)) 49 | 50 | end 51 | 52 | -------------------------------------------------------------------------------- /testdata/lab5or6/testcases/twhi.tig: -------------------------------------------------------------------------------- 1 | let 2 | var a := 10 3 | 4 | in 5 | while a >= 0 6 | do (printi(a);a := a - 1;if a = 2 then break) 7 | end 8 | -------------------------------------------------------------------------------- /期末整理/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/.DS_Store -------------------------------------------------------------------------------- /期末整理/垃圾收集算法——分代收集算法(Generational Collection)。_孤芳不自赏-CSDN博客_分代收集算法.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/垃圾收集算法——分代收集算法(Generational Collection)。_孤芳不自赏-CSDN博客_分代收集算法.pdf -------------------------------------------------------------------------------- /期末整理/垃圾收集算法——复制算法(Copying)。_孤芳不自赏-CSDN博客_复制算法.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/垃圾收集算法——复制算法(Copying)。_孤芳不自赏-CSDN博客_复制算法.pdf -------------------------------------------------------------------------------- /期末整理/增量式垃圾回收_一蓑烟雨的专栏-CSDN博客.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/增量式垃圾回收_一蓑烟雨的专栏-CSDN博客.pdf -------------------------------------------------------------------------------- /期末整理/引用计数_百度百科.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/引用计数_百度百科.pdf -------------------------------------------------------------------------------- /期末整理/期末题型整理compiler.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/期末题型整理compiler.pdf -------------------------------------------------------------------------------- /期末整理/深入了解标记-清扫回收算法_一只海滩上的贝壳-CSDN博客.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/深入了解标记-清扫回收算法_一只海滩上的贝壳-CSDN博客.pdf -------------------------------------------------------------------------------- /期末整理/编译原理期末整理.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WilliamX1/tiger-compiler/c540829d3e987d99c14c817ac852b815d70765eb/期末整理/编译原理期末整理.pdf --------------------------------------------------------------------------------