├── .gitignore ├── 0.SnuPL.Compiler.Project.pdf ├── 1.Scanning ├── 1.Scanning.pdf ├── 1.Scanning_report.pdf ├── snuplc │ ├── Doxyfile │ ├── Makefile │ ├── obj │ │ └── README.md │ └── src │ │ ├── scanner.cpp │ │ ├── scanner.h │ │ └── test_scanner.cpp └── test │ └── scanner │ ├── SnuPL-1 │ ├── test01.mod │ ├── test02.mod │ └── test03.mod │ ├── array.mod │ ├── character.mod │ ├── escape_char.mod │ ├── fibonacci.mod │ ├── string.mod │ ├── test01.mod │ └── test02.mod ├── 2.Parsing ├── 2.Parsing.pdf ├── 2.Parsing_report.pdf ├── compare ├── reference │ └── test_parser ├── scanner │ ├── Makefile │ ├── README │ ├── scanner.h │ └── scanner.o ├── snuplc │ ├── Doxyfile │ ├── Makefile │ └── src │ │ ├── ast.cpp │ │ ├── ast.h │ │ ├── data.cpp │ │ ├── data.h │ │ ├── ir.cpp │ │ ├── ir.h │ │ ├── parser.cpp │ │ ├── parser.h │ │ ├── scanner.cpp │ │ ├── scanner.h │ │ ├── symtab.cpp │ │ ├── symtab.h │ │ ├── test_parser.cpp │ │ ├── test_scanner.cpp │ │ ├── type.cpp │ │ └── type.h └── test │ ├── parser │ ├── SnuPL-1 │ │ ├── test01.mod │ │ ├── test02.mod │ │ ├── test03.mod │ │ ├── test04.mod │ │ └── test05.mod │ ├── array.mod │ ├── array01.mod │ ├── array02.mod │ ├── array03.mod │ ├── array04.mod │ ├── array05.mod │ ├── array06.mod │ ├── array07.mod │ ├── char01.mod │ ├── char02.mod │ ├── char03.mod │ ├── char04.mod │ ├── error01.mod │ ├── error02.mod │ ├── error03.mod │ ├── error04.mod │ ├── error05.mod │ ├── error06.mod │ ├── error07.mod │ ├── error08.mod │ ├── error09.mod │ ├── error10.mod │ ├── my0.mod │ ├── pstest01.mod │ ├── pstest02.mod │ ├── pstest03.mod │ ├── pstest04.mod │ ├── string01.mod │ ├── string02.mod │ ├── test03.mod │ ├── test04.mod │ ├── test05.mod │ └── test06.mod │ └── scanner │ ├── SnuPL-1 │ ├── test01.mod │ ├── test02.mod │ └── test03.mod │ ├── test01.mod │ └── test02.mod ├── 3.Semantic.Analysis ├── 3.Semantic.Analysis.Report.pdf ├── 3.Semantic.Analysis.pdf ├── compare ├── reference │ ├── 3_test_parser │ ├── 3_test_parser.relaxed │ ├── 3_test_parser.simple │ └── 3_test_parser.strict ├── snuplc │ ├── Doxyfile │ ├── Makefile │ └── src │ │ ├── ast.cpp │ │ ├── ast.h │ │ ├── data.cpp │ │ ├── data.h │ │ ├── ir.cpp │ │ ├── ir.h │ │ ├── old │ │ ├── data.cpp │ │ ├── data.h │ │ ├── symtab.cpp │ │ ├── type.cpp │ │ └── type.h │ │ ├── parser.cpp │ │ ├── parser.h │ │ ├── scanner.cpp │ │ ├── scanner.h │ │ ├── symtab.cpp │ │ ├── symtab.h │ │ ├── test_parser.cpp │ │ ├── test_scanner.cpp │ │ ├── type.cpp │ │ └── type.h └── test │ ├── parser │ ├── SnuPL-1 │ │ ├── test01.mod │ │ ├── test02.mod │ │ ├── test03.mod │ │ ├── test04.mod │ │ └── test05.mod │ ├── array.mod │ ├── array01.mod │ ├── array02.mod │ ├── array03.mod │ ├── array04.mod │ ├── array05.mod │ ├── array06.mod │ ├── array07.mod │ ├── char01.mod │ ├── char02.mod │ ├── char03.mod │ ├── char04.mod │ ├── error01.mod │ ├── error02.mod │ ├── error03.mod │ ├── error04.mod │ ├── error05.mod │ ├── error06.mod │ ├── error07.mod │ ├── error08.mod │ ├── error09.mod │ ├── error10.mod │ ├── my0.mod │ ├── pstest01.mod │ ├── pstest02.mod │ ├── pstest03.mod │ ├── pstest04.mod │ ├── string01.mod │ ├── string02.mod │ ├── test03.mod │ ├── test04.mod │ ├── test05.mod │ └── test06.mod │ ├── scanner │ ├── SnuPL-1 │ │ ├── test01.mod │ │ ├── test02.mod │ │ └── test03.mod │ ├── test01.mod │ └── test02.mod │ └── semanal │ ├── arrays.mod │ ├── error │ ├── error4_1_1.mod │ ├── error4_1_2_1.mod │ ├── error4_1_2_2.mod │ ├── error4_1_2_3.mod │ ├── error4_1_2_4.mod │ ├── error4_1_3.mod │ ├── error4_1_4.mod │ ├── error4_1_5.mod │ ├── error4_1_6.mod │ ├── error4_1_7.mod │ ├── error4_2_1.mod │ ├── error4_2_10.mod │ ├── error4_2_11.mod │ ├── error4_2_2.mod │ ├── error4_2_3.mod │ ├── error4_2_4.mod │ ├── error4_2_5.mod │ ├── error4_2_6.mod │ ├── error4_2_7.mod │ ├── error4_2_8.mod │ └── error4_2_9.mod │ ├── hmtest00.mod │ ├── hmtest01.mod │ ├── hmtest02.mod │ ├── hmtest03.mod │ ├── hmtest04.mod │ ├── int_const_relaxed.mod │ ├── int_const_simple.mod │ ├── int_const_strict.mod │ ├── pstest00.mod │ ├── pstest01.mod │ ├── pstest02.mod │ ├── pstest03.mod │ ├── pstest04.mod │ ├── pstest05.mod │ ├── pstest06.mod │ ├── semantics.mod │ ├── simple00.mod │ ├── simple01.mod │ ├── simple02.mod │ ├── simple03.mod │ ├── simple04.mod │ ├── simple05.mod │ ├── simple06.mod │ ├── simple07.mod │ ├── simple08.mod │ ├── simple09.mod │ ├── simple10.mod │ ├── simple11.mod │ ├── simple12.mod │ └── strings.mod ├── 4.Intermediate.Code.Generation ├── 4.Intermediate.Code.Generation.Report.pdf ├── 4.Intermediate.Code.Generation.pdf ├── compare ├── reference │ └── 4_test_ir ├── snuplc │ ├── Makefile │ └── src │ │ ├── ast.cpp │ │ ├── ast.h │ │ ├── data.cpp │ │ ├── data.h │ │ ├── ir.cpp │ │ ├── ir.h │ │ ├── parser.cpp │ │ ├── parser.h │ │ ├── scanner.cpp │ │ ├── scanner.h │ │ ├── symtab.cpp │ │ ├── symtab.h │ │ ├── test_ir.cpp │ │ ├── test_parser.cpp │ │ ├── test_scanner.cpp │ │ ├── type.cpp │ │ └── type.h └── test │ └── tac │ ├── giftToEgger.mod │ ├── hmtest00.mod │ ├── hmtest01.mod │ ├── hmtest02.mod │ ├── hmtest03.mod │ ├── hmtest04.mod │ ├── pstest00.mod │ ├── pstest01.mod │ ├── pstest02.mod │ ├── pstest03.mod │ ├── pstest04.mod │ ├── pstest05.mod │ ├── pstest06.mod │ ├── pstest07.mod │ ├── pstest08.mod │ ├── pstest09.mod │ ├── pstest10.mod │ ├── pstest11.mod │ ├── pstest12.mod │ ├── pstest13.mod │ ├── simple00.mod │ ├── simple01.mod │ ├── simple02.mod │ ├── simple03.mod │ ├── simple04.mod │ ├── simple05.mod │ ├── simple06.mod │ ├── simple07.mod │ ├── simple08.mod │ ├── simple09.mod │ ├── simple09_2.mod │ ├── simple10.mod │ ├── simple11.mod │ ├── simple12.mod │ ├── simple13.mod │ ├── simple14.mod │ ├── simple15.mod │ ├── simple16.mod │ ├── simple17.mod │ ├── simple18.mod │ ├── simple19.mod │ ├── simple20.mod │ ├── simple21.mod │ ├── simple22.mod │ ├── simple23.mod │ ├── test1.mod │ ├── test2.mod │ ├── test3.mod │ ├── test4.mod │ ├── test4_2.mod │ ├── test5.mod │ ├── test6.mod │ ├── test7.mod │ ├── test7_2.mod │ ├── test7_3.mod │ ├── test8.mod │ ├── test8_2.mod │ ├── test8_3.mod │ ├── test8_4.mod │ └── test9.mod ├── 5.Code.Generation ├── 5.Code.Generation.pdf ├── 5.Final.Report_with_cover.pdf ├── compare ├── compile ├── reference │ └── snuplc ├── rte │ └── IA32 │ │ ├── ARRAY.s │ │ └── IO.s ├── snuplc │ ├── Makefile │ └── src │ │ ├── ast.cpp │ │ ├── ast.h │ │ ├── backend.cpp │ │ ├── backend.h │ │ ├── data.cpp │ │ ├── data.h │ │ ├── ir.cpp │ │ ├── ir.h │ │ ├── parser.cpp │ │ ├── parser.h │ │ ├── scanner.cpp │ │ ├── scanner.h │ │ ├── snuplc.cpp │ │ ├── symtab.cpp │ │ ├── symtab.h │ │ ├── test_ir.cpp │ │ ├── test_parser.cpp │ │ ├── test_scanner.cpp │ │ ├── type.cpp │ │ └── type.h └── test │ └── codegen │ ├── .test05.mod.swp │ ├── .test11.mod.swp │ ├── Makefile │ ├── factorial.mod │ ├── fibonacci.mod │ ├── gcd.mod │ ├── hmtest01.mod │ ├── hmtest02.mod │ ├── instr00.mod │ ├── instr01.mod │ ├── instr02.mod │ ├── instr03.mod │ ├── pfact.mod │ ├── primes.mod │ ├── pstest00.mod │ ├── pstest01.mod │ ├── pstest02.mod │ ├── pstest04.mod │ ├── pstest06.mod │ ├── pstest07.mod │ ├── pstest08.mod │ ├── pstest09.mod │ ├── pstest10.mod │ ├── pstest12.mod │ ├── pstest13.mod │ ├── ref_bug0.mod │ ├── ref_bug1.mod │ ├── simple00.mod │ ├── simple01.mod │ ├── simple02.mod │ ├── simple03.mod │ ├── simple04.mod │ ├── simple05.mod │ ├── simple06.mod │ ├── simple07.mod │ ├── simple08.mod │ ├── simple09.mod │ ├── simple09_2.mod │ ├── simple10.mod │ ├── simple11.mod │ ├── simple12.mod │ ├── simple13.mod │ ├── simple14.mod │ ├── simple15.mod │ ├── simple16.mod │ ├── simple17.mod │ ├── simple19.mod │ ├── simple20.mod │ ├── simple21.mod │ ├── simple22.mod │ ├── simple23.mod │ ├── stackframe00.mod │ ├── test01.mod │ ├── test02.mod │ ├── test03.mod │ ├── test04.mod │ ├── test05.mod │ ├── test06.mod │ ├── test07.mod │ ├── test08.mod │ ├── test09.mod │ ├── test10.mod │ ├── test11.mod │ ├── test4_2.mod │ ├── test7_2.mod │ ├── test7_3.mod │ ├── test8_2.mod │ ├── test8_3.mod │ └── test8_4.mod ├── README.md ├── helper.ml └── vim_syntax └── mod.vim /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | /1.Scanning/snuplc/test_scanner 8 | /1.Scanning/snuplc/obj/*.o 9 | *.mod.ast.dot 10 | -------------------------------------------------------------------------------- /0.SnuPL.Compiler.Project.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/0.SnuPL.Compiler.Project.pdf -------------------------------------------------------------------------------- /1.Scanning/1.Scanning.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/1.Scanning/1.Scanning.pdf -------------------------------------------------------------------------------- /1.Scanning/1.Scanning_report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/1.Scanning/1.Scanning_report.pdf -------------------------------------------------------------------------------- /1.Scanning/snuplc/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CCFLAGS=-std=c++0x -g -O0 3 | 4 | SRC_DIR=src 5 | OBJ_DIR=obj 6 | 7 | DEPS=scanner.h 8 | SCANNER=scanner.cpp 9 | 10 | DEPS_=$(patsubst %,$(SRC_DIR)/%,$(DEPS)) 11 | OBJ_SCANNER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SCANNER)) 12 | 13 | .PHONY: clean doc 14 | 15 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS_) 16 | $(CC) $(CCFLAGS) -c -o $@ $< 17 | 18 | all: test_scanner 19 | 20 | test_scanner: $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 21 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 22 | 23 | doc: 24 | doxygen 25 | 26 | clean: 27 | rm -rf $(OBJ_DIR)/*.o test_scanner 28 | 29 | mrproper: clean 30 | rm -rf doc/* 31 | 32 | -------------------------------------------------------------------------------- /1.Scanning/snuplc/obj/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/1.Scanning/snuplc/obj/README.md -------------------------------------------------------------------------------- /1.Scanning/snuplc/src/test_scanner.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SNUPL scanner test 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2012/09/14 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2012, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "scanner.h" 38 | using namespace std; 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | int i = 1; 43 | 44 | while (i < argc) { 45 | CScanner *s = new CScanner(new ifstream(argv[i])); 46 | 47 | cout << "scanning '" << argv[i] << "'..." << endl; 48 | 49 | if (!s->Good()) cout << " cannot open input stream: " << s->Peek() << endl; 50 | 51 | while (s->Good()) { 52 | CToken t = s->Get(); 53 | cout << " " << t << endl; 54 | if (t.GetType() == tEOF) break; 55 | } 56 | 57 | cout << endl << endl; 58 | 59 | i++; 60 | } 61 | 62 | cout << "Done." << endl; 63 | 64 | return EXIT_SUCCESS; 65 | } 66 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/SnuPL-1/test01.mod: -------------------------------------------------------------------------------- 1 | := 2 | + 3 | - 4 | * 5 | / 6 | 7 | = 8 | # 9 | 10 | ; 11 | . 12 | ( 13 | ) 14 | 15 | 0 16 | 1 17 | 7 18 | 123456789 19 | a 20 | b 21 | f 22 | xyz 23 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/SnuPL-1/test02.mod: -------------------------------------------------------------------------------- 1 | a=:==#:=;;;1(2);11:=-1.1;5::==5; 2 | 3 | 4 | [ 5 | ] 6 | { 7 | } 8 | ? 9 | ^ 10 | \ 11 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/SnuPL-1/test03.mod: -------------------------------------------------------------------------------- 1 | a := 5; 2 | 3 | b := 2 + 3; 4 | 5 | c := 2 + 3 * (1 - 2 - 3 + 1) 6 | . 7 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/array.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | 5 | module arrays; 6 | 7 | var A : integer[5]; 8 | B : boolean[1]; 9 | C : char[256]; 10 | i : integer; 11 | b : boolean; 12 | c : char; 13 | 14 | procedure print_array(array: integer[]); 15 | begin 16 | end print_array; 17 | 18 | begin 19 | i := A[0]; 20 | b := B[5]; 21 | c := C[-1]; 22 | 23 | print_array(A) 24 | end arrays. 25 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/character.mod: -------------------------------------------------------------------------------- 1 | module character; 2 | 3 | var c: char; 4 | 5 | function test(a: char): char; 6 | begin 7 | return a 8 | end test; 9 | 10 | procedure WriteLn(string: char[]); 11 | begin 12 | end WriteLn; 13 | 14 | begin 15 | c := '7'; 16 | c := test(c); 17 | c := test('0'); 18 | WriteLn("Hello, world!\n") 19 | end character. 20 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/escape_char.mod: -------------------------------------------------------------------------------- 1 | // valid characters 2 | 3 | 'a''x''r''z''A''H''Z''K' 4 | '0''1''2''3''4''5''6''7''8''9' 5 | ' ' '\t' '\n' ';' ':' '@' '^' 6 | '"' '\"' '\\' '\0' '\'' '\0' '\n' 7 | '_''+''>' '/' 'M''*''%''`' 8 | '\'''\"''"''\'''"''.' 9 | 10 | // unvalid characters 11 | // * 12 | // * many comments 13 | 14 | '\/''\a''\b''\l' '\ ' 15 | 'ê' 'ä' 'ů' '‘' '’' '—' 16 | 'さ' 'é' 'わ' 'わ' 'ⅹ' 'や' 'ゐ' 17 | ' '' ' 18 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/fibonacci.mod: -------------------------------------------------------------------------------- 1 | // 2 | // Fibonacci: compute fibonacci numbers 3 | // 4 | module fibonacci; 5 | 6 | var n: integer; 7 | 8 | // fib(n: integer): integer 9 | // compute the fibonacci number of n. n >= 0 10 | function fib(n: integer): integer; 11 | begin 12 | if (n <= 1) then 13 | return n 14 | else 15 | return fib(n-1) + fib(n-2) 16 | end 17 | end fib; 18 | 19 | begin 20 | Write("Enter a number: "); 21 | n := ReadInt(); 22 | 23 | // loop until the user enters a number < 0 24 | while (n > 0) do 25 | Write("Result: "); WriteInt(fib(n)); WriteLn; 26 | 27 | Write("Enter a number: "); 28 | n := ReadInt() 29 | end 30 | end fibonacci. 31 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/string.mod: -------------------------------------------------------------------------------- 1 | module string; 2 | 3 | function foo: 4 | // valid input 5 | 6 | "Hello, world!\n" 7 | // comment 8 | "a-zA-Z_\n \t \\ \' \"" 9 | "123" // not a number 123 10 | "01234//56789_asdav wFC // SAD Df s FS" 11 | "'/'" 12 | "'\''" 13 | 14 | " -*:=<>#_:;,.$@%^&()\\" 15 | " " 16 | "" 17 | "'" "\"\"" "''" "\n" "\t" " " 18 | "// not a comment" // white spaces "This is not a string" 19 | "string with \tab" "" 20 | 21 | "function" 22 | "module" 23 | 24 | 25 | // invalid input 26 | 27 | "안녕, 세상!\n" 28 | "1" "2""34567" 29 | "<" 30 | "Not a  string .\n" 31 | "Not a  string" 32 | "\nNot a  string" 33 | """ 34 | // comment 35 | "'_\" if (a <= 3) then WriteLine(str); else return a + 5 end \" 36 | // comment " 37 | "Open string 38 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/test01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test01 3 | // 4 | // scanner test: contains only valid tokens 5 | // 6 | 7 | // keywords 8 | 9 | module 10 | procedure 11 | function 12 | var 13 | integer 14 | boolean 15 | char 16 | begin 17 | end 18 | if 19 | then 20 | else 21 | while 22 | do 23 | return 24 | true 25 | false 26 | 27 | // operators 28 | := 29 | + 30 | - 31 | * 32 | / 33 | || 34 | && 35 | ! 36 | 37 | // relops 38 | < 39 | <= 40 | = 41 | >= 42 | > 43 | # 44 | 45 | // syntax elements 46 | , 47 | ; 48 | : 49 | . 50 | ( 51 | ) 52 | [ 53 | ] 54 | 55 | // identifiers 56 | a 57 | b 58 | c 59 | temp1 60 | iftemp 61 | elsetemp 62 | _tmp1 63 | _____t 64 | 65 | // numbers 66 | 0 67 | 1 68 | 2147483647 69 | 2147483648 70 | 000000000000000000 71 | 999999999999999999 72 | -100 73 | +400 74 | 75 | // boolean 76 | true 77 | false 78 | 79 | // characters 80 | 'a' 81 | '\n' 82 | '\t' 83 | '\0' 84 | '\\' 85 | 86 | // strings 87 | "hello, world!" 88 | "this\tis\ta\ttab!" 89 | "'a\'" 90 | "" 91 | "\"before_newline\nafter_newline\"" 92 | "before_null\0after_null\n" 93 | -------------------------------------------------------------------------------- /1.Scanning/test/scanner/test02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test02 3 | // 4 | // scanner test: contains valid and invalid tokens 5 | // 6 | 7 | // scannable input 8 | <===>=#:=:::==>;;;if(then)else;a:=-1.1;a::==0x5; 9 | 1a2b"hello world" 10 | 11 | // invalid input 12 | { 13 | } 14 | ? 15 | ^ 16 | \ 17 | 'hello world' 18 | -------------------------------------------------------------------------------- /2.Parsing/2.Parsing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/2.Parsing/2.Parsing.pdf -------------------------------------------------------------------------------- /2.Parsing/2.Parsing_report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/2.Parsing/2.Parsing_report.pdf -------------------------------------------------------------------------------- /2.Parsing/compare: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | rm -f ./my ./egger 3 | find test/parser -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "snuplc/test_parser {} >> my" 4 | find test/parser -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "reference/test_parser {} >> egger" 5 | -------------------------------------------------------------------------------- /2.Parsing/reference/test_parser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/2.Parsing/reference/test_parser -------------------------------------------------------------------------------- /2.Parsing/scanner/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CCFLAGS=-std=c++0x -g -O0 3 | 4 | SRC_DIR=src 5 | OBJ_DIR=obj 6 | LIB_DIR=lib 7 | 8 | DEPS=scanner.h \ 9 | parser.h \ 10 | type.h \ 11 | data.h \ 12 | symtab.h \ 13 | ast.h \ 14 | ir.h 15 | SCANNER=scanner.cpp 16 | PARSER=parser.cpp \ 17 | type.cpp \ 18 | data.cpp \ 19 | symtab.cpp \ 20 | ast.cpp \ 21 | ir.cpp 22 | 23 | DEPS_=$(patsubst %,$(SRC_DIR)/%,$(DEPS)) 24 | LIB_SCANNER=$(patsubst %.cpp,$(LIB_DIR)/%.o,$(SCANNER)) 25 | OBJ_PARSER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(PARSER)) 26 | 27 | .PHONY: clean doc 28 | 29 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS_) 30 | $(CC) $(CCFLAGS) -c -o $@ $< 31 | 32 | all: test_scanner test_parser 33 | 34 | test_scanner: $(OBJ_DIR)/test_scanner.o 35 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_scanner.o $(LIB_SCANNER) 36 | 37 | test_parser: $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 38 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_parser.o $(LIB_SCANNER) $(OBJ_PARSER) 39 | 40 | doc: 41 | doxygen 42 | 43 | clean: 44 | rm -rf $(OBJ_DIR)/*.o test_scanner test_parser 45 | 46 | mrproper: clean 47 | rm -rf doc/* 48 | 49 | -------------------------------------------------------------------------------- /2.Parsing/scanner/README: -------------------------------------------------------------------------------- 1 | This directory contains the reference implementation of the SnuPL/1 scanner. 2 | 3 | To use this scanner instead of your own, perform the following steps: 4 | 5 | 1. create a directory 'lib' under 'snuplc' 6 | $ mkdir ../snuplc/lib 7 | 8 | 2. copy scanner.o to the newly created directory 9 | $ cp scanner.o ../snuplc/lib/ 10 | 11 | 3. copy scanner.h to the source directory 12 | $ cp scanner.h ../snuplc/src/ 13 | 14 | 4. replace the Makefile in snuplc/ with the one here 15 | $ cp Makefile ../snuplc/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /2.Parsing/scanner/scanner.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/2.Parsing/scanner/scanner.o -------------------------------------------------------------------------------- /2.Parsing/snuplc/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CCFLAGS=-std=c++0x -g -O0 3 | 4 | SRC_DIR=src 5 | OBJ_DIR=obj 6 | 7 | DEPS=scanner.h \ 8 | parser.h \ 9 | type.h \ 10 | data.h \ 11 | symtab.h \ 12 | ast.h \ 13 | ir.h 14 | SCANNER=scanner.cpp 15 | PARSER=parser.cpp \ 16 | type.cpp \ 17 | data.cpp \ 18 | symtab.cpp \ 19 | ast.cpp \ 20 | ir.cpp 21 | 22 | DEPS_=$(patsubst %,$(SRC_DIR)/%,$(DEPS)) 23 | OBJ_SCANNER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SCANNER)) 24 | OBJ_PARSER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(PARSER) $(SCANNER)) 25 | 26 | .PHONY: clean doc 27 | 28 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS_) 29 | $(CC) $(CCFLAGS) -c -o $@ $< 30 | 31 | all: test_scanner test_parser 32 | 33 | test_scanner: $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 34 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 35 | 36 | test_parser: $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 37 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 38 | 39 | doc: 40 | doxygen 41 | 42 | clean: 43 | rm -rf $(OBJ_DIR)/*.o test_scanner test_parser 44 | 45 | mrproper: clean 46 | rm -rf doc/* 47 | 48 | -------------------------------------------------------------------------------- /2.Parsing/snuplc/src/data.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SnuPL data initializers 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2016/04/05 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | 36 | #include "data.h" 37 | using namespace std; 38 | 39 | 40 | //------------------------------------------------------------------------------ 41 | // CDataInitializer 42 | // 43 | CDataInitializer::CDataInitializer(void) 44 | { 45 | } 46 | 47 | CDataInitializer::~CDataInitializer(void) 48 | { 49 | } 50 | 51 | 52 | //------------------------------------------------------------------------------ 53 | // CDataInitString 54 | // 55 | CDataInitString::CDataInitString(const string data) 56 | : CDataInitializer(), _data(data) 57 | { 58 | } 59 | 60 | string CDataInitString::GetData(void) const 61 | { 62 | return _data; 63 | } 64 | 65 | ostream& CDataInitString::print(ostream &out, int indent) const 66 | { 67 | string ind(indent, ' '); 68 | 69 | out << ind << "[ data: '" << _data << "' ]"; 70 | return out; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /2.Parsing/snuplc/src/test_scanner.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SNUPL scanner test 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2012/09/14 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2012-2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "scanner.h" 38 | using namespace std; 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | int i = 1; 43 | 44 | while (i < argc) { 45 | CScanner *s = new CScanner(new ifstream(argv[i])); 46 | 47 | cout << "scanning '" << argv[i] << "'..." << endl; 48 | 49 | if (!s->Good()) cout << " cannot open input stream: " << s->Peek() << endl; 50 | 51 | while (s->Good()) { 52 | CToken t = s->Get(); 53 | cout << " " << t << endl; 54 | if (t.GetType() == tEOF) break; 55 | } 56 | 57 | cout << endl << endl; 58 | 59 | i++; 60 | } 61 | 62 | cout << "Done." << endl; 63 | 64 | return EXIT_SUCCESS; 65 | } 66 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/SnuPL-1/test01.mod: -------------------------------------------------------------------------------- 1 | 1 := 5; 2 | 3 | 1 := 2 + 3; 4 | 5 | 5 := 2 + 3 * (1 - 2 - 3 + 1) 6 | . 7 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/SnuPL-1/test02.mod: -------------------------------------------------------------------------------- 1 | 1 := 2 + 3; 2 | 3 | 4 := 5 * 6; 4 | 5 | . 6 | 7 | 7 := 8 - 9; 8 | 9 | . 10 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/SnuPL-1/test03.mod: -------------------------------------------------------------------------------- 1 | 1 := 2 + 3; 2 | 3 | 4 := 5 * 6 4 | 5 | . 6 | 7 | 7 := 8 - 9 8 | 9 | . 10 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/SnuPL-1/test04.mod: -------------------------------------------------------------------------------- 1 | 1 := 5 = 4; 2 | 3 | 2 := 1 = (2 # (3 = 4)); 4 | 5 | 3 := 1 + (1 # 1) / 4 + 4; 6 | 7 | 1 := 1; 2 := 2; 3 := 3 8 | . 9 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/SnuPL-1/test05.mod: -------------------------------------------------------------------------------- 1 | 1 := 5 = 4; 2 | 3 | 2 := 1 = 2 # 3 = 4; 4 | 5 | 3 := 1 + 1 # 1 / 4 + 4; 6 | . 7 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array.mod: -------------------------------------------------------------------------------- 1 | module array; 2 | 3 | var a,b,c: integer[5][5]; 4 | 5 | procedure add(A,B,C: integer[5][5]); 6 | var i,j: integer; 7 | begin 8 | i := 0; 9 | while (i < 5) do 10 | j := 0; 11 | while (j < 5) do 12 | C[i][j] := A[i][j] + B[i][j] 13 | end 14 | end 15 | end add; 16 | 17 | procedure addB(A,B,C: integer[][]); 18 | var i,j: integer; 19 | begin 20 | i := 0; 21 | while (i < 5) do 22 | j := 0; 23 | while (j < 5) do 24 | C[i][j] := A[i][j] + B[i][j] 25 | end 26 | end 27 | end addB; 28 | 29 | begin 30 | add(a,b,c) 31 | end array. 32 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | 5 | module array01; 6 | 7 | var A : integer[5][5]; 8 | 9 | begin 10 | A[0][1] := A[2][3] 11 | end array01. 12 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array02; 8 | 9 | var A : integer[5][5]; 10 | 11 | begin 12 | A[2][3] := ReadInt(); 13 | A[0][1] := A[2][3]; 14 | WriteInt(A[0][1]); WriteLn() 15 | end array02. 16 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array03; 8 | 9 | var A: integer[5]; 10 | i: integer; 11 | 12 | procedure Set(P: integer[]; v: integer); 13 | begin 14 | P[v] := 1 15 | end Set; 16 | 17 | procedure print; 18 | var i: integer; 19 | begin 20 | i := 0; 21 | while (i < 5) do 22 | WriteInt(A[i]); WriteLn(); 23 | i := i+1 24 | end 25 | end print; 26 | 27 | begin 28 | WriteInt(11111111); WriteLn(); 29 | print(); 30 | A[2] := 3; 31 | i := A[2]; 32 | Set(A, i); 33 | WriteInt(22222222); WriteLn(); 34 | print() 35 | end array03. 36 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array04; 8 | 9 | var A: integer[3][3]; 10 | i: integer; 11 | 12 | procedure Set(P: integer[][]; v: integer); 13 | begin 14 | P[v][v] := 1 15 | end Set; 16 | 17 | procedure print; 18 | var i,j: integer; 19 | begin 20 | i := 0; 21 | while (i < 3) do 22 | j := 0; 23 | while (j < 3) do 24 | WriteInt(A[i][j]); 25 | j := j+1 26 | end; 27 | i := i+1 28 | end; 29 | WriteLn() 30 | end print; 31 | 32 | begin 33 | WriteInt(11111111); WriteLn(); 34 | print(); 35 | A[0][0] := 2; 36 | i := A[0][0]; 37 | Set(A, i); 38 | WriteInt(22222222); WriteLn(); 39 | print() 40 | end array04. 41 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array05.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array05; 8 | 9 | var A: integer[3][3]; 10 | i: integer; 11 | 12 | procedure Set(P: integer[][]; v: integer); 13 | begin 14 | P[v][v] := 1 15 | end Set; 16 | 17 | procedure Print(A: integer[][]); 18 | var i,j,N,M: integer; 19 | begin 20 | N := DIM(A, 1); 21 | M := DIM(A, 2); 22 | i := 0; 23 | while (i < N) do 24 | j := 0; 25 | while (j < M) do 26 | WriteInt(A[i][j]); WriteLn(); 27 | j := j+1 28 | end; 29 | i := i+1 30 | end 31 | end Print; 32 | 33 | procedure Init(a: integer[][]); 34 | var i,j,N,M,c: integer; 35 | begin 36 | N := DIM(a, 1); 37 | M := DIM(a, 2); 38 | c := 0; 39 | i := 0; 40 | while (i < N) do 41 | j := 0; 42 | while (j < M) do 43 | a[i][j] := c; 44 | c := c + 1; 45 | j := j+1 46 | end; 47 | i := i+1 48 | end; 49 | Print(a) 50 | end Init; 51 | 52 | begin 53 | WriteInt(11111111); WriteLn(); 54 | Print(A); 55 | WriteInt(22222222); WriteLn(); 56 | Init(A) 57 | end array05. 58 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array06.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array06; 8 | 9 | procedure Print(A: integer[][]); 10 | var i,j,N,M: integer; 11 | begin 12 | N := DIM(A, 1); 13 | M := DIM(A, 2); 14 | i := 0; 15 | while (i < N) do 16 | j := 0; 17 | while (j < M) do 18 | WriteInt(A[i][j]); WriteLn(); 19 | j := j+1 20 | end; 21 | i := i+1 22 | end 23 | end Print; 24 | 25 | procedure Init(a: integer[][]); 26 | var i,j,N,M,c: integer; 27 | begin 28 | N := DIM(a, 1); 29 | M := DIM(a, 2); 30 | c := 0; 31 | i := 0; 32 | while (i < N) do 33 | j := 0; 34 | while (j < M) do 35 | a[i][j] := c; 36 | c := c + 1; 37 | j := j+1 38 | end; 39 | i := i+1 40 | end; 41 | Print(a) 42 | end Init; 43 | 44 | procedure Test; 45 | var x: integer[3][3]; 46 | begin 47 | WriteInt(11111111); WriteLn(); 48 | Print(x); 49 | WriteInt(22222222); WriteLn(); 50 | Init(x) 51 | end Test; 52 | 53 | begin 54 | Test() 55 | end array06. 56 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/array07.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array07; 8 | 9 | var sum: integer[5][5]; 10 | 11 | procedure Print(a: integer[][]); 12 | var i,j: integer; 13 | N,M: integer; 14 | begin 15 | N := DIM(a, 1); 16 | M := DIM(a, 2); 17 | 18 | i := 0; 19 | while (i < N) do 20 | j := 0; 21 | while (j < M) do 22 | WriteInt(a[i][j]); 23 | j := j+1 24 | end; 25 | i := i+1 26 | end 27 | end Print; 28 | 29 | procedure Init(a: integer[][]); 30 | var i,j,c: integer; 31 | N,M : integer; 32 | begin 33 | N := DIM(a, 1); 34 | M := DIM(a, 2); 35 | 36 | c := 0; 37 | i := 0; 38 | while (i < N) do 39 | j := 0; 40 | while (j < M) do 41 | a[i][j] := c; 42 | c := c + 1; 43 | j := j+1 44 | end; 45 | i := i+1 46 | end 47 | end Init; 48 | 49 | procedure Add(s1,s2,d: integer[][]); 50 | var i,j,c: integer; 51 | N,M : integer; 52 | begin 53 | N := DIM(d, 1); 54 | M := DIM(d, 2); 55 | 56 | c := 0; 57 | i := 0; 58 | while (i < N) do 59 | j := 0; 60 | while (j < M) do 61 | d[i][j] := s1[i][j] + s2[i][j]; 62 | c := c + 1; 63 | j := j+1 64 | end; 65 | i := i+1 66 | end 67 | end Add; 68 | 69 | procedure Test; 70 | var a,b: integer[5][5]; 71 | c: integer[5]; 72 | begin 73 | Init(a); 74 | Init(b); 75 | Add(a,b,sum) 76 | end Test; 77 | 78 | begin 79 | Test(); 80 | Print(sum) 81 | end array07. 82 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/char01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char01; 8 | 9 | var c: char; 10 | 11 | begin 12 | c := '1'; 13 | c := '\t'; 14 | WriteChar(c); 15 | WriteChar('!'); 16 | WriteLn() 17 | end char01. 18 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/char02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char02; 8 | 9 | var c: char; 10 | 11 | procedure compare(c: char); 12 | begin 13 | if (c >= '1') then WriteChar('1') 14 | else WriteChar('0') end; 15 | WriteLn() 16 | end compare; 17 | 18 | begin 19 | c := '1'; 20 | compare(c); 21 | compare('a'); 22 | compare('1'); 23 | compare('\0') 24 | end char02. 25 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/char03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char03; 8 | 9 | var i: integer; 10 | 11 | procedure PrintInt(v: integer); 12 | var r: integer; 13 | begin 14 | r := v - v / 10 * 10; 15 | v := v / 10; 16 | if (v > 0) then PrintInt(v) end; 17 | if (r = 0) then WriteChar('0') end; 18 | if (r = 1) then WriteChar('1') end; 19 | if (r = 2) then WriteChar('2') end; 20 | if (r = 3) then WriteChar('3') end; 21 | if (r = 4) then WriteChar('4') end; 22 | if (r = 5) then WriteChar('5') end; 23 | if (r = 6) then WriteChar('6') end; 24 | if (r = 7) then WriteChar('7') end; 25 | if (r = 8) then WriteChar('8') end; 26 | if (r = 9) then WriteChar('9') end 27 | end PrintInt; 28 | 29 | begin 30 | i := 1; 31 | while (i # 0) do 32 | i := ReadInt(); 33 | PrintInt(i); WriteLn() 34 | end 35 | end char03. 36 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/char04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char04; 8 | 9 | var a,b,c,d: char; 10 | 11 | begin 12 | if (a = b) then a := '0' end; 13 | if (a # b) then a := '1' end; 14 | if (a < b) then a := '7' end; 15 | if (a > b) then a := '6' end; 16 | //if (a + b < '9') then a := '6' end; 17 | //if (a * b = '0') then a := '0' end 18 | end char04. 19 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error01.mod: -------------------------------------------------------------------------------- 1 | // error01 2 | 3 | module error01; 4 | 5 | begin 6 | 7 | end __error01__. 8 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error02.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest05; 4 | 5 | var a,b,c,d,a : integer; 6 | 7 | begin 8 | WriteStr("Hello, World\n") 9 | end pstest05. 10 | 11 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error03.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest06; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | c : integer; 8 | 9 | begin 10 | WriteStr("Goodbye, World!\n"); 11 | end pstest06. 12 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error04.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure f; 9 | begin 10 | end f; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error05.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure foo(a,a : integer); 9 | begin 10 | end foo; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error06.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure foo(a : integer; a : integer); 9 | begin 10 | end foo; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error07.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure foo(a : integer; foo : integer); 9 | begin 10 | end foo; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error08.mod: -------------------------------------------------------------------------------- 1 | // re-declaration function 2 | 3 | module super_fantasy_war; 4 | 5 | var f : integer; 6 | 7 | function f(a,b : integer) : integer; 8 | begin 9 | return a+b 10 | end f; 11 | 12 | begin 13 | WriteInt(f(1,2)) 14 | end super_fantasy_war. 15 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error09.mod: -------------------------------------------------------------------------------- 1 | // undeclared variable 2 | 3 | module topdown; 4 | 5 | var a,b : integer; 6 | 7 | begin 8 | WriteInt(a+b+c) 9 | end topdown. 10 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/error10.mod: -------------------------------------------------------------------------------- 1 | // procedure identifier mismatched 2 | 3 | module p; 4 | 5 | procedure input(); 6 | begin 7 | ReadInt() 8 | end intput; 9 | 10 | begin 11 | input() 12 | end p. 13 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/my0.mod: -------------------------------------------------------------------------------- 1 | module my0; 2 | 3 | var A: integer[10]; 4 | i: integer; 5 | 6 | procedure merge(A: integer[]; i,j: integer); 7 | var B: integer[10]; 8 | p,mid,fig1,fig2: integer; 9 | begin 10 | p := i; 11 | mid := (i + j) / 2; 12 | fig1 := i; 13 | fig2 := mid + 1; 14 | 15 | while ((p <= j) && (fig1 <= mid) && (fig2 <= j)) do 16 | if (A[fig1] > A[fig2]) 17 | then 18 | B[p] := A[fig2]; 19 | fig2 := fig2 + 1 20 | else 21 | B[p] := A[fig1]; 22 | fig1 := fig1 + 1 23 | end; 24 | p := p + 1 25 | end; 26 | 27 | if (fig1 > mid) then 28 | while (fig2 <= j) do 29 | B[p] := A[fig2]; 30 | 31 | p := p + 1; 32 | fig2 := fig2 + 1 33 | end 34 | end; 35 | 36 | if (fig2 > j) then 37 | while (fig1 <= mid) do 38 | B[p] := A[fig1]; 39 | 40 | p := p + 1; 41 | fig1 := fig1 + 1 42 | end 43 | end 44 | 45 | end merge; 46 | 47 | procedure mergesort(A: integer[]; i,j: integer); 48 | var mid: integer; 49 | begin 50 | if (!(i < j)) then 51 | return 52 | end; 53 | 54 | mid := (i + j) / 2; 55 | 56 | mergesort(A, i, mid); 57 | mergesort(A, mid + 1, j); 58 | 59 | merge(A, i, j) 60 | end mergesort; 61 | 62 | procedure Init(A: integer[]); 63 | begin 64 | i := 0; 65 | while (i < 10) do 66 | A[9 - i] := i 67 | end; 68 | mergesort(A, 0, 9) 69 | end Init; 70 | 71 | procedure Print(A: integer[]); 72 | var N: integer; 73 | begin 74 | N := DIM(A, 1); 75 | 76 | i := 0; 77 | while (i < N) do 78 | WriteInt(A[i]) 79 | end 80 | end Print; 81 | 82 | begin 83 | Init(A); 84 | Print(A) 85 | end my0. 86 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/pstest01.mod: -------------------------------------------------------------------------------- 1 | // welcome to nested factor hellgate. 2 | 3 | module pstest01; 4 | 5 | var b, c, d, e: integer; 6 | 7 | function f(a,b,c : integer) : integer; 8 | begin 9 | return -a+(-b+c) 10 | end f; 11 | 12 | begin 13 | 14 | b := +c*12345+c||true/'D'&&"I"-f(1,2,3)+(+d-123456789)+!true/e+987654321-'D'&&false&&"EGGER"+(-f(9,8,7)#-true||false)||"U" 15 | 16 | end pstest01. 17 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/pstest02.mod: -------------------------------------------------------------------------------- 1 | // add, minus, mul, div, equal, A+B problem 2 | 3 | module pstest02; 4 | 5 | var a,b,c,d,e,f : integer; g : boolean; 6 | 7 | function add(a:integer; b:integer) : integer; 8 | begin 9 | return a + b 10 | end add; 11 | 12 | function minus(a:integer; b:integer) : integer; 13 | begin 14 | return a - b 15 | end minus; 16 | 17 | function mul(a:integer; b:integer) : integer; 18 | begin 19 | return a * b 20 | end mul; 21 | 22 | function div(a:integer; b:integer) : integer; 23 | begin 24 | return a / b 25 | end div; 26 | 27 | function equal(a:integer; b:integer) : boolean; 28 | begin 29 | return a = b 30 | end equal; 31 | 32 | procedure printAdd(a:integer; b:integer); 33 | begin 34 | WriteInt(a+b) 35 | end printAdd; 36 | 37 | begin 38 | a := 1; b := 2; 39 | c := add(a,b); 40 | d := minus(a,b); 41 | e := mul(a,b); 42 | f := div(a,b); 43 | g := equal(a,b); 44 | printAdd(a,b) 45 | end pstest02. 46 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/pstest03.mod: -------------------------------------------------------------------------------- 1 | // find element in array 2 | 3 | module heehoon; 4 | 5 | var a : integer[111111]; 6 | x,n,i : integer; 7 | 8 | function find (arr : integer[]; elem : integer) : boolean; 9 | var i,N : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | while (i < N) do 13 | if (arr[i] = elem) then 14 | return true 15 | end; 16 | i := i+1 17 | end; 18 | return false 19 | end find; 20 | 21 | begin 22 | n := ReadInt(); 23 | 24 | i := 0; 25 | while (i < n) do 26 | a[i] := ReadInt() 27 | end; 28 | 29 | x := ReadInt(); 30 | 31 | if (find(a,x)) then 32 | WriteStr("Found") 33 | else 34 | WriteStr("Not Found. I EGGER U") 35 | end; 36 | WriteLn() 37 | end heehoon. 38 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/pstest04.mod: -------------------------------------------------------------------------------- 1 | // find 2 | 3 | module pstest04; 4 | 5 | var a : integer[1111][1111]; 6 | n, m, i, j : integer; 7 | 8 | function sum (arr : integer[][]) : integer; 9 | var ret, N, M, i, j : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | M := DIM(arr, 2); 13 | 14 | i := 0; 15 | while (i < N) do 16 | j := 0; 17 | while (j < M) do 18 | ret := ret + arr[i][j]; 19 | j := j+1 20 | end; 21 | i := i+1 22 | end; 23 | return ret 24 | end sum; 25 | 26 | begin 27 | n := ReadInt(); 28 | m := ReadInt(); 29 | 30 | i := 0; 31 | while (i < n) do 32 | j := 0; 33 | while (j < m) do 34 | a[i][j] := ReadInt(); 35 | j := j+1 36 | end; 37 | i := i+1 38 | end; 39 | 40 | WriteInt(sum(a)); 41 | WriteLn() 42 | end pstest04. 43 | 44 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/string01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // strings 3 | // 4 | 5 | module string01; 6 | 7 | begin 8 | WriteStr("Hello, world\n"); 9 | WriteStr("This is pretty nice!\n\n") 10 | end string01. 11 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/string02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // strings 3 | // 4 | 5 | module string02; 6 | 7 | var age, year: integer; 8 | 9 | begin 10 | WriteStr("Enter your age: "); age := ReadInt(); 11 | WriteStr("Enter the year: "); year := ReadInt(); 12 | 13 | WriteStr("You will be 100 years old in the year "); 14 | WriteInt(year + 100 - age); 15 | WriteStr(".\n") 16 | end string02. 17 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/test03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test03 3 | // 4 | // parser test: syntax errors 5 | // - module identifier does not match 6 | // - function identifier does not match 7 | // - procedure with a return type 8 | // - function without a return type 9 | // - extra semicolon at end of statement sequence 10 | // - module body missing 11 | // 12 | // The errors must be eliminated one by one for testing since the compiler 13 | // aborts at the first error. 14 | // 15 | 16 | // change "test03_wrong" -> "test03" to eliminate 17 | module test03; 18 | 19 | // change "foox" -> "foo" to eliminate 20 | function foo(): integer; 21 | begin 22 | end foox; 23 | 24 | // change "procedure" -> "function" to eliminate 25 | procedure bar: integer; 26 | begin 27 | end bar; 28 | 29 | // add return type to eliminate 30 | function foobar(); 31 | begin 32 | // remove semicolon to eliminate 33 | return 1; 34 | end foobar; 35 | 36 | // add "begin" to eliminate 37 | end test03_wrong. 38 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/test04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test04 3 | // 4 | // parser test: 5 | // - global integer variables 6 | // - module body 7 | // - integer expressions 8 | // 9 | 10 | module test04; 11 | 12 | var a,b,c : integer; 13 | 14 | begin 15 | a := 1; 16 | b := 2; 17 | c := 3; 18 | 19 | a := a + b + c; 20 | b := a - b - c; 21 | c := a + b * c; 22 | a := -a; 23 | b := (a + b) / c; 24 | c := -(-1 + a) 25 | end test04. 26 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/test05.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test05 3 | // 4 | // parser test: 5 | // - test integer constant limits 6 | // (its okay to catch (+)2147483648 later during type checking) 7 | // 8 | module test05; 9 | 10 | var min, max: integer; 11 | 12 | begin 13 | // smallest valid integer constant 14 | min := -2147483648; 15 | 16 | // largest valid integer constant 17 | max := 2147483647 18 | end test05. 19 | -------------------------------------------------------------------------------- /2.Parsing/test/parser/test06.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test06 3 | // 4 | // parser test: 5 | // - integer & boolean, binary and unary expressions 6 | // 7 | module test06; 8 | 9 | var a,b,c: integer; 10 | b0,b1: boolean; 11 | 12 | procedure foo(a: integer); 13 | var b: integer; 14 | begin 15 | b := c; 16 | c := (a+b) 17 | end foo; 18 | 19 | procedure unary(); 20 | begin 21 | a := -b; 22 | b0 := !b1 23 | end unary; 24 | 25 | function binop(p0, p1: integer): boolean; 26 | begin 27 | return !((-p0+p1 > 0) || (p0 > 0) && (p1 < 0)) 28 | end binop; 29 | 30 | function intop(p0, p1: integer): integer; 31 | begin 32 | return -p0 + (+p1) 33 | end intop; 34 | 35 | function compare(a, b: integer): boolean; 36 | begin 37 | if (binop(a, b) && (intop(b, a) < a) && (a # b)) then 38 | return true 39 | else 40 | return false 41 | end 42 | end compare; 43 | 44 | begin 45 | end test06. 46 | -------------------------------------------------------------------------------- /2.Parsing/test/scanner/SnuPL-1/test01.mod: -------------------------------------------------------------------------------- 1 | := 2 | + 3 | - 4 | * 5 | / 6 | 7 | = 8 | # 9 | 10 | ; 11 | . 12 | ( 13 | ) 14 | 15 | 0 16 | 1 17 | 2147483647 18 | 2147483648 19 | 000000000000000000 20 | 999999999999999999 21 | -------------------------------------------------------------------------------- /2.Parsing/test/scanner/SnuPL-1/test02.mod: -------------------------------------------------------------------------------- 1 | =:==#:=;;;1(2);1:=-1.1;5::==5; 2 | 3 | 4 | a 5 | b 6 | c 7 | [ 8 | ] 9 | { 10 | } 11 | ? 12 | ^ 13 | \ 14 | -------------------------------------------------------------------------------- /2.Parsing/test/scanner/SnuPL-1/test03.mod: -------------------------------------------------------------------------------- 1 | 1 := 5; 2 | 3 | 1 := 2 + 3; 4 | 5 | 5 := 2 + 3 * (1 - 2 - 3 + 1) 6 | . 7 | -------------------------------------------------------------------------------- /2.Parsing/test/scanner/test01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test01 3 | // 4 | // scanner test: contains only valid tokens 5 | // 6 | 7 | // keywords 8 | 9 | module 10 | procedure 11 | function 12 | var 13 | integer 14 | boolean 15 | begin 16 | end 17 | if 18 | then 19 | else 20 | while 21 | do 22 | return 23 | true 24 | false 25 | 26 | // operators 27 | := 28 | + 29 | - 30 | * 31 | / 32 | || 33 | && 34 | ! 35 | 36 | // relops 37 | < 38 | <= 39 | = 40 | >= 41 | > 42 | # 43 | 44 | // syntax elements 45 | , 46 | ; 47 | : 48 | . 49 | ( 50 | ) 51 | 52 | // identifiers 53 | a 54 | b 55 | c 56 | temp1 57 | iftemp 58 | elsetemp 59 | _tmp1 60 | _____t 61 | 62 | // numbers 63 | 0 64 | 1 65 | 2147483647 66 | 2147483648 67 | 000000000000000000 68 | 999999999999999999 69 | -------------------------------------------------------------------------------- /2.Parsing/test/scanner/test02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test02 3 | // 4 | // scanner test: contains valid and invalid tokens 5 | // 6 | 7 | // scannable input 8 | <===>=#:=:::==>;;;if(then)else;a:=-1.1;a::==0x5; 9 | 1a2b 10 | 11 | // invalid input 12 | [ 13 | ] 14 | { 15 | } 16 | ? 17 | ^ 18 | \ 19 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/3.Semantic.Analysis.Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/3.Semantic.Analysis/3.Semantic.Analysis.Report.pdf -------------------------------------------------------------------------------- /3.Semantic.Analysis/3.Semantic.Analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/3.Semantic.Analysis/3.Semantic.Analysis.pdf -------------------------------------------------------------------------------- /3.Semantic.Analysis/compare: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | rm -f ./me ./egger 3 | find test/semanal -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "snuplc/test_parser {} >> me" 4 | find test/semanal -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "reference/3_test_parser {} >> egger" 5 | 6 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/reference/3_test_parser: -------------------------------------------------------------------------------- 1 | 3_test_parser.simple -------------------------------------------------------------------------------- /3.Semantic.Analysis/reference/3_test_parser.relaxed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/3.Semantic.Analysis/reference/3_test_parser.relaxed -------------------------------------------------------------------------------- /3.Semantic.Analysis/reference/3_test_parser.simple: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/3.Semantic.Analysis/reference/3_test_parser.simple -------------------------------------------------------------------------------- /3.Semantic.Analysis/reference/3_test_parser.strict: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/3.Semantic.Analysis/reference/3_test_parser.strict -------------------------------------------------------------------------------- /3.Semantic.Analysis/snuplc/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CCFLAGS=-std=c++0x -g -O0 3 | 4 | SRC_DIR=src 5 | OBJ_DIR=obj 6 | 7 | DEPS=scanner.h \ 8 | parser.h \ 9 | type.h \ 10 | data.h \ 11 | symtab.h \ 12 | ast.h \ 13 | ir.h 14 | SCANNER=scanner.cpp 15 | PARSER=parser.cpp \ 16 | type.cpp \ 17 | data.cpp \ 18 | symtab.cpp \ 19 | ast.cpp \ 20 | ir.cpp 21 | 22 | DEPS_=$(patsubst %,$(SRC_DIR)/%,$(DEPS)) 23 | OBJ_SCANNER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SCANNER)) 24 | OBJ_PARSER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(PARSER) $(SCANNER)) 25 | 26 | .PHONY: clean doc 27 | 28 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS_) 29 | $(CC) $(CCFLAGS) -c -o $@ $< 30 | 31 | all: test_scanner test_parser 32 | 33 | test_scanner: $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 34 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 35 | 36 | test_parser: $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 37 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 38 | 39 | doc: 40 | doxygen 41 | 42 | clean: 43 | rm -rf $(OBJ_DIR)/*.o test_scanner test_parser 44 | 45 | mrproper: clean 46 | rm -rf doc/* 47 | 48 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/snuplc/src/data.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SnuPL data initializers 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2016/04/05 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | 36 | #include "data.h" 37 | using namespace std; 38 | 39 | 40 | //------------------------------------------------------------------------------ 41 | // CDataInitializer 42 | // 43 | CDataInitializer::CDataInitializer(void) 44 | { 45 | } 46 | 47 | CDataInitializer::~CDataInitializer(void) 48 | { 49 | } 50 | 51 | ostream& operator<<(ostream &out, const CDataInitializer &t) 52 | { 53 | return t.print(out); 54 | } 55 | 56 | ostream& operator<<(ostream &out, const CDataInitializer *t) 57 | { 58 | return t->print(out); 59 | } 60 | 61 | 62 | //------------------------------------------------------------------------------ 63 | // CDataInitString 64 | // 65 | CDataInitString::CDataInitString(const string data) 66 | : CDataInitializer(), _data(data) 67 | { 68 | } 69 | 70 | string CDataInitString::GetData(void) const 71 | { 72 | return _data; 73 | } 74 | 75 | ostream& CDataInitString::print(ostream &out, int indent) const 76 | { 77 | string ind(indent, ' '); 78 | 79 | out << ind << "[ data: '" << _data << "' ]"; 80 | return out; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/snuplc/src/old/data.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SnuPL data initializers 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2016/04/05 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | 36 | #include "data.h" 37 | using namespace std; 38 | 39 | 40 | //------------------------------------------------------------------------------ 41 | // CDataInitializer 42 | // 43 | CDataInitializer::CDataInitializer(void) 44 | { 45 | } 46 | 47 | CDataInitializer::~CDataInitializer(void) 48 | { 49 | } 50 | 51 | ostream& operator<<(ostream &out, const CDataInitializer &t) 52 | { 53 | return t.print(out); 54 | } 55 | 56 | ostream& operator<<(ostream &out, const CDataInitializer *t) 57 | { 58 | return t->print(out); 59 | } 60 | 61 | 62 | //------------------------------------------------------------------------------ 63 | // CDataInitString 64 | // 65 | CDataInitString::CDataInitString(const string data) 66 | : CDataInitializer(), _data(data) 67 | { 68 | } 69 | 70 | string CDataInitString::GetData(void) const 71 | { 72 | return _data; 73 | } 74 | 75 | ostream& CDataInitString::print(ostream &out, int indent) const 76 | { 77 | string ind(indent, ' '); 78 | 79 | out << ind << "[ data: '" << _data << "' ]"; 80 | return out; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/snuplc/src/test_scanner.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SNUPL scanner test 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2012/09/14 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2012-2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "scanner.h" 38 | using namespace std; 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | int i = 1; 43 | 44 | while (i < argc) { 45 | CScanner *s = new CScanner(new ifstream(argv[i])); 46 | 47 | cout << "scanning '" << argv[i] << "'..." << endl; 48 | 49 | if (!s->Good()) cout << " cannot open input stream: " << s->Peek() << endl; 50 | 51 | while (s->Good()) { 52 | CToken t = s->Get(); 53 | cout << " " << t << endl; 54 | if (t.GetType() == tEOF) break; 55 | } 56 | 57 | cout << endl << endl; 58 | 59 | i++; 60 | } 61 | 62 | cout << "Done." << endl; 63 | 64 | return EXIT_SUCCESS; 65 | } 66 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/SnuPL-1/test01.mod: -------------------------------------------------------------------------------- 1 | 1 := 5; 2 | 3 | 1 := 2 + 3; 4 | 5 | 5 := 2 + 3 * (1 - 2 - 3 + 1) 6 | . 7 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/SnuPL-1/test02.mod: -------------------------------------------------------------------------------- 1 | 1 := 2 + 3; 2 | 3 | 4 := 5 * 6; 4 | 5 | . 6 | 7 | 7 := 8 - 9; 8 | 9 | . 10 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/SnuPL-1/test03.mod: -------------------------------------------------------------------------------- 1 | 1 := 2 + 3; 2 | 3 | 4 := 5 * 6 4 | 5 | . 6 | 7 | 7 := 8 - 9 8 | 9 | . 10 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/SnuPL-1/test04.mod: -------------------------------------------------------------------------------- 1 | 1 := 5 = 4; 2 | 3 | 2 := 1 = (2 # (3 = 4)); 4 | 5 | 3 := 1 + (1 # 1) / 4 + 4; 6 | 7 | 1 := 1; 2 := 2; 3 := 3 8 | . 9 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/SnuPL-1/test05.mod: -------------------------------------------------------------------------------- 1 | 1 := 5 = 4; 2 | 3 | 2 := 1 = 2 # 3 = 4; 4 | 5 | 3 := 1 + 1 # 1 / 4 + 4; 6 | . 7 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array.mod: -------------------------------------------------------------------------------- 1 | module array; 2 | 3 | var a,b,c: integer[5][5]; 4 | 5 | procedure add(A,B,C: integer[5][5]); 6 | var i,j: integer; 7 | begin 8 | i := 0; 9 | while (i < 5) do 10 | j := 0; 11 | while (j < 5) do 12 | C[i][j] := A[i][j] + B[i][j] 13 | end 14 | end 15 | end add; 16 | 17 | procedure addB(A,B,C: integer[][]); 18 | var i,j: integer; 19 | begin 20 | i := 0; 21 | while (i < 5) do 22 | j := 0; 23 | while (j < 5) do 24 | C[i][j] := A[i][j] + B[i][j] 25 | end 26 | end 27 | end addB; 28 | 29 | begin 30 | add(a,b,c) 31 | end array. 32 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | 5 | module array01; 6 | 7 | var A : integer[5][5]; 8 | 9 | begin 10 | A[0][1] := A[2][3] 11 | end array01. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array02; 8 | 9 | var A : integer[5][5]; 10 | 11 | begin 12 | A[2][3] := ReadInt(); 13 | A[0][1] := A[2][3]; 14 | WriteInt(A[0][1]); WriteLn() 15 | end array02. 16 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array03; 8 | 9 | var A: integer[5]; 10 | i: integer; 11 | 12 | procedure Set(P: integer[]; v: integer); 13 | begin 14 | P[v] := 1 15 | end Set; 16 | 17 | procedure print; 18 | var i: integer; 19 | begin 20 | i := 0; 21 | while (i < 5) do 22 | WriteInt(A[i]); WriteLn(); 23 | i := i+1 24 | end 25 | end print; 26 | 27 | begin 28 | WriteInt(11111111); WriteLn(); 29 | print(); 30 | A[2] := 3; 31 | i := A[2]; 32 | Set(A, i); 33 | WriteInt(22222222); WriteLn(); 34 | print() 35 | end array03. 36 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array04; 8 | 9 | var A: integer[3][3]; 10 | i: integer; 11 | 12 | procedure Set(P: integer[][]; v: integer); 13 | begin 14 | P[v][v] := 1 15 | end Set; 16 | 17 | procedure print; 18 | var i,j: integer; 19 | begin 20 | i := 0; 21 | while (i < 3) do 22 | j := 0; 23 | while (j < 3) do 24 | WriteInt(A[i][j]); 25 | j := j+1 26 | end; 27 | i := i+1 28 | end; 29 | WriteLn() 30 | end print; 31 | 32 | begin 33 | WriteInt(11111111); WriteLn(); 34 | print(); 35 | A[0][0] := 2; 36 | i := A[0][0]; 37 | Set(A, i); 38 | WriteInt(22222222); WriteLn(); 39 | print() 40 | end array04. 41 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array05.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array05; 8 | 9 | var A: integer[3][3]; 10 | i: integer; 11 | 12 | procedure Set(P: integer[][]; v: integer); 13 | begin 14 | P[v][v] := 1 15 | end Set; 16 | 17 | procedure Print(A: integer[][]); 18 | var i,j,N,M: integer; 19 | begin 20 | N := DIM(A, 1); 21 | M := DIM(A, 2); 22 | i := 0; 23 | while (i < N) do 24 | j := 0; 25 | while (j < M) do 26 | WriteInt(A[i][j]); WriteLn(); 27 | j := j+1 28 | end; 29 | i := i+1 30 | end 31 | end Print; 32 | 33 | procedure Init(a: integer[][]); 34 | var i,j,N,M,c: integer; 35 | begin 36 | N := DIM(a, 1); 37 | M := DIM(a, 2); 38 | c := 0; 39 | i := 0; 40 | while (i < N) do 41 | j := 0; 42 | while (j < M) do 43 | a[i][j] := c; 44 | c := c + 1; 45 | j := j+1 46 | end; 47 | i := i+1 48 | end; 49 | Print(a) 50 | end Init; 51 | 52 | begin 53 | WriteInt(11111111); WriteLn(); 54 | Print(A); 55 | WriteInt(22222222); WriteLn(); 56 | Init(A) 57 | end array05. 58 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array06.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array06; 8 | 9 | procedure Print(A: integer[][]); 10 | var i,j,N,M: integer; 11 | begin 12 | N := DIM(A, 1); 13 | M := DIM(A, 2); 14 | i := 0; 15 | while (i < N) do 16 | j := 0; 17 | while (j < M) do 18 | WriteInt(A[i][j]); WriteLn(); 19 | j := j+1 20 | end; 21 | i := i+1 22 | end 23 | end Print; 24 | 25 | procedure Init(a: integer[][]); 26 | var i,j,N,M,c: integer; 27 | begin 28 | N := DIM(a, 1); 29 | M := DIM(a, 2); 30 | c := 0; 31 | i := 0; 32 | while (i < N) do 33 | j := 0; 34 | while (j < M) do 35 | a[i][j] := c; 36 | c := c + 1; 37 | j := j+1 38 | end; 39 | i := i+1 40 | end; 41 | Print(a) 42 | end Init; 43 | 44 | procedure Test; 45 | var x: integer[3][3]; 46 | begin 47 | WriteInt(11111111); WriteLn(); 48 | Print(x); 49 | WriteInt(22222222); WriteLn(); 50 | Init(x) 51 | end Test; 52 | 53 | begin 54 | Test() 55 | end array06. 56 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/array07.mod: -------------------------------------------------------------------------------- 1 | // 2 | // array declaration and definitions 3 | // 4 | // does not require string support 5 | // 6 | 7 | module array07; 8 | 9 | var sum: integer[5][5]; 10 | 11 | procedure Print(a: integer[][]); 12 | var i,j: integer; 13 | N,M: integer; 14 | begin 15 | N := DIM(a, 1); 16 | M := DIM(a, 2); 17 | 18 | i := 0; 19 | while (i < N) do 20 | j := 0; 21 | while (j < M) do 22 | WriteInt(a[i][j]); 23 | j := j+1 24 | end; 25 | i := i+1 26 | end 27 | end Print; 28 | 29 | procedure Init(a: integer[][]); 30 | var i,j,c: integer; 31 | N,M : integer; 32 | begin 33 | N := DIM(a, 1); 34 | M := DIM(a, 2); 35 | 36 | c := 0; 37 | i := 0; 38 | while (i < N) do 39 | j := 0; 40 | while (j < M) do 41 | a[i][j] := c; 42 | c := c + 1; 43 | j := j+1 44 | end; 45 | i := i+1 46 | end 47 | end Init; 48 | 49 | procedure Add(s1,s2,d: integer[][]); 50 | var i,j,c: integer; 51 | N,M : integer; 52 | begin 53 | N := DIM(d, 1); 54 | M := DIM(d, 2); 55 | 56 | c := 0; 57 | i := 0; 58 | while (i < N) do 59 | j := 0; 60 | while (j < M) do 61 | d[i][j] := s1[i][j] + s2[i][j]; 62 | c := c + 1; 63 | j := j+1 64 | end; 65 | i := i+1 66 | end 67 | end Add; 68 | 69 | procedure Test; 70 | var a,b: integer[5][5]; 71 | c: integer[5]; 72 | begin 73 | Init(a); 74 | Init(b); 75 | Add(a,b,sum) 76 | end Test; 77 | 78 | begin 79 | Test(); 80 | Print(sum) 81 | end array07. 82 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/char01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char01; 8 | 9 | var c: char; 10 | 11 | begin 12 | c := '1'; 13 | c := '\t'; 14 | WriteChar(c); 15 | WriteChar('!'); 16 | WriteLn() 17 | end char01. 18 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/char02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char02; 8 | 9 | var c: char; 10 | 11 | procedure compare(c: char); 12 | begin 13 | if (c >= '1') then WriteChar('1') 14 | else WriteChar('0') end; 15 | WriteLn() 16 | end compare; 17 | 18 | begin 19 | c := '1'; 20 | compare(c); 21 | compare('a'); 22 | compare('1'); 23 | compare('\0') 24 | end char02. 25 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/char03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char03; 8 | 9 | var i: integer; 10 | 11 | procedure PrintInt(v: integer); 12 | var r: integer; 13 | begin 14 | r := v - v / 10 * 10; 15 | v := v / 10; 16 | if (v > 0) then PrintInt(v) end; 17 | if (r = 0) then WriteChar('0') end; 18 | if (r = 1) then WriteChar('1') end; 19 | if (r = 2) then WriteChar('2') end; 20 | if (r = 3) then WriteChar('3') end; 21 | if (r = 4) then WriteChar('4') end; 22 | if (r = 5) then WriteChar('5') end; 23 | if (r = 6) then WriteChar('6') end; 24 | if (r = 7) then WriteChar('7') end; 25 | if (r = 8) then WriteChar('8') end; 26 | if (r = 9) then WriteChar('9') end 27 | end PrintInt; 28 | 29 | begin 30 | i := 1; 31 | while (i # 0) do 32 | i := ReadInt(); 33 | PrintInt(i); WriteLn() 34 | end 35 | end char03. 36 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/char04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // char declaration and definitions 3 | // 4 | // does not require array or string support 5 | // 6 | 7 | module char04; 8 | 9 | var a,b,c,d: char; 10 | 11 | begin 12 | if (a = b) then a := '0' end; 13 | if (a # b) then a := '1' end; 14 | if (a < b) then a := '7' end; 15 | if (a > b) then a := '6' end; 16 | //if (a + b < '9') then a := '6' end; 17 | //if (a * b = '0') then a := '0' end 18 | end char04. 19 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error01.mod: -------------------------------------------------------------------------------- 1 | // error01 2 | 3 | module error01; 4 | 5 | begin 6 | 7 | end __error01__. 8 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error02.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest05; 4 | 5 | var a,b,c,d,a : integer; 6 | 7 | begin 8 | WriteStr("Hello, World\n") 9 | end pstest05. 10 | 11 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error03.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest06; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | c : integer; 8 | 9 | begin 10 | WriteStr("Goodbye, World!\n"); 11 | end pstest06. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error04.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure f; 9 | begin 10 | end f; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error05.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure foo(a,a : integer); 9 | begin 10 | end foo; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error06.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure foo(a : integer; a : integer); 9 | begin 10 | end foo; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error07.mod: -------------------------------------------------------------------------------- 1 | // re-definition error 2 | 3 | module pstest07; 4 | 5 | var a,b,c : integer; 6 | d,e,f : integer; 7 | 8 | procedure foo(a : integer; foo : integer); 9 | begin 10 | end foo; 11 | 12 | begin 13 | WriteStr("Goodbye, World!\n"); 14 | end pstest07. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error08.mod: -------------------------------------------------------------------------------- 1 | // re-declaration function 2 | 3 | module super_fantasy_war; 4 | 5 | var f : integer; 6 | 7 | function f(a,b : integer) : integer; 8 | begin 9 | return a+b 10 | end f; 11 | 12 | begin 13 | WriteInt(f(1,2)) 14 | end super_fantasy_war. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error09.mod: -------------------------------------------------------------------------------- 1 | // undeclared variable 2 | 3 | module topdown; 4 | 5 | var a,b : integer; 6 | 7 | begin 8 | WriteInt(a+b+c) 9 | end topdown. 10 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/error10.mod: -------------------------------------------------------------------------------- 1 | // procedure identifier mismatched 2 | 3 | module p; 4 | 5 | procedure input(); 6 | begin 7 | ReadInt() 8 | end intput; 9 | 10 | begin 11 | input() 12 | end p. 13 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/my0.mod: -------------------------------------------------------------------------------- 1 | module my0; 2 | 3 | var A: integer[10]; 4 | i: integer; 5 | 6 | procedure merge(A: integer[]; i,j: integer); 7 | var B: integer[10]; 8 | p,mid,fig1,fig2: integer; 9 | begin 10 | p := i; 11 | mid := (i + j) / 2; 12 | fig1 := i; 13 | fig2 := mid + 1; 14 | 15 | while ((p <= j) && (fig1 <= mid) && (fig2 <= j)) do 16 | if (A[fig1] > A[fig2]) 17 | then 18 | B[p] := A[fig2]; 19 | fig2 := fig2 + 1 20 | else 21 | B[p] := A[fig1]; 22 | fig1 := fig1 + 1 23 | end; 24 | p := p + 1 25 | end; 26 | 27 | if (fig1 > mid) then 28 | while (fig2 <= j) do 29 | B[p] := A[fig2]; 30 | 31 | p := p + 1; 32 | fig2 := fig2 + 1 33 | end 34 | end; 35 | 36 | if (fig2 > j) then 37 | while (fig1 <= mid) do 38 | B[p] := A[fig1]; 39 | 40 | p := p + 1; 41 | fig1 := fig1 + 1 42 | end 43 | end 44 | 45 | end merge; 46 | 47 | procedure mergesort(A: integer[]; i,j: integer); 48 | var mid: integer; 49 | begin 50 | if (!(i < j)) then 51 | return 52 | end; 53 | 54 | mid := (i + j) / 2; 55 | 56 | mergesort(A, i, mid); 57 | mergesort(A, mid + 1, j); 58 | 59 | merge(A, i, j) 60 | end mergesort; 61 | 62 | procedure Init(A: integer[]); 63 | begin 64 | i := 0; 65 | while (i < 10) do 66 | A[9 - i] := i 67 | end; 68 | mergesort(A, 0, 9) 69 | end Init; 70 | 71 | procedure Print(A: integer[]); 72 | var N: integer; 73 | begin 74 | N := DIM(A, 1); 75 | 76 | i := 0; 77 | while (i < N) do 78 | WriteInt(A[i]) 79 | end 80 | end Print; 81 | 82 | begin 83 | Init(A); 84 | Print(A) 85 | end my0. 86 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/pstest01.mod: -------------------------------------------------------------------------------- 1 | // welcome to nested factor hellgate. 2 | 3 | module pstest01; 4 | 5 | var b, c, d, e: integer; 6 | 7 | function f(a,b,c : integer) : integer; 8 | begin 9 | return -a+(-b+c) 10 | end f; 11 | 12 | begin 13 | 14 | b := +c*12345+c||true/'D'&&"I"-f(1,2,3)+(+d-123456789)+!true/e+987654321-'D'&&false&&"EGGER"+(-f(9,8,7)#-true||false)||"U" 15 | 16 | end pstest01. 17 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/pstest02.mod: -------------------------------------------------------------------------------- 1 | // add, minus, mul, div, equal, A+B problem 2 | 3 | module pstest02; 4 | 5 | var a,b,c,d,e,f : integer; g : boolean; 6 | 7 | function add(a:integer; b:integer) : integer; 8 | begin 9 | return a + b 10 | end add; 11 | 12 | function minus(a:integer; b:integer) : integer; 13 | begin 14 | return a - b 15 | end minus; 16 | 17 | function mul(a:integer; b:integer) : integer; 18 | begin 19 | return a * b 20 | end mul; 21 | 22 | function div(a:integer; b:integer) : integer; 23 | begin 24 | return a / b 25 | end div; 26 | 27 | function equal(a:integer; b:integer) : boolean; 28 | begin 29 | return a = b 30 | end equal; 31 | 32 | procedure printAdd(a:integer; b:integer); 33 | begin 34 | WriteInt(a+b) 35 | end printAdd; 36 | 37 | begin 38 | a := 1; b := 2; 39 | c := add(a,b); 40 | d := minus(a,b); 41 | e := mul(a,b); 42 | f := div(a,b); 43 | g := equal(a,b); 44 | printAdd(a,b) 45 | end pstest02. 46 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/pstest03.mod: -------------------------------------------------------------------------------- 1 | // find element in array 2 | 3 | module heehoon; 4 | 5 | var a : integer[111111]; 6 | x,n,i : integer; 7 | 8 | function find (arr : integer[]; elem : integer) : boolean; 9 | var i,N : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | while (i < N) do 13 | if (arr[i] = elem) then 14 | return true 15 | end; 16 | i := i+1 17 | end; 18 | return false 19 | end find; 20 | 21 | begin 22 | n := ReadInt(); 23 | 24 | i := 0; 25 | while (i < n) do 26 | a[i] := ReadInt() 27 | end; 28 | 29 | x := ReadInt(); 30 | 31 | if (find(a,x)) then 32 | WriteStr("Found") 33 | else 34 | WriteStr("Not Found. I EGGER U") 35 | end; 36 | WriteLn() 37 | end heehoon. 38 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/pstest04.mod: -------------------------------------------------------------------------------- 1 | // find 2 | 3 | module pstest04; 4 | 5 | var a : integer[1111][1111]; 6 | n, m, i, j : integer; 7 | 8 | function sum (arr : integer[][]) : integer; 9 | var ret, N, M, i, j : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | M := DIM(arr, 2); 13 | 14 | i := 0; 15 | while (i < N) do 16 | j := 0; 17 | while (j < M) do 18 | ret := ret + arr[i][j]; 19 | j := j+1 20 | end; 21 | i := i+1 22 | end; 23 | return ret 24 | end sum; 25 | 26 | begin 27 | n := ReadInt(); 28 | m := ReadInt(); 29 | 30 | i := 0; 31 | while (i < n) do 32 | j := 0; 33 | while (j < m) do 34 | a[i][j] := ReadInt(); 35 | j := j+1 36 | end; 37 | i := i+1 38 | end; 39 | 40 | WriteInt(sum(a)); 41 | WriteLn() 42 | end pstest04. 43 | 44 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/string01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // strings 3 | // 4 | 5 | module string01; 6 | 7 | begin 8 | WriteStr("Hello, world\n"); 9 | WriteStr("This is pretty nice!\n\n") 10 | end string01. 11 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/string02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // strings 3 | // 4 | 5 | module string02; 6 | 7 | var age, year: integer; 8 | 9 | begin 10 | WriteStr("Enter your age: "); age := ReadInt(); 11 | WriteStr("Enter the year: "); year := ReadInt(); 12 | 13 | WriteStr("You will be 100 years old in the year "); 14 | WriteInt(year + 100 - age); 15 | WriteStr(".\n") 16 | end string02. 17 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/test03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test03 3 | // 4 | // parser test: syntax errors 5 | // - module identifier does not match 6 | // - function identifier does not match 7 | // - procedure with a return type 8 | // - function without a return type 9 | // - extra semicolon at end of statement sequence 10 | // - module body missing 11 | // 12 | // The errors must be eliminated one by one for testing since the compiler 13 | // aborts at the first error. 14 | // 15 | 16 | // change "test03_wrong" -> "test03" to eliminate 17 | module test03; 18 | 19 | // change "foox" -> "foo" to eliminate 20 | function foo(): integer; 21 | begin 22 | end foox; 23 | 24 | // change "procedure" -> "function" to eliminate 25 | procedure bar: integer; 26 | begin 27 | end bar; 28 | 29 | // add return type to eliminate 30 | function foobar(); 31 | begin 32 | // remove semicolon to eliminate 33 | return 1; 34 | end foobar; 35 | 36 | // add "begin" to eliminate 37 | end test03_wrong. 38 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/test04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test04 3 | // 4 | // parser test: 5 | // - global integer variables 6 | // - module body 7 | // - integer expressions 8 | // 9 | 10 | module test04; 11 | 12 | var a,b,c : integer; 13 | 14 | begin 15 | a := 1; 16 | b := 2; 17 | c := 3; 18 | 19 | a := a + b + c; 20 | b := a - b - c; 21 | c := a + b * c; 22 | a := -a; 23 | b := (a + b) / c; 24 | c := -(-1 + a) 25 | end test04. 26 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/test05.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test05 3 | // 4 | // parser test: 5 | // - test integer constant limits 6 | // (its okay to catch (+)2147483648 later during type checking) 7 | // 8 | module test05; 9 | 10 | var min, max: integer; 11 | 12 | begin 13 | // smallest valid integer constant 14 | min := -2147483648; 15 | 16 | // largest valid integer constant 17 | max := 2147483647 18 | end test05. 19 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/parser/test06.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test06 3 | // 4 | // parser test: 5 | // - integer & boolean, binary and unary expressions 6 | // 7 | module test06; 8 | 9 | var a,b,c: integer; 10 | b0,b1: boolean; 11 | 12 | procedure foo(a: integer); 13 | var b: integer; 14 | begin 15 | b := c; 16 | c := (a+b) 17 | end foo; 18 | 19 | procedure unary(); 20 | begin 21 | a := -b; 22 | b0 := !b1 23 | end unary; 24 | 25 | function binop(p0, p1: integer): boolean; 26 | begin 27 | return !((-p0+p1 > 0) || (p0 > 0) && (p1 < 0)) 28 | end binop; 29 | 30 | function intop(p0, p1: integer): integer; 31 | begin 32 | return -p0 + (+p1) 33 | end intop; 34 | 35 | function compare(a, b: integer): boolean; 36 | begin 37 | if (binop(a, b) && (intop(b, a) < a) && (a # b)) then 38 | return true 39 | else 40 | return false 41 | end 42 | end compare; 43 | 44 | begin 45 | end test06. 46 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/scanner/SnuPL-1/test01.mod: -------------------------------------------------------------------------------- 1 | := 2 | + 3 | - 4 | * 5 | / 6 | 7 | = 8 | # 9 | 10 | ; 11 | . 12 | ( 13 | ) 14 | 15 | 0 16 | 1 17 | 2147483647 18 | 2147483648 19 | 000000000000000000 20 | 999999999999999999 21 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/scanner/SnuPL-1/test02.mod: -------------------------------------------------------------------------------- 1 | =:==#:=;;;1(2);1:=-1.1;5::==5; 2 | 3 | 4 | a 5 | b 6 | c 7 | [ 8 | ] 9 | { 10 | } 11 | ? 12 | ^ 13 | \ 14 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/scanner/SnuPL-1/test03.mod: -------------------------------------------------------------------------------- 1 | 1 := 5; 2 | 3 | 1 := 2 + 3; 4 | 5 | 5 := 2 + 3 * (1 - 2 - 3 + 1) 6 | . 7 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/scanner/test01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test01 3 | // 4 | // scanner test: contains only valid tokens 5 | // 6 | 7 | // keywords 8 | 9 | module 10 | procedure 11 | function 12 | var 13 | integer 14 | boolean 15 | begin 16 | end 17 | if 18 | then 19 | else 20 | while 21 | do 22 | return 23 | true 24 | false 25 | 26 | // operators 27 | := 28 | + 29 | - 30 | * 31 | / 32 | || 33 | && 34 | ! 35 | 36 | // relops 37 | < 38 | <= 39 | = 40 | >= 41 | > 42 | # 43 | 44 | // syntax elements 45 | , 46 | ; 47 | : 48 | . 49 | ( 50 | ) 51 | 52 | // identifiers 53 | a 54 | b 55 | c 56 | temp1 57 | iftemp 58 | elsetemp 59 | _tmp1 60 | _____t 61 | 62 | // numbers 63 | 0 64 | 1 65 | 2147483647 66 | 2147483648 67 | 000000000000000000 68 | 999999999999999999 69 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/scanner/test02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test02 3 | // 4 | // scanner test: contains valid and invalid tokens 5 | // 6 | 7 | // scannable input 8 | <===>=#:=:::==>;;;if(then)else;a:=-1.1;a::==0x5; 9 | 1a2b 10 | 11 | // invalid input 12 | [ 13 | ] 14 | { 15 | } 16 | ? 17 | ^ 18 | \ 19 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/arrays.mod: -------------------------------------------------------------------------------- 1 | // 2 | // arrays.mod 3 | // 4 | // specific semantic anaysis for arrays 5 | // - definition of arrays 6 | // - array element access 7 | // - array passing 8 | // - type checking 9 | // 10 | // * the reference implementation does not support assignments of arrays, 11 | // but allows assignments of pointers to arrays as long as the array 12 | // structure is compatible. 13 | 14 | module arrays; 15 | 16 | var A: integer[10]; // pass 17 | B: integer[10][5][10]; // pass 18 | //C: integer[]; // fail 19 | D: boolean[5]; // pass 20 | 21 | 22 | procedure p1(A,B: integer[]; C: integer[][][]); // pass 23 | var i: integer; 24 | c: char; 25 | b: boolean; 26 | X,Y: integer[5]; 27 | begin 28 | i := A[0]; // pass 29 | i := A[-1]; // pass 30 | i := A[i]; // pass 31 | i := A[A[A[i]]]; // pass 32 | 33 | //c := A[0]; // fail 34 | //b := A[0]; // fail 35 | 36 | A[0] := A[0]; // pass 37 | A := B; // pass (pointer-copy) 38 | //A := C; // fail (incompatible pointer types) 39 | //X := Y; // fail (array assignments not supported) 40 | 41 | //A := B[0]; // fail 42 | //A[0] := B; // fail 43 | 44 | //A[A] := i; // fail 45 | 46 | b := D[0]; // pass 47 | //i := D[0]; // fail 48 | 49 | i := 0 50 | end p1; 51 | 52 | procedure p2(a: integer[][5][]); // pass 53 | var b: integer[5][5][5]; // pass 54 | c: integer[5][7][9]; // pass 55 | //d: integer[][5][]; // fail 56 | begin 57 | p2(a); // pass 58 | //p2(1); // fail 59 | //p2(a[0]); // fail 60 | //p2(a, a); // fail 61 | 62 | p2(B); // pass 63 | p2(b); // pass 64 | p2(c); // fail 65 | 66 | a[0][0][0] := 0 67 | end p2; 68 | 69 | //function strcpy(src, dst: char[]): char[]; // fail 70 | //function strcpy(src, dst: char[]): char[5]; // fail 71 | function strcpy(src, dst: char[]): integer; // pass 72 | var res10: char[10]; 73 | res5 : char[5]; 74 | begin 75 | //return res10; // fail 76 | //return res5; // fail 77 | 78 | //return; // fail 79 | 80 | return 1 81 | end strcpy; 82 | 83 | begin 84 | end arrays. 85 | 86 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_1.mod: -------------------------------------------------------------------------------- 1 | module input; 2 | begin 3 | 4 | end intput; 5 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_2_1.mod: -------------------------------------------------------------------------------- 1 | module re_dec; 2 | 3 | procedure f(); 4 | var a : integer; 5 | b, a : boolean; 6 | begin 7 | 8 | end f; 9 | 10 | begin 11 | 12 | end re_dec. 13 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_2_2.mod: -------------------------------------------------------------------------------- 1 | module re_dec; 2 | 3 | procedure f(a : integer); 4 | var a : boolean; 5 | begin 6 | 7 | end f; 8 | 9 | begin 10 | 11 | end re_dec. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_2_3.mod: -------------------------------------------------------------------------------- 1 | module re_dec; 2 | 3 | procedure f(a : integer; a : boolean); 4 | begin 5 | end f; 6 | 7 | begin 8 | 9 | end re_dec. 10 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_2_4.mod: -------------------------------------------------------------------------------- 1 | module re_dec; 2 | var a,a : integer; 3 | 4 | begin 5 | 6 | end re_dec; 7 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_3.mod: -------------------------------------------------------------------------------- 1 | module undec; 2 | 3 | begin 4 | 5 | a := 3 6 | 7 | end undec. 8 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_4.mod: -------------------------------------------------------------------------------- 1 | module retarr; 2 | 3 | function f() : integer[3][5]; 4 | begin 5 | end f; 6 | 7 | begin 8 | 9 | end retarr. 10 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_5.mod: -------------------------------------------------------------------------------- 1 | module open; 2 | var a : integer[5][]; 3 | 4 | procedure f(a : integer[]); 5 | var b : integer[]; 6 | begin 7 | end f; 8 | 9 | begin 10 | 11 | end open. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_6.mod: -------------------------------------------------------------------------------- 1 | module index; 2 | 3 | var a : integer; 4 | 5 | procedure f(); 6 | begin 7 | // a[3] := 5 8 | end f; 9 | 10 | begin 11 | a[6] := true 12 | end index. 13 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_1_7.mod: -------------------------------------------------------------------------------- 1 | module invalid; 2 | 3 | var a : integer; 4 | 5 | begin 6 | a := 2147483647; // pass 7 | a := 2147483648; // fail (typecheck) 8 | a := 12346734652445364374623765345245647834735; // fail (parser) 9 | a := 1243513463764'u'124565376421234; // fail (parser) 10 | return 11 | end invalid. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_1.mod: -------------------------------------------------------------------------------- 1 | module assign; 2 | 3 | var a : integer; 4 | b : boolean; 5 | c : integer[3][4]; 6 | d : integer[5]; 7 | 8 | begin 9 | a := b; // fail 10 | c := a; // fail 11 | c := d; // fail 12 | c[0] := d; // fail 13 | d[0] := c[0]; // fail 14 | d[0] := c[0][0]; // pass 15 | return 16 | end assign. 17 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_10.mod: -------------------------------------------------------------------------------- 1 | module array; 2 | var a : boolean[5]; 3 | i : integer; 4 | cnt : integer; 5 | 6 | begin 7 | cnt := 0; 8 | 9 | i := 0; 10 | while (i < 5) do 11 | // if (a[i]) then // pass 12 | // if (a['c']) then // fail 13 | // if (a[true]) then // fail 14 | if (a["hello"]) then // fail 15 | cnt := cnt + 1 16 | else 17 | cnt := cnt 18 | end; 19 | i := i+1 20 | end; 21 | 22 | WriteInt(cnt) 23 | end array. 24 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_11.mod: -------------------------------------------------------------------------------- 1 | module invalid; 2 | 3 | var a : integer; 4 | 5 | begin 6 | a := -2147483648; // pass 7 | // a := +2147483648; // fail 8 | a := -2147483648 + 3; // pass 9 | a := -2147483648 * 3; // fail 10 | return 11 | end invalid. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_2.mod: -------------------------------------------------------------------------------- 1 | module proc; 2 | 3 | procedure f(a : integer); 4 | begin 5 | a := 4 + 5; 6 | return a 7 | end f; 8 | 9 | begin 10 | 11 | end proc. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_3.mod: -------------------------------------------------------------------------------- 1 | module fun; 2 | 3 | function f(a : integer) : integer; 4 | begin 5 | if (a > 5) then 6 | return a 7 | else 8 | return 9 | end; 10 | return -1 11 | end f; 12 | 13 | begin 14 | 15 | end fun. 16 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_4.mod: -------------------------------------------------------------------------------- 1 | module ret; 2 | 3 | function f(a : integer) : boolean; 4 | begin 5 | a := ReadInt(); 6 | return a 7 | end f; 8 | 9 | begin 10 | 11 | end ret. 12 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_5.mod: -------------------------------------------------------------------------------- 1 | module while_if; 2 | 3 | var a, sum : integer; 4 | 5 | begin 6 | a := ReadInt(); 7 | 8 | sum := 0; 9 | // while (a) do 10 | // sum := sum + a; 11 | // a := a-1 12 | // end; 13 | if (a) then 14 | sum := sum + a 15 | else 16 | sum := a 17 | end; 18 | 19 | WriteInt(sum) 20 | end while_if. 21 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_6.mod: -------------------------------------------------------------------------------- 1 | module bin; 2 | 3 | var a : integer; 4 | b : boolean; 5 | c : char; 6 | arr : integer[5]; 7 | 8 | procedure compare(ptr : integer[5]; ptr2 : integer[5]); 9 | var s : char[14]; 10 | 11 | begin 12 | a := a + b; // fail 13 | a := a + c; // fail 14 | a := a + arr; // fail 15 | a := a + ptr; // fail 16 | 17 | a := arr - a; 18 | arr := arr - a; // fail 19 | arr := arr - b; // fail 20 | arr := arr - c; // fail 21 | arr := ptr2 - ptr; // fail 22 | 23 | ptr := ptr / arr; // fail 24 | 25 | s := s + "Hello, World\n"; // fail 26 | 27 | ptr := ptr2; // pass 28 | 29 | return 30 | end compare; 31 | 32 | begin 33 | 34 | end bin. 35 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_7.mod: -------------------------------------------------------------------------------- 1 | module unary; 2 | 3 | var a : integer; 4 | b : boolean; 5 | 6 | begin 7 | a := +a; // pass 8 | a := -a; // pass 9 | b := !b; // pass 10 | 11 | b := +b; // fail 12 | b := -b; // fail 13 | a := !a; // fail 14 | 15 | return 16 | 17 | end unary. 18 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_8.mod: -------------------------------------------------------------------------------- 1 | module number; 2 | 3 | procedure f(a : integer; b : integer); 4 | begin 5 | a := b; 6 | return 7 | end f; 8 | 9 | begin 10 | // f(); // fail 11 | // f(3); // fail 12 | // f(3,4,5); // fail 13 | f(6,7,8,9); // fail 14 | f(987654321,123456789); // pass 15 | return 16 | end number. 17 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/error/error4_2_9.mod: -------------------------------------------------------------------------------- 1 | module number; 2 | 3 | procedure f(a : integer; b : integer); 4 | begin 5 | a := b; 6 | return 7 | end f; 8 | 9 | begin 10 | f(5, true); // fail 11 | f('a', 4); // fail 12 | f("hello", "world\n"); // fail 13 | 14 | f(3,5); // pass 15 | return 16 | end number. 17 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/hmtest00.mod: -------------------------------------------------------------------------------- 1 | // hmtest00.mod 2 | 3 | module hmtest00; 4 | 5 | var a : integer; 6 | 7 | begin 8 | a := -true; // fail 9 | return 10 | end hmtest00. 11 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/hmtest01.mod: -------------------------------------------------------------------------------- 1 | // hmtest01.mod 2 | // this fail with redundant expression 3 | 4 | module hmtest01; 5 | 6 | var a : integer[1]; 7 | 8 | begin 9 | a[0] := -2147483648; 10 | a[0] := -2147483648*1; 11 | a[0] := -(2147483648); 12 | a[0] := -(2147483648*1); 13 | return 14 | end hmtest01. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/hmtest02.mod: -------------------------------------------------------------------------------- 1 | // hmtest02.mod 2 | // this fail with redundant expression 3 | 4 | module hmtest02; 5 | 6 | var a : integer[1]; 7 | 8 | begin 9 | return a[0] 10 | end hmtest02. 11 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/hmtest03.mod: -------------------------------------------------------------------------------- 1 | // hmtest03.mod 2 | 3 | module hmtest03; 4 | 5 | // empty procedure 6 | procedure ProcedureCall(); 7 | begin 8 | end ProcedureCall; 9 | 10 | // condition type checking 11 | procedure If(p1, p2: integer); 12 | begin 13 | if (p1 + p2 > 0) then // pass 14 | return 15 | else 16 | return 17 | end; 18 | 19 | if (true) then // pass 20 | return 21 | else 22 | return 23 | end 24 | end If; 25 | 26 | begin 27 | If(1, 2) 28 | end hmtest03. 29 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/hmtest04.mod: -------------------------------------------------------------------------------- 1 | // hmtest04.mod 2 | // Weak points in reference parser 3 | // abuse of stringConstant 4 | 5 | module weak; // fail everywhere 6 | 7 | var _str_2 : integer; // symbol table occupied 8 | _str_3 : char[7]; // symbol table occupied 9 | 10 | procedure _str_1(s : char[]); // symbol table occupied 11 | begin 12 | WriteStr(s); 13 | return 14 | end _str_1; 15 | 16 | procedure clear(s : char[]); 17 | begin 18 | s[0] := '\0' 19 | end clear; 20 | 21 | begin 22 | _str_3[0] := '_'; 23 | _str_3[1] := 'f'; 24 | _str_3[2] := 'u'; 25 | _str_3[3] := 'n'; 26 | _str_3[4] := '_'; 27 | _str_3[5] := '3'; 28 | _str_3[6] := '\0'; 29 | 30 | WriteStr("_str_1"); // can't use _str_1 as pointer to array of char 31 | _str_1("_str_2"); // can't use _str_2 as pointer to array of char 32 | _str_1("_str_3"); // when using _str_3, _fun_3 will be returned 33 | WriteStr("_str_4"); 34 | _str_4[5] := '5'; // using undeclared variable _str_4 35 | 36 | clear("constant?"); // stringConstant is lie - it is mutable 37 | return 38 | end weak. 39 | 40 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/int_const_relaxed.mod: -------------------------------------------------------------------------------- 1 | // 2 | // advanced folding of integer constants 3 | // 4 | module int_const_relaxed; 5 | 6 | // 7 | // relaxed(): fold negation with constant. 8 | // 9 | // relaxed() improves the unintuitive behavior of simple() by also folding an 10 | // integer constant if it appears as the leftmost leaf in the 'term' expression 11 | // following the inital sign in 'simpleexpr'. 12 | // 13 | // I.e., for the parse trees 14 | // 15 | // -2147483648 + 5 -2147483648 * 5 16 | // 17 | // simpleexpr simpleexpr 18 | // / | | \ / \ 19 | // "-" term "+" term "-" term 20 | // | | / | \ 21 | // factor factor factor "*" factor 22 | // | | | | 23 | // number number number number 24 | // | | | | 25 | // 2147483648 5 2147483648 5 26 | // 27 | // 28 | // we first identify the leftmost leaf in the first term and fold if it is 29 | // a CAstConstant: 30 | // 31 | // simpleexpr simpleexpr 32 | // / | | \ / \ 33 | // "-" term "+" term "-" term 34 | // (of type) (of type) (of type) 35 | // CAstConstant CAstConstant CAstBinaryOp 36 | // ^ / | \ 37 | // | factor "*" factor 38 | // fold "-" w/ CAstConstant (of type) (of type) 39 | // CAstConstant CAstConstant 40 | // ^ 41 | // | 42 | // fold "-" w/ CAstConstant 43 | // 44 | // This approach requires modifications to the AST data structure since we need 45 | // to know whether an expression had been enclosed in parentheses or not. 46 | // Otherwise we would wrongfully accept expressions such as 47 | // 48 | // i := -(2147483648 + 5) 49 | // 50 | // or even worse (b is of boolean type here) 51 | // 52 | // b := -(1 > 0) 53 | // 54 | procedure relaxed(); 55 | var i: integer; 56 | b: boolean; 57 | begin 58 | i := -2147483648; // pass 59 | i := -2147483647; // pass 60 | i := 2147483647; // pass 61 | i := 2147483648; // fail 62 | 63 | i := -2147483648 + 2147483648; // fail 64 | i := -2147483648 + -2147483648; // fail 65 | i := -2147483648 + (-2147483648); // pass 66 | 67 | i := -2147483648 + 3; // pass 68 | i := -2147483648 * 3; // pass 69 | i := -(2147483648 + 3); // fail 70 | i := -(i + 2147483648); // fail 71 | 72 | i := -(2147483648); // fail 73 | i := -(-(-(1))); // pass 74 | 75 | b := -((1 > 0) && (2 < 5)); // fail 76 | 77 | i := 0 78 | end relaxed; 79 | 80 | begin 81 | end int_const_relaxed. 82 | 83 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/int_const_simple.mod: -------------------------------------------------------------------------------- 1 | // 2 | // allow simple folding of integer constants 3 | // 4 | module int_const_simple; 5 | 6 | // 7 | // simple(): fold negation with constant 'term' 8 | // 9 | // simple() interpretes the grammar is a slightly different way if a constant 10 | // follows the initial sign of a simplexpr. simple() performs folding of nega- 11 | // tion and constants iff the term follwing the +/- sign is a constant. This 12 | // leads to unintuitive behavior since -MIN_INT + ... is accepted, but 13 | // -MIN_INT * ... is not. 14 | // 15 | // To understand why consider the parse trees 16 | // 17 | // -2147483648 + 5 -2147483648 * 5 18 | // 19 | // simpleexpr simpleexpr 20 | // / | | \ / \ 21 | // "-" term "+" term "-" term 22 | // | | / | \ 23 | // factor factor factor "*" factor 24 | // | | | | 25 | // number number number number 26 | // | | | | 27 | // 2147483648 5 2147483648 5 28 | // 29 | // in the left case, the first term is represented by an CAstConstant node 30 | // which can be easily folded with the "-" sign on its left. For the multi- 31 | // plication, the (first) term is of type CAstBinaryOp and can thus not be 32 | // folded anymore. 33 | // 34 | // simpleexpr simpleexpr 35 | // / | | \ / \ 36 | // "-" term "+" term "-" term 37 | // (of type) (of type) (of type) 38 | // CAstConstant CAstConstant CAstBinaryOp 39 | // / | \ 40 | // ^ factor "*" factor 41 | // | (of type) (of type) 42 | // fold "-" w/ CAstConstant CAstConstant CAstConstant 43 | // 44 | procedure simple(); 45 | var i: integer; 46 | begin 47 | i := -2147483648; // pass 48 | i := -2147483647; // pass 49 | i := 2147483647; // pass 50 | i := 2147483648; // fail 51 | 52 | i := -2147483648 + 2147483648; // fail 53 | i := -2147483648 + -2147483648; // fail 54 | i := -2147483648 + (-2147483648); // pass 55 | 56 | i := -2147483648 + 3; // pass 57 | i := -2147483648 * 3; // fail 58 | 59 | i := 0 60 | end simple; 61 | 62 | begin 63 | end int_const_simple. 64 | 65 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/int_const_strict.mod: -------------------------------------------------------------------------------- 1 | // 2 | // strict implementation of SnuPL/1's integer constants 3 | // 4 | module int_const_strict; 5 | 6 | // 7 | // strict(): 1:1 implementation of SnuPL/1 EBNF 8 | // 9 | // strict() does not perform folding of negation and constants. 10 | // Since 'number' accepts only positive numbers, there is no way 11 | // to directly represent MIN_INT. 12 | // 13 | procedure strict(); 14 | var i: integer; 15 | begin 16 | i := -2147483648; // fail 17 | i := -2147483647; // pass 18 | i := 2147483647; // pass 19 | i := 2147483648; // fail 20 | 21 | i := 0 22 | end strict; 23 | 24 | begin 25 | end int_const_strict. 26 | 27 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest00.mod: -------------------------------------------------------------------------------- 1 | // pstest00.mod 2 | // this tests the function with boolean return type, 3 | // integer array, and boolean array. 4 | 5 | module pstest00; 6 | 7 | var a : integer[111111]; 8 | b : integer[1111][1111]; 9 | n, m, sum : integer; 10 | 11 | procedure input; 12 | var i, j : integer; 13 | begin 14 | n := ReadInt(); m := ReadInt(); 15 | i := 0; j := 0; 16 | 17 | while (i < n*m) do 18 | a[i] := ReadInt(); 19 | i := i+1 20 | end; 21 | 22 | i := 0; 23 | while (i < n) do 24 | while (j < m) do 25 | b[i][j] := ReadInt(); 26 | j := j+1 27 | end; 28 | i := i+1 29 | end; 30 | 31 | return 32 | end input; 33 | 34 | function div(value : integer ; q : integer) : integer; 35 | begin 36 | return value / q 37 | end div; 38 | 39 | function mod(value : integer ; q : integer) : integer; 40 | begin 41 | return value - value / q * q 42 | end mod; 43 | 44 | function pos(index : integer ; arr : integer[][]) : boolean; 45 | var x : integer; 46 | begin 47 | x := mod(index, n * m); 48 | if (arr[div(x,m)][mod(x,m)] = 0) then 49 | return false 50 | end; 51 | return true 52 | end pos; 53 | 54 | procedure process(); 55 | var i : integer; 56 | begin 57 | i := 0; 58 | 59 | while (pos(a[i], b) && (i < n*m)) do 60 | sum := sum + a[i]; 61 | i := i+1 62 | end 63 | 64 | end process; 65 | 66 | procedure output(); 67 | begin 68 | WriteInt(sum) 69 | end output; 70 | 71 | begin 72 | input(); 73 | process(); 74 | output() 75 | end pstest00. 76 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest01.mod: -------------------------------------------------------------------------------- 1 | // pstest01.mod 2 | // function declaration without return statements 3 | // remark that it is undefined behaviour in c and c++, not compile error 4 | 5 | module pstest01; 6 | 7 | var a : integer; 8 | 9 | function f(a : integer) : integer; 10 | 11 | begin 12 | a := 3; 13 | WriteInt(a) 14 | end f; 15 | 16 | begin 17 | a := ReadInt(); 18 | a := f(a); 19 | WriteInt(a) 20 | end pstest01. 21 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest02.mod: -------------------------------------------------------------------------------- 1 | // pstest02.mod 2 | // statSequence = [ statement { ";" statement } ] 3 | // therefore, statSequence can be empty. 4 | 5 | module pstest02; 6 | 7 | var a : boolean; 8 | 9 | function input() : boolean; 10 | 11 | var x : integer; 12 | 13 | begin 14 | x := ReadInt(); 15 | if (x = 0) then 16 | return false 17 | end; 18 | return true 19 | end input; 20 | 21 | procedure empty; 22 | begin 23 | end empty; 24 | 25 | begin 26 | WriteStr ("module begin"); 27 | WriteStr ("enter a integer. nonzero means true, and zero means false"); 28 | a := input(); 29 | empty(); 30 | 31 | if (a) then end; 32 | if (!a) then end; 33 | WriteStr("if statements end"); 34 | 35 | while (!a) do end; 36 | WriteStr("while statements end"); 37 | 38 | WriteStr("module end") 39 | end pstest02. 40 | 41 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest03.mod: -------------------------------------------------------------------------------- 1 | // pstest03.mod 2 | // tests function with array return type 3 | 4 | module pstest03; 5 | 6 | var a : integer[3][5][4]; 7 | 8 | function f(a : integer[][5][]) : integer; 9 | begin 10 | if (a[3][2][1] > 0) then 11 | return a 12 | end 13 | end f; 14 | 15 | begin 16 | WriteInt(f(a)) 17 | end pstest03. 18 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest04.mod: -------------------------------------------------------------------------------- 1 | // pstest04.mod 2 | // tests not matchable array parameter 3 | 4 | module pstest04; 5 | 6 | var a : integer[3][4][5][6]; 7 | 8 | function f(a : integer[][5][][]) : integer; 9 | begin 10 | if (a[0][0][0][0] > a[1][1][1][1]) then 11 | return a[0][0][0][0] 12 | else 13 | return a[1][1][1][1] 14 | end; 15 | return -1 16 | end f; 17 | 18 | begin 19 | WriteInt(f(a)) 20 | end pstest04. 21 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest05.mod: -------------------------------------------------------------------------------- 1 | // pstest05.mod 2 | // tests for NULL type expression 3 | 4 | module pstest05; 5 | 6 | procedure f; 7 | begin 8 | return 9 | end f; 10 | 11 | procedure g; 12 | begin 13 | // return f() 14 | end g; 15 | 16 | function f2 : integer; 17 | begin 18 | return f() 19 | end f2; 20 | 21 | begin 22 | // return f(g()) 23 | end pstest05. 24 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/pstest06.mod: -------------------------------------------------------------------------------- 1 | // pstest06 2 | // fibonacci seq. 3 | 4 | module pstest06; 5 | 6 | function fib(n : integer) : integer; 7 | begin 8 | if (n < 0) then 9 | WriteStr("number cannot be a negative integer"); 10 | return -1 11 | else 12 | if (n = 0) then 13 | return 0 14 | else 15 | if (n = 1) then 16 | return 1 17 | else 18 | return fib(n-2) + fib(n-1) 19 | end 20 | end 21 | end 22 | end fib; 23 | 24 | begin 25 | 26 | end pstest06. 27 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple00.mod: -------------------------------------------------------------------------------- 1 | module simple00; 2 | 3 | var a : integer[5][5]; 4 | 5 | procedure f(a: integer[][]; b,c: integer); 6 | var i,j : integer; 7 | begin 8 | i := b; j := c; 9 | a[2][2] := i+j 10 | end f; 11 | 12 | begin 13 | f(a,3,5); 14 | WriteInt(a[2][2]); 15 | return 16 | end simple00. 17 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple01.mod: -------------------------------------------------------------------------------- 1 | module simple01; 2 | 3 | var a : integer; 4 | b : boolean; 5 | c : char; 6 | arr : integer[5]; 7 | 8 | begin 9 | a := b; // fail 10 | b := c; // fail 11 | c := a; // fail 12 | // arr['a'] := a; 13 | return 14 | end simple01. 15 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple02.mod: -------------------------------------------------------------------------------- 1 | module simple02; 2 | 3 | function f() : integer; 4 | var a : integer; 5 | begin 6 | a := 3; 7 | return a 8 | end f; 9 | 10 | begin 11 | f := 2 12 | end simple02. 13 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple03.mod: -------------------------------------------------------------------------------- 1 | module simple03; 2 | 3 | var a : integer; 4 | 5 | function f() : integer; 6 | begin 7 | a := 3; 8 | return a 9 | end f; 10 | 11 | begin 12 | a := f(3) 13 | end simple03. 14 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple04.mod: -------------------------------------------------------------------------------- 1 | module simple04; 2 | 3 | procedure f(a,b : integer[][]); 4 | begin 5 | a := b // pass 6 | end f; 7 | 8 | begin 9 | 10 | end simple04. 11 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple05.mod: -------------------------------------------------------------------------------- 1 | module simple05; 2 | 3 | var a : integer; 4 | 5 | begin 6 | 7 | a := -2147483647; // pass 8 | a := 2147483647; // pass 9 | a := +2147483647; // pass 10 | 11 | a := -2147483648; // pass 12 | // a := 2147483648; // fail 13 | // a := +2147483648; // fail 14 | 15 | // a := -2147483649; // fail 16 | // a := 2147483649; // fail 17 | // a := +2147483649 // fail 18 | 19 | a := -2147483648 * 987654321 // fail 20 | 21 | end simple05. 22 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple06.mod: -------------------------------------------------------------------------------- 1 | module simple06; 2 | 3 | procedure f(arr : integer[][]); 4 | begin 5 | 6 | end f; 7 | 8 | begin 9 | 10 | end simple06. 11 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple07.mod: -------------------------------------------------------------------------------- 1 | module simple06; 2 | var a : integer; 3 | begin 4 | a := 18446744073709551616987654321; // fail 5 | a := 4294967296; // fail 6 | a := 2147483647 // pass 7 | 8 | end simple06. 9 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple08.mod: -------------------------------------------------------------------------------- 1 | module simple08; 2 | 3 | var i : integer; 4 | 5 | begin 6 | i := -true 7 | end simple08. 8 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple09.mod: -------------------------------------------------------------------------------- 1 | module simple09; 2 | 3 | var b : boolean; 4 | 5 | begin 6 | 7 | if (b > b) then return else return end 8 | 9 | end simple09. 10 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple10.mod: -------------------------------------------------------------------------------- 1 | module simple10; 2 | 3 | var a : integer; 4 | 5 | procedure f(a : integer[][]); 6 | begin 7 | 8 | end f; 9 | 10 | begin 11 | 12 | end simple10. 13 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple11.mod: -------------------------------------------------------------------------------- 1 | module simple11; 2 | 3 | var s : char[55]; 4 | 5 | procedure modify(target, comment : char[]); 6 | begin 7 | end modify; 8 | 9 | begin 10 | modify(s, "Hello, World\n"); 11 | _str_1[0] := 'a' 12 | end simple11. 13 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/simple12.mod: -------------------------------------------------------------------------------- 1 | module simple12; 2 | 3 | procedure f(); 4 | begin 5 | // WriteStr("Hello, World\n") 6 | end f; 7 | 8 | function _str_1 : integer; 9 | begin 10 | WriteStr("Hello, World\n"); 11 | WriteStr("Hello, World\n"); 12 | WriteStr("Hello, World\n"); 13 | return 1 14 | end _str_1; 15 | 16 | begin 17 | f(); 18 | WriteInt(_str_1()) 19 | end simple12. 20 | -------------------------------------------------------------------------------- /3.Semantic.Analysis/test/semanal/strings.mod: -------------------------------------------------------------------------------- 1 | // 2 | // strings.mod 3 | // 4 | // specific semantic anaysis for strings 5 | // - definition of strings 6 | // - string passing 7 | // - type checking 8 | // 9 | // Note that the reference implementation 10 | // - treats strings as character arrays 11 | // - but does not support assignments of arrays 12 | // This means that strings cannot be assigned to 13 | // character arrays. 14 | 15 | module strings; 16 | 17 | var s: char[256]; // pass 18 | 19 | 20 | procedure foo(); 21 | begin 22 | WriteStr("Hello, world!"); // pass 23 | WriteLn() 24 | end foo; 25 | 26 | procedure bar(str: char[]); // pass 27 | begin 28 | WriteStr(str); // pass 29 | WriteLn() 30 | end bar; 31 | 32 | procedure foobar(); 33 | var s: char[9]; 34 | begin 35 | s := "No good."; // fail 36 | WriteStr(s); // pass 37 | WriteLn() 38 | end foobar; 39 | 40 | procedure not_fun(); 41 | var s: char[6]; 42 | begin 43 | s[0]:='H'; s[1]:='e'; // pass 44 | s[2]:='l'; s[3]:='l'; // pass 45 | s[4]:='o'; s[5]:='\0'; // pass 46 | WriteStr(s); // pass 47 | WriteLn() 48 | end not_fun; 49 | 50 | begin 51 | foo(); 52 | bar("This should work."); 53 | not_fun() 54 | end strings. 55 | 56 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/4.Intermediate.Code.Generation.Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/4.Intermediate.Code.Generation/4.Intermediate.Code.Generation.Report.pdf -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/4.Intermediate.Code.Generation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/4.Intermediate.Code.Generation/4.Intermediate.Code.Generation.pdf -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/compare: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | rm -f ./me ./egger 3 | find test/tac -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "snuplc/test_ir {} >> me" 4 | find test/tac -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "reference/4_test_ir {} >> egger" 5 | 6 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/reference/4_test_ir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/4.Intermediate.Code.Generation/reference/4_test_ir -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/snuplc/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CCFLAGS=-std=c++0x -g -O0 3 | 4 | SRC_DIR=src 5 | OBJ_DIR=obj 6 | 7 | DEPS=scanner.h \ 8 | parser.h \ 9 | type.h \ 10 | symtab.h \ 11 | data.h \ 12 | ast.h \ 13 | ir.h 14 | SCANNER=scanner.cpp 15 | PARSER=parser.cpp \ 16 | type.cpp \ 17 | symtab.cpp \ 18 | data.cpp \ 19 | ast.cpp \ 20 | ir.cpp 21 | IR= 22 | BACKEND=backend.cpp 23 | 24 | DEPS_=$(patsubst %,$(SRC_DIR)/%,$(DEPS)) 25 | OBJ_SCANNER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SCANNER)) 26 | OBJ_PARSER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(PARSER) $(SCANNER)) 27 | OBJ_IR=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(IR) $(PARSER) $(SCANNER)) 28 | 29 | .PHONY: clean doc 30 | 31 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS_) 32 | $(CC) $(CCFLAGS) -c -o $@ $< 33 | 34 | all: test_ir 35 | 36 | test_scanner: $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 37 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 38 | 39 | test_parser: $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 40 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 41 | 42 | test_ir: $(OBJ_DIR)/test_ir.o $(OBJ_IR) 43 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_ir.o $(OBJ_IR) 44 | 45 | doc: 46 | doxygen 47 | 48 | clean: 49 | rm -rf $(OBJ_DIR)/*.o test_scanner test_parser test_ir 50 | 51 | mrproper: clean 52 | rm -rf doc/* 53 | 54 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/snuplc/src/data.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SnuPL data initializers 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2016/04/05 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | 36 | #include "data.h" 37 | using namespace std; 38 | 39 | 40 | //------------------------------------------------------------------------------ 41 | // CDataInitializer 42 | // 43 | CDataInitializer::CDataInitializer(void) 44 | { 45 | } 46 | 47 | CDataInitializer::~CDataInitializer(void) 48 | { 49 | } 50 | 51 | ostream& operator<<(ostream &out, const CDataInitializer &t) 52 | { 53 | return t.print(out); 54 | } 55 | 56 | ostream& operator<<(ostream &out, const CDataInitializer *t) 57 | { 58 | return t->print(out); 59 | } 60 | 61 | 62 | //------------------------------------------------------------------------------ 63 | // CDataInitString 64 | // 65 | CDataInitString::CDataInitString(const string data) 66 | : CDataInitializer(), _data(data) 67 | { 68 | } 69 | 70 | string CDataInitString::GetData(void) const 71 | { 72 | return _data; 73 | } 74 | 75 | ostream& CDataInitString::print(ostream &out, int indent) const 76 | { 77 | string ind(indent, ' '); 78 | 79 | out << ind << "[ data: '" << _data << "' ]"; 80 | return out; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/snuplc/src/test_scanner.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SNUPL scanner test 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2012/09/14 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2012-2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "scanner.h" 38 | using namespace std; 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | int i = 1; 43 | 44 | while (i < argc) { 45 | CScanner *s = new CScanner(new ifstream(argv[i])); 46 | 47 | cout << "scanning '" << argv[i] << "'..." << endl; 48 | 49 | if (!s->Good()) cout << " cannot open input stream: " << s->Peek() << endl; 50 | 51 | while (s->Good()) { 52 | CToken t = s->Get(); 53 | cout << " " << t << endl; 54 | if (t.GetType() == tEOF) break; 55 | } 56 | 57 | cout << endl << endl; 58 | 59 | i++; 60 | } 61 | 62 | cout << "Done." << endl; 63 | 64 | return EXIT_SUCCESS; 65 | } 66 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/giftToEgger.mod: -------------------------------------------------------------------------------- 1 | // hmtest04.mod 2 | // Weak points in reference parser 3 | // abuse of stringConstant 4 | 5 | module weak; // fail everywhere 6 | 7 | var _str_2 : integer; // symbol table occupied 8 | _str_3 : char[7]; // symbol table occupied 9 | 10 | procedure _str_1(s : char[]); // symbol table occupied 11 | begin 12 | WriteStr(s); 13 | return 14 | end _str_1; 15 | 16 | procedure clear(s : char[]); 17 | begin 18 | s[0] := '\0' 19 | end clear; 20 | 21 | begin 22 | _str_3[0] := '_'; 23 | _str_3[1] := 'f'; 24 | _str_3[2] := 'u'; 25 | _str_3[3] := 'n'; 26 | _str_3[4] := '_'; 27 | _str_3[5] := '3'; 28 | _str_3[6] := '\0'; 29 | 30 | WriteStr("_str_1"); // can't use _str_1 as pointer to array of char 31 | _str_1("_str_2"); // can't use _str_2 as pointer to array of char 32 | _str_1("_str_3"); // when using _str_3, _fun_3 will be returned 33 | WriteStr("_str_4"); 34 | _str_4[5] := '5'; // using undeclared variable _str_4 35 | 36 | clear("constant?"); // stringConstant is lie - it is mutable 37 | return 38 | end weak. 39 | 40 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/hmtest00.mod: -------------------------------------------------------------------------------- 1 | // hmtest03.mod 2 | 3 | module hmtest03; 4 | 5 | // empty procedure 6 | procedure ProcedureCall(); 7 | begin 8 | end ProcedureCall; 9 | 10 | // condition type checking 11 | procedure If(p1, p2: integer); 12 | begin 13 | if (p1 + p2 > 0) then // pass 14 | return 15 | else 16 | return 17 | end; 18 | 19 | if (true) then // pass 20 | return 21 | else 22 | return 23 | end 24 | end If; 25 | 26 | begin 27 | If(1, 2) 28 | end hmtest03. 29 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/hmtest01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test6 3 | // 4 | // IR generation 5 | // 6 | 7 | module test6; 8 | 9 | var i, j: integer; 10 | A, B: integer[10][5]; 11 | 12 | procedure foo1(M: integer[][]); 13 | var a, b, c: integer; 14 | N: integer[7][8]; 15 | begin 16 | N[a][b] := c; 17 | if (N[6][5] < M[DIM(M, 1) - 1][DIM(M, 2) - 1]) then 18 | N[0][0] := N[1][1]; 19 | M[0][0] := N[a][b]; 20 | return 21 | else 22 | return 23 | end; 24 | return 25 | end foo1; 26 | 27 | procedure foo2(M: integer[][]); 28 | var n, m: integer; 29 | N: integer[1][1][1][1]; 30 | begin 31 | n := M[i][j]; 32 | N[5-5][2/(m - m)][DIM(N, 4) - 1][n] := M[N[0][0][0][0]][M[0][0]]; 33 | return 34 | end foo2; 35 | 36 | procedure foo3(M: integer[][]; k: integer); 37 | var n, m: integer; 38 | N: integer[10][10][10]; 39 | O: integer[1][2]; 40 | begin 41 | bar2(k); 42 | foo1(M); 43 | foo2(O); 44 | N[1+2][M[0][0]][0] := M[i*j][ReadInt()]; 45 | return 46 | end foo3; 47 | 48 | procedure bar1(M: integer[][]); 49 | begin 50 | WriteInt(M[1][2]) 51 | end bar1; 52 | 53 | procedure bar2(m: integer); 54 | begin 55 | WriteInt(m) 56 | end bar2; 57 | 58 | begin 59 | bar2(A[0][0]); 60 | bar1(A); 61 | foo1(B); 62 | foo2(B); 63 | foo3(A, B[1][2]); 64 | return 65 | end test6. 66 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/hmtest02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // hmtest02 3 | // 4 | // IR generation 5 | // 6 | 7 | module hmtest02; 8 | 9 | var i: integer; 10 | b: boolean; 11 | A: integer[10]; 12 | B: boolean[10]; 13 | 14 | begin 15 | if (B[0]) then 16 | b := !B[0] 17 | else 18 | b := B[0] || true 19 | end; 20 | 21 | if (A[0] > i) then 22 | b := A[0] < i 23 | else 24 | b := i < A[0] 25 | end; 26 | return 27 | end hmtest02. 28 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/hmtest03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // hmtest03 3 | // 4 | // IR generation 5 | // 6 | 7 | module hmtest03; 8 | 9 | var a : integer[5]; 10 | b : integer[5][5][5]; 11 | 12 | procedure fun1(A : integer); 13 | begin 14 | end fun1; 15 | 16 | procedure fun2(A : integer[]); 17 | begin 18 | end fun2; 19 | 20 | procedure fun3(A : integer[][]); 21 | begin 22 | end fun3; 23 | 24 | procedure fun4(A : integer[][][]); 25 | begin 26 | end fun4; 27 | 28 | begin 29 | fun1(a[2]); 30 | fun1(b[2][3][4]); 31 | fun2(a); 32 | fun2(b[2][3]); 33 | fun3(b[2]); 34 | fun4(b); 35 | return 36 | end hmtest03. 37 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/hmtest04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // hmtest04 3 | // 4 | // IR generation 5 | // 6 | 7 | module hmtest04; 8 | 9 | var A: integer[10]; 10 | 11 | function bar(A: integer[]) : integer; 12 | begin 13 | return A[0] 14 | end bar; 15 | 16 | begin 17 | bar(A); 18 | return 19 | end hmtest04. 20 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest00.mod: -------------------------------------------------------------------------------- 1 | // pstest00.mod 2 | // this tests the function with boolean return type, 3 | // integer array, and boolean array. 4 | 5 | module pstest00; 6 | 7 | var a : integer[111111]; 8 | b : integer[1111][1111]; 9 | n, m, sum : integer; 10 | 11 | procedure input; 12 | var i, j : integer; 13 | begin 14 | n := ReadInt(); m := ReadInt(); 15 | i := 0; j := 0; 16 | 17 | while (i < n*m) do 18 | a[i] := ReadInt(); 19 | i := i+1 20 | end; 21 | 22 | i := 0; 23 | while (i < n) do 24 | while (j < m) do 25 | b[i][j] := ReadInt(); 26 | j := j+1 27 | end; 28 | i := i+1 29 | end; 30 | 31 | return 32 | end input; 33 | 34 | function div(value : integer ; q : integer) : integer; 35 | begin 36 | return value / q 37 | end div; 38 | 39 | function mod(value : integer ; q : integer) : integer; 40 | begin 41 | return value - value / q * q 42 | end mod; 43 | 44 | function pos(index : integer ; arr : integer[][]) : boolean; 45 | var x : integer; 46 | begin 47 | x := mod(index, n * m); 48 | if (arr[div(x,m)][mod(x,m)] = 0) then 49 | return false 50 | end; 51 | return true 52 | end pos; 53 | 54 | procedure process(); 55 | var i : integer; 56 | begin 57 | i := 0; 58 | 59 | while (pos(a[i], b) && (i < n*m)) do 60 | sum := sum + a[i]; 61 | i := i+1 62 | end 63 | 64 | end process; 65 | 66 | procedure output(); 67 | begin 68 | WriteInt(sum) 69 | end output; 70 | 71 | begin 72 | input(); 73 | process(); 74 | output() 75 | end pstest00. 76 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest01.mod: -------------------------------------------------------------------------------- 1 | // pstest01.mod 2 | // function declaration without return statements 3 | // remark that it is undefined behaviour in c and c++, not compile error 4 | 5 | module pstest01; 6 | 7 | var a : integer; 8 | 9 | function f(a : integer) : integer; 10 | 11 | begin 12 | a := 3; 13 | WriteInt(a) 14 | end f; 15 | 16 | begin 17 | a := ReadInt(); 18 | a := f(a); 19 | WriteInt(a) 20 | end pstest01. 21 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest02.mod: -------------------------------------------------------------------------------- 1 | // pstest02.mod 2 | // statSequence = [ statement { ";" statement } ] 3 | // therefore, statSequence can be empty. 4 | 5 | module pstest02; 6 | 7 | var a : boolean; 8 | 9 | function input() : boolean; 10 | 11 | var x : integer; 12 | 13 | begin 14 | x := ReadInt(); 15 | if (x = 0) then 16 | return false 17 | end; 18 | return true 19 | end input; 20 | 21 | procedure empty; 22 | begin 23 | end empty; 24 | 25 | begin 26 | WriteStr ("module begin"); 27 | WriteStr ("enter a integer. nonzero means true, and zero means false"); 28 | a := input(); 29 | empty(); 30 | 31 | if (a) then end; 32 | if (!a) then end; 33 | WriteStr("if statements end"); 34 | 35 | while (!a) do end; 36 | WriteStr("while statements end"); 37 | 38 | WriteStr("module end") 39 | end pstest02. 40 | 41 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest03.mod: -------------------------------------------------------------------------------- 1 | // pstest03.mod 2 | // tests function with array return type 3 | 4 | module pstest03; 5 | 6 | var a : integer[3][5][4]; 7 | 8 | function f(a : integer[][5][]) : integer; 9 | begin 10 | if (a[3][2][1] > 0) then 11 | return a 12 | end 13 | end f; 14 | 15 | begin 16 | WriteInt(f(a)) 17 | end pstest03. 18 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest04.mod: -------------------------------------------------------------------------------- 1 | // pstest04.mod 2 | // tests not matchable array parameter 3 | 4 | module pstest04; 5 | 6 | var a : integer[3][5][5][6]; 7 | 8 | function f(a : integer[][5][][]) : integer; 9 | begin 10 | if (a[0][0][0][0] > a[1][1][1][1]) then 11 | // return a[0][0][0][0] 12 | else 13 | // return a[1][1][1][1] 14 | end; 15 | return -1 16 | end f; 17 | 18 | function g() : integer; 19 | begin 20 | return -1 21 | end g; 22 | 23 | begin 24 | WriteInt(f(a)) 25 | end pstest04. 26 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest05.mod: -------------------------------------------------------------------------------- 1 | // pstest05.mod 2 | // tests for NULL type expression 3 | 4 | module pstest05; 5 | 6 | procedure f; 7 | begin 8 | return 9 | end f; 10 | 11 | procedure g; 12 | begin 13 | // return f() 14 | end g; 15 | 16 | function f2 : integer; 17 | begin 18 | return f() 19 | end f2; 20 | 21 | begin 22 | // return f(g()) 23 | end pstest05. 24 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest06.mod: -------------------------------------------------------------------------------- 1 | // pstest06 2 | // fibonacci seq. 3 | 4 | module pstest06; 5 | 6 | function fib(n : integer) : integer; 7 | begin 8 | if (n < 0) then 9 | WriteStr("number cannot be a negative integer"); 10 | return -1 11 | else 12 | if (n = 0) then 13 | return 0 14 | else 15 | if (n = 1) then 16 | return 1 17 | else 18 | return fib(n-2) + fib(n-1) 19 | end 20 | end 21 | end 22 | end fib; 23 | 24 | begin 25 | 26 | end pstest06. 27 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest07.mod: -------------------------------------------------------------------------------- 1 | // add, minus, mul, div, equal, A+B problem 2 | 3 | module pstest02; 4 | 5 | var a,b,c,d,e,f : integer; g : boolean; 6 | 7 | function add(a:integer; b:integer) : integer; 8 | begin 9 | return a + b 10 | end add; 11 | 12 | function minus(a:integer; b:integer) : integer; 13 | begin 14 | return a - b 15 | end minus; 16 | 17 | function mul(a:integer; b:integer) : integer; 18 | begin 19 | return a * b 20 | end mul; 21 | 22 | function div(a:integer; b:integer) : integer; 23 | begin 24 | return a / b 25 | end div; 26 | 27 | function equal(a:integer; b:integer) : boolean; 28 | begin 29 | return a = b 30 | end equal; 31 | 32 | procedure printAdd(a:integer; b:integer); 33 | begin 34 | WriteInt(a+b) 35 | end printAdd; 36 | 37 | begin 38 | a := 1; b := 2; 39 | c := add(a,b); 40 | d := minus(a,b); 41 | e := mul(a,b); 42 | f := div(a,b); 43 | g := equal(a,b); 44 | printAdd(a,b) 45 | end pstest02. 46 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest08.mod: -------------------------------------------------------------------------------- 1 | // find element in array 2 | 3 | module heehoon; 4 | 5 | var a : integer[111111]; 6 | x,n,i : integer; 7 | 8 | function find (arr : integer[]; elem : integer) : boolean; 9 | var i,N : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | while (i < N) do 13 | if (arr[i] = elem) then 14 | return true 15 | end; 16 | i := i+1 17 | end; 18 | return false 19 | end find; 20 | 21 | begin 22 | n := ReadInt(); 23 | 24 | i := 0; 25 | while (i < n) do 26 | a[i] := ReadInt() 27 | end; 28 | 29 | x := ReadInt(); 30 | 31 | if (find(a,x)) then 32 | WriteStr("Found") 33 | else 34 | WriteStr("Not Found. I EGGER U") 35 | end; 36 | WriteLn() 37 | end heehoon. 38 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest09.mod: -------------------------------------------------------------------------------- 1 | // find 2 | 3 | module pstest04; 4 | 5 | var a : integer[1111][1111]; 6 | n, m, i, j : integer; 7 | 8 | function sum (arr : integer[][]) : integer; 9 | var ret, N, M, i, j : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | M := DIM(arr, 2); 13 | 14 | i := 0; 15 | while (i < N) do 16 | j := 0; 17 | while (j < M) do 18 | ret := ret + arr[i][j]; 19 | j := j+1 20 | end; 21 | i := i+1 22 | end; 23 | return ret 24 | end sum; 25 | 26 | begin 27 | n := ReadInt(); 28 | m := ReadInt(); 29 | 30 | i := 0; 31 | while (i < n) do 32 | j := 0; 33 | while (j < m) do 34 | a[i][j] := ReadInt(); 35 | j := j+1 36 | end; 37 | i := i+1 38 | end; 39 | 40 | WriteInt(sum(a)); 41 | WriteLn() 42 | end pstest04. 43 | 44 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest10.mod: -------------------------------------------------------------------------------- 1 | // pstest10 2 | // https://www.acmicpc.net/problem/12790 3 | 4 | module MiniFantasyWar; 5 | var T, tc, i, ans : integer; 6 | input : integer[8]; 7 | 8 | function solve(stats : integer[]) : integer; 9 | var hp, ehp, mp, emp, atk, eatk, def, edef : integer; 10 | ret : integer; 11 | begin 12 | hp := stats[0]; ehp := stats[1]; mp := stats[2]; emp := stats[3]; 13 | atk := stats[4]; eatk := stats[5]; def := stats[6]; edef := stats[7]; 14 | 15 | ret := 0; 16 | if (hp + ehp >= 1) then 17 | ret := ret + hp + ehp 18 | else 19 | ret := ret + 1 20 | end; 21 | if (mp + emp >= 1) then 22 | ret := ret + 5 * (mp + emp) 23 | else 24 | ret := ret + 5 * 1 25 | end; 26 | if (atk + eatk >= 0) then 27 | ret := 2 * (atk + eatk) 28 | end; 29 | ret := ret + 2 * (def + edef); 30 | 31 | return ret 32 | end solve; 33 | 34 | begin 35 | T := ReadInt(); 36 | 37 | tc := 0; 38 | while (tc < T) do 39 | i := 0; 40 | while (i < 8) do 41 | input[i] := ReadInt(); 42 | i := i + 1 43 | end; 44 | 45 | ans := solve(input); 46 | WriteInt(ans); 47 | WriteLn(); 48 | 49 | tc := tc + 1 50 | end 51 | end MiniFantasyWar. 52 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest12.mod: -------------------------------------------------------------------------------- 1 | // pstest12 2 | // https://www.acmicpc.net/problem/12792 3 | 4 | module jujak_ju_jujak; 5 | 6 | begin 7 | WriteInt(1000003) 8 | end jujak_ju_jujak. 9 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/pstest13.mod: -------------------------------------------------------------------------------- 1 | module pstest13; 2 | 3 | var cond1 : boolean[5]; 4 | cond2 : boolean[7][3]; 5 | cond3 : boolean[9][4][8]; 6 | cond4 : boolean[11][2][3][5]; 7 | ret : boolean; 8 | 9 | function f 10 | (c1 : boolean[]; c2 : boolean[][]; 11 | c3 : boolean[][][]; c4 : boolean[][][][5]) : boolean; 12 | begin 13 | if (c1[3] || c2[3][2] || c3[3][2][1] || c4[3][2][1][0]) then 14 | if (c1[3]) then 15 | return !c1[3] 16 | else 17 | return !(c2[3][2] && c3[3][2][1]) 18 | end 19 | else 20 | return !(c3[3][2][1] || c4[3][2][1][0]) 21 | end; 22 | return !c3[3][2][1]; 23 | return !f(c1, c2, c3, c4); 24 | return f(c1, c2, c3, c4) 25 | end f; 26 | 27 | begin 28 | while (f(cond1, cond2, cond3, cond4)) do 29 | while (!f(cond1, cond2, cond3, cond4)) do 30 | if (cond1[5]) then 31 | ret := !cond3[1][3][2] 32 | else 33 | ret := cond3[3][2][1] && cond2[1][2] 34 | end 35 | end; 36 | while(!cond2[3][4]) do 37 | while(!cond4[9][8][7][6]) do 38 | if (cond3[1][3][2]) then 39 | ret := !true || false 40 | else 41 | ret := !true && true 42 | end 43 | end 44 | end 45 | end; 46 | if (ret && cond1[0]) then 47 | WriteStr("sound, compact"); 48 | WriteLn(); 49 | WriteInt(1) 50 | else 51 | if (ret && !cond1[0]) then 52 | WriteStr("sound, not compact"); 53 | WriteLn(); 54 | WriteInt(1) 55 | else 56 | if (!ret && cond1[0]) then 57 | WriteStr("not sound, compact"); 58 | WriteLn(); 59 | WriteInt(1) 60 | else 61 | WriteStr("not sound, not compact"); 62 | WriteLn(); 63 | WriteInt(0) 64 | end 65 | end 66 | end; 67 | 68 | return 69 | end pstest13. 70 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple00.mod: -------------------------------------------------------------------------------- 1 | module simple00; 2 | 3 | procedure f(a, b : integer); 4 | begin 5 | 6 | end f; 7 | 8 | begin 9 | f(1, 2) 10 | end simple00. 11 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple01.mod: -------------------------------------------------------------------------------- 1 | module simple00; 2 | 3 | var sum : integer; 4 | 5 | function f(a, b : integer) : integer; 6 | begin 7 | return a + b 8 | end f; 9 | 10 | begin 11 | sum := f(1, 2); 12 | WriteInt(sum) 13 | end simple00. 14 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple02.mod: -------------------------------------------------------------------------------- 1 | module simple02; 2 | 3 | var i : integer; 4 | 5 | begin 6 | if (i > 3) then 7 | i := 3 8 | else 9 | i := i 10 | end 11 | end simple02. 12 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple03.mod: -------------------------------------------------------------------------------- 1 | module simple03; 2 | 3 | var i, sum : integer; 4 | 5 | begin 6 | while ((i < 3) && (i < 4)) do 7 | sum := sum + i; 8 | i := i + 1 9 | end 10 | end simple03. 11 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple04.mod: -------------------------------------------------------------------------------- 1 | module simple04; 2 | 3 | var i : boolean; 4 | 5 | begin 6 | if ((4 > 3) && (5 > 3) && (1 + 6 > 3)) then 7 | i := true && true 8 | else 9 | i := true && false 10 | end 11 | end simple04. 12 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple05.mod: -------------------------------------------------------------------------------- 1 | module simple05; 2 | 3 | var i, j, k : boolean; 4 | 5 | begin 6 | i := false || false; 7 | i := (j = k) 8 | end simple05. 9 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple06.mod: -------------------------------------------------------------------------------- 1 | module simple06; 2 | 3 | var i : boolean; 4 | 5 | function f : boolean; 6 | begin 7 | return true 8 | end f; 9 | 10 | begin 11 | if (f()) then 12 | i := f() 13 | end; 14 | 15 | i := (f() && f()) 16 | end simple06. 17 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple07.mod: -------------------------------------------------------------------------------- 1 | module simple07; 2 | 3 | var i : boolean; 4 | 5 | function f(a,b : boolean) : boolean; 6 | begin 7 | return a && b && a && b 8 | end f; 9 | 10 | begin 11 | i := f(true, true) || f(true, false) 12 | end simple07. 13 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple08.mod: -------------------------------------------------------------------------------- 1 | module simple08; 2 | 3 | var i : integer; 4 | j, j0, j1, j2 : boolean; 5 | k : boolean; 6 | l, l0 : boolean; 7 | 8 | begin 9 | 10 | i := (i + 1); 11 | j := (j0 && j1) && j2; 12 | j := j0 && j1; 13 | i := i + i; 14 | k := (i > 2); 15 | l := (l = l0); 16 | 17 | return 18 | 19 | end simple08. 20 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple09.mod: -------------------------------------------------------------------------------- 1 | module simple09; 2 | 3 | var i : integer; 4 | j : boolean; 5 | b1, b2 : boolean; 6 | function f(i : integer) : boolean; 7 | begin 8 | return true 9 | end f; 10 | 11 | procedure g(b : boolean); 12 | begin 13 | 14 | end g; 15 | 16 | begin 17 | i := +i; 18 | i := -i; 19 | j := !j && j; 20 | j := j && !j; 21 | j := !j && !j; 22 | j := !(j && j); 23 | g(!(true || false)); 24 | 25 | j := !(b1 && b2); 26 | j := !j; 27 | j := !f(1); 28 | j := (-i > -i); 29 | i := -2147483648; 30 | 31 | return 32 | end simple09. 33 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple09_2.mod: -------------------------------------------------------------------------------- 1 | module simple09_2; 2 | 3 | var b1,b2,b3,b4,b5 : boolean; 4 | ret : boolean; 5 | 6 | function f(arg : boolean) : boolean; 7 | begin 8 | ret := !(b1 && b2); 9 | ret := !true; 10 | ret := f(!(b1 && b2)); 11 | f(!(b1 && b2)); 12 | if (!(b1 && b2)) then end; 13 | while (!(b1 && b2)) do end; 14 | return (!(b1 && b2)) 15 | end f; 16 | 17 | begin 18 | 19 | end simple09_2. 20 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple10.mod: -------------------------------------------------------------------------------- 1 | module simple10; 2 | 3 | var a : integer[5]; 4 | b : integer[5][5]; 5 | procedure f(a : integer[]); 6 | begin 7 | end f; 8 | 9 | begin 10 | f(a); 11 | f(b[5]); 12 | return 13 | end simple10. 14 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple11.mod: -------------------------------------------------------------------------------- 1 | module simple11; 2 | 3 | var b : boolean; 4 | 5 | begin 6 | b := !b; 7 | if (!b) then 8 | else 9 | end 10 | end simple11. 11 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple12.mod: -------------------------------------------------------------------------------- 1 | module simple12; 2 | 3 | var i, j : boolean; 4 | 5 | begin 6 | 7 | i := i || j || i || j 8 | 9 | end simple12. 10 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple13.mod: -------------------------------------------------------------------------------- 1 | module simple13; 2 | 3 | var res : boolean; 4 | 5 | begin 6 | res := !true || false 7 | end simple13. 8 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple14.mod: -------------------------------------------------------------------------------- 1 | module simple14; 2 | 3 | var i : integer; 4 | b : boolean; 5 | 6 | begin 7 | b := !(i<3); 8 | b := (i<3); 9 | return 10 | end simple14. 11 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple15.mod: -------------------------------------------------------------------------------- 1 | module simple15; 2 | 3 | var i, j, k, l, n, m : boolean; 4 | ret : boolean; 5 | 6 | begin 7 | ret := (i = j) || (k # l) && (!j) || (!n && (n || m)) && true || (!true && (i && (j || (k && (l || (!l || l)))))); 8 | return 9 | end simple15. 10 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple16.mod: -------------------------------------------------------------------------------- 1 | module simple16; 2 | 3 | var i : boolean; 4 | j : integer; 5 | 6 | begin 7 | 8 | i := (j > 3); 9 | i := (j > 3); 10 | return 11 | 12 | end simple16. 13 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple17.mod: -------------------------------------------------------------------------------- 1 | module simple17; 2 | 3 | var i : integer; 4 | 5 | begin 6 | 7 | // i := 2147483648 // error 8 | i := +9999; 9 | i := +(+9999); 10 | i := +(+(+(+(+9999)))); 11 | i := -2147483648; 12 | i := -(-2147483648); 13 | i := -(-(-(-(-2147483648)))); 14 | i := -2147483648 + 3 + (-7) - (-8); 15 | // i := -2147483648 * 3; // error when simple 16 | return 17 | 18 | end simple17. 19 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple18.mod: -------------------------------------------------------------------------------- 1 | module simple18; 2 | 3 | var a : integer[10][15]; 4 | 5 | procedure f(a : integer[]); 6 | begin 7 | 8 | end f; 9 | 10 | procedure g(a : integer); 11 | begin 12 | 13 | end g; 14 | 15 | begin 16 | f(a[10]); 17 | // g(a[10][15]); 18 | return 19 | end simple18. 20 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple19.mod: -------------------------------------------------------------------------------- 1 | module simple19; 2 | 3 | var a, b : boolean; 4 | 5 | begin 6 | 7 | a := !b 8 | 9 | end simple19. 10 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple20.mod: -------------------------------------------------------------------------------- 1 | module simple20; 2 | 3 | var b : boolean; 4 | 5 | function f() : boolean; 6 | begin 7 | end f; 8 | 9 | function g() : boolean; 10 | begin 11 | end g; 12 | 13 | function h() : boolean; 14 | begin 15 | end h; 16 | 17 | begin 18 | 19 | b := f() && g() || h() && g() || !h(); 20 | if (f()) then else end 21 | 22 | end simple20. 23 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple21.mod: -------------------------------------------------------------------------------- 1 | module simple21; 2 | 3 | var b : boolean; 4 | 5 | begin 6 | b := b && b && b && b 7 | end simple21. 8 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple22.mod: -------------------------------------------------------------------------------- 1 | module simple22; 2 | 3 | var a, i : integer; 4 | b : boolean; 5 | 6 | begin 7 | a := i + 3 8 | // b := i > 3; 9 | // b := b || b || b || b 10 | end simple22. 11 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/simple23.mod: -------------------------------------------------------------------------------- 1 | module simple23; 2 | 3 | function f() : integer; 4 | begin 5 | if (true) then 6 | else 7 | end; 8 | return -1 9 | // return -2; 10 | // return -987654321; 11 | // return -12345; 12 | // return -2147483648 13 | end f; 14 | 15 | begin 16 | 17 | end simple23. 18 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test1.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test1 3 | // 4 | // IR generation 5 | // 6 | 7 | module test1; 8 | 9 | var i: integer; 10 | 11 | begin 12 | i := (1 + 2) * 3 13 | end test1. 14 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test2.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test2 3 | // 4 | // IR generation 5 | // 6 | 7 | module test2; 8 | 9 | var i: integer; 10 | 11 | procedure foo(v: integer); 12 | begin 13 | i := (1 + 2) * v 14 | end foo; 15 | 16 | function bar(p1, p2, p3, p4: integer): integer; 17 | begin 18 | return p1 + p2 + p3 * p4 19 | end bar; 20 | 21 | begin 22 | foo(1); 23 | bar(1,2,3,4) 24 | end test2. 25 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test3.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test3 3 | // 4 | // IR generation 5 | // 6 | 7 | module test3; 8 | 9 | var i: integer; 10 | 11 | begin 12 | if (i > 3) then 13 | i := 0 14 | else 15 | i := 1 16 | end 17 | end test3. 18 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test4.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test4 3 | // 4 | // IR generation 5 | // 6 | 7 | module test4; 8 | 9 | var i: integer; 10 | 11 | begin 12 | while (i > 3) do 13 | i := i-1 14 | end 15 | end test4. 16 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test4_2.mod: -------------------------------------------------------------------------------- 1 | module test4_2; 2 | 3 | var i : integer; 4 | 5 | begin 6 | 7 | while (i < 3) do 8 | i := i; 9 | while (i < 4) do 10 | i := i - 1 11 | end 12 | end 13 | 14 | end test4_2. 15 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test5.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test5 3 | // 4 | // IR generation 5 | // 6 | 7 | module test5; 8 | 9 | var i: integer; 10 | A: integer[10][5]; 11 | 12 | begin 13 | A[1][3] := i 14 | end test5. 15 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test6.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test6 3 | // 4 | // IR generation 5 | // 6 | 7 | module test6; 8 | 9 | var i: integer; 10 | A: integer[10][5]; 11 | 12 | procedure foo(M: integer[][]); 13 | begin 14 | M[1][3] := i 15 | end foo; 16 | 17 | begin 18 | i := 0; 19 | foo(A) 20 | end test6. 21 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test7.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test7 3 | // 4 | // IR generation 5 | // 6 | 7 | module test7; 8 | 9 | var i: integer; 10 | 11 | begin 12 | if ((i < 3) && (i > 0)) then 13 | i := 0 14 | end 15 | end test7. 16 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test7_2.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test7_2 3 | // 4 | // IR generation 5 | // 6 | 7 | module test7_2; 8 | 9 | var i: integer; 10 | 11 | begin 12 | if (i < 3) then 13 | i := 0; 14 | if (i > 9) then 15 | i := 987654321 16 | else 17 | i := 123456789; 18 | if (i > 11) then 19 | i := 1029384756 20 | else 21 | i := 0192837465 22 | end 23 | end; 24 | i := 0 25 | end 26 | end test7_2. 27 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test7_3.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test7 3 | // 4 | // IR generation 5 | // 6 | 7 | module test7_3; 8 | 9 | var i: integer; 10 | 11 | begin 12 | if ((i < 3) && (i > 0)) then 13 | i := 0; 14 | if ((i > 9) || (i > 7)) then 15 | i := 987654321 16 | else 17 | i := -i; 18 | if (((i > 1111) && (i < 9999)) || (i = 5000)) then 19 | i := 1029384756 20 | else 21 | i := -i + 1 22 | end 23 | end; 24 | i := 0 25 | end 26 | end test7_3. 27 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test8.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test8 3 | // 4 | // IR generation 5 | // 6 | 7 | module test8; 8 | 9 | var i: integer; 10 | b: boolean; 11 | 12 | begin 13 | b := (i < 3) && (i > 0); 14 | if (b) then 15 | i := 0 16 | end 17 | end test8. 18 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test8_2.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test8_2 3 | // 4 | // IR generation 5 | // 6 | 7 | module test8_2; 8 | 9 | var i: integer; 10 | b: boolean; 11 | 12 | begin 13 | b := (1 < 3); 14 | b := (1 < 3); 15 | b := (1 < 3); 16 | // if (b) then 17 | // i := 0 18 | // end 19 | return 20 | end test8_2. 21 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test8_3.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test8 3 | // 4 | // IR generation 5 | // 6 | 7 | module test8; 8 | 9 | var i: integer; 10 | b: boolean; 11 | 12 | begin 13 | b := (i < 3); 14 | if (!b) then 15 | i := 0 16 | end 17 | end test8. 18 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test8_4.mod: -------------------------------------------------------------------------------- 1 | module test8_4; 2 | 3 | procedure f(b : boolean); 4 | begin 5 | 6 | end f; 7 | 8 | begin 9 | f(true = false); 10 | f(true = false); 11 | f(true = false); 12 | f(true); 13 | return 14 | end test8_4. 15 | -------------------------------------------------------------------------------- /4.Intermediate.Code.Generation/test/tac/test9.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test9 3 | // 4 | // IR generation 5 | // 6 | 7 | module test9; 8 | 9 | var i: integer; 10 | b: boolean; 11 | A: integer[10]; 12 | B: boolean[10]; 13 | 14 | begin 15 | b := true; 16 | b := false; 17 | b := B[0]; 18 | b := A[0] > 1; 19 | 20 | if (b) then 21 | b := true 22 | else 23 | b := false 24 | end; 25 | 26 | if (B[0]) then 27 | b := true 28 | else 29 | b := false 30 | end; 31 | 32 | if (A[0] > 1) then 33 | b := true 34 | else 35 | b := false 36 | end; 37 | 38 | i := 0 39 | end test9. 40 | -------------------------------------------------------------------------------- /5.Code.Generation/5.Code.Generation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/5.Code.Generation/5.Code.Generation.pdf -------------------------------------------------------------------------------- /5.Code.Generation/5.Final.Report_with_cover.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/5.Code.Generation/5.Final.Report_with_cover.pdf -------------------------------------------------------------------------------- /5.Code.Generation/compare: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | rm -f ./me ./egger 4 | 5 | find test/codegen -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "reference/snuplc {} && cat {}.s >> egger" 6 | find test/codegen -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "snuplc/snuplc {} && cat {}.s >> me" 7 | -------------------------------------------------------------------------------- /5.Code.Generation/compile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | rm -f ./me ./egger 4 | 5 | #find test/codegen -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "reference/snuplc --exe {}" 6 | find test/codegen -maxdepth 1 -name "*.mod" -print0 | xargs -0 -L1 -I{} -- sh -c "snuplc/snuplc --exe {}" 7 | -------------------------------------------------------------------------------- /5.Code.Generation/reference/snuplc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/5.Code.Generation/reference/snuplc -------------------------------------------------------------------------------- /5.Code.Generation/rte/IA32/ARRAY.s: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | #// @brief SnuPL dynamic array supportlibrary 3 | #// @author Bernhard Egger 4 | #// @section changelog Change Log 5 | #// 2016/03/24 Bernhard Egger created 6 | #// 7 | #// @section license_section License 8 | #// Copyright (c) 2016, Bernhard Egger 9 | #// All rights reserved. 10 | #// 11 | #// Redistribution and use in source and binary forms, with or without modifi- 12 | #// cation, are permitted provided that the following conditions are met: 13 | #// 14 | #// - Redistributions of source code must retain the above copyright notice, 15 | #// this list of conditions and the following disclaimer. 16 | #// - Redistributions in binary form must reproduce the above copyright notice, 17 | #// this list of conditions and the following disclaimer in the documentation 18 | #// and/or other materials provided with the distribution. 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 23 | #// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | #// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | #// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | #// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | #// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | #// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | #// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | #// DAMAGE. 31 | #------------------------------------------------------------------------------- 32 | 33 | .text 34 | .align 4 35 | 36 | .global DIM 37 | .global DOFS 38 | 39 | #------------------------------------------------------------------------------- 40 | # Dynamic array implementation 41 | # 42 | # The code below assumes the following layout for arrays: 43 | # 44 | # ------------------------------------------ 45 | # | #dim | d1 | d2 | ... | dn | data ... 46 | # ------------------------------------------ 47 | # ^ 48 | # | 49 | # a 50 | # 51 | # i.e., the number of dimensions (#dim) and the size of each dimension (d?) are 52 | # stored as 4-byte integers in front of the actual data 53 | # 54 | 55 | 56 | #------------------------------------------------------------------------------- 57 | # function DIM(a, d) 58 | # (C: int DIM(void *a, int d) 59 | # 60 | # returns the size of the d-th dimension of array a (d >= 1) 61 | # returns the number of dimensions of array a (d == 0) 62 | # 63 | # IA32 Linux calling convention, leaf function (no stack frame) 64 | DIM: 65 | movl 8(%esp), %eax # d 66 | shll $2, %eax # 4*d 67 | addl 4(%esp), %eax # a + 4*d 68 | 69 | movl (%eax), %eax # load dimension (no range checks) 70 | 71 | ret 72 | 73 | 74 | #------------------------------------------------------------------------------- 75 | # function DOFS(a) 76 | # (C: int DOFS(void *a)) 77 | # 78 | # returns the offset to the beginning of the data of an array a 79 | # 80 | # IA32 Linux calling convention, leaf function (no stack frame) 81 | DOFS: 82 | movl 4(%esp), %eax # ptr to a 83 | movl (%eax), %eax # load number of dimensions, #dim 84 | leal 4(,%eax,4), %eax # result = 4 + 4*#dim 85 | 86 | ret 87 | -------------------------------------------------------------------------------- /5.Code.Generation/snuplc/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CCFLAGS=-std=c++0x -g -O0 3 | 4 | SRC_DIR=src 5 | OBJ_DIR=obj 6 | 7 | DEPS=scanner.h \ 8 | parser.h \ 9 | type.h \ 10 | symtab.h \ 11 | data.h \ 12 | ast.h \ 13 | ir.h \ 14 | backend.h 15 | SCANNER=scanner.cpp 16 | PARSER=parser.cpp \ 17 | type.cpp \ 18 | symtab.cpp \ 19 | data.cpp \ 20 | ast.cpp \ 21 | ir.cpp 22 | IR= 23 | BACKEND=backend.cpp 24 | 25 | DEPS_=$(patsubst %,$(SRC_DIR)/%,$(DEPS)) 26 | OBJ_SCANNER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SCANNER)) 27 | OBJ_PARSER=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(PARSER) $(SCANNER)) 28 | OBJ_IR=$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(IR) $(PARSER) $(SCANNER)) 29 | OBJ_SNUPLC=$(patsubst %.cpp,$(OBJ_DIR)/%.o, \ 30 | $(BACKEND) $(IR) $(PARSER) $(SCANNER)) 31 | 32 | .PHONY: clean doc 33 | 34 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS_) 35 | $(CC) $(CCFLAGS) -c -o $@ $< 36 | 37 | all: snuplc 38 | 39 | test_scanner: $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 40 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_scanner.o $(OBJ_SCANNER) 41 | 42 | test_parser: $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 43 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_parser.o $(OBJ_PARSER) 44 | 45 | test_ir: $(OBJ_DIR)/test_ir.o $(OBJ_IR) 46 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/test_ir.o $(OBJ_IR) 47 | 48 | snuplc: $(OBJ_DIR)/snuplc.o $(OBJ_SNUPLC) 49 | $(CC) $(CCFLAGS) -o $@ $(OBJ_DIR)/snuplc.o $(OBJ_SNUPLC) 50 | 51 | doc: 52 | doxygen 53 | 54 | clean: 55 | rm -rf $(OBJ_DIR)/*.o test_scanner test_parser test_ir snuplc 56 | 57 | mrproper: clean 58 | rm -rf doc/* 59 | 60 | -------------------------------------------------------------------------------- /5.Code.Generation/snuplc/src/data.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SnuPL data initializers 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2016/04/05 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | 36 | #include "data.h" 37 | using namespace std; 38 | 39 | 40 | //------------------------------------------------------------------------------ 41 | // CDataInitializer 42 | // 43 | CDataInitializer::CDataInitializer(void) 44 | { 45 | } 46 | 47 | CDataInitializer::~CDataInitializer(void) 48 | { 49 | } 50 | 51 | ostream& operator<<(ostream &out, const CDataInitializer &t) 52 | { 53 | return t.print(out); 54 | } 55 | 56 | ostream& operator<<(ostream &out, const CDataInitializer *t) 57 | { 58 | return t->print(out); 59 | } 60 | 61 | 62 | //------------------------------------------------------------------------------ 63 | // CDataInitString 64 | // 65 | CDataInitString::CDataInitString(const string data) 66 | : CDataInitializer(), _data(data) 67 | { 68 | } 69 | 70 | string CDataInitString::GetData(void) const 71 | { 72 | return _data; 73 | } 74 | 75 | ostream& CDataInitString::print(ostream &out, int indent) const 76 | { 77 | string ind(indent, ' '); 78 | 79 | out << ind << "[ data: '" << _data << "' ]"; 80 | return out; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /5.Code.Generation/snuplc/src/test_scanner.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | /// @brief SNUPL scanner test 3 | /// @author Bernhard Egger 4 | /// @section changelog Change Log 5 | /// 2012/09/14 Bernhard Egger created 6 | /// 7 | /// @section license_section License 8 | /// Copyright (c) 2012-2016, Bernhard Egger 9 | /// All rights reserved. 10 | /// 11 | /// Redistribution and use in source and binary forms, with or without modifi- 12 | /// cation, are permitted provided that the following conditions are met: 13 | /// 14 | /// - Redistributions of source code must retain the above copyright notice, 15 | /// this list of conditions and the following disclaimer. 16 | /// - Redistributions in binary form must reproduce the above copyright notice, 17 | /// this list of conditions and the following disclaimer in the documentation 18 | /// and/or other materials provided with the distribution. 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 23 | /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE- 25 | /// QUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 | /// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | /// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | /// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | /// DAMAGE. 31 | //------------------------------------------------------------------------------ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "scanner.h" 38 | using namespace std; 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | int i = 1; 43 | 44 | while (i < argc) { 45 | CScanner *s = new CScanner(new ifstream(argv[i])); 46 | 47 | cout << "scanning '" << argv[i] << "'..." << endl; 48 | 49 | if (!s->Good()) cout << " cannot open input stream: " << s->Peek() << endl; 50 | 51 | while (s->Good()) { 52 | CToken t = s->Get(); 53 | cout << " " << t << endl; 54 | if (t.GetType() == tEOF) break; 55 | } 56 | 57 | cout << endl << endl; 58 | 59 | i++; 60 | } 61 | 62 | cout << "Done." << endl; 63 | 64 | return EXIT_SUCCESS; 65 | } 66 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/.test05.mod.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/5.Code.Generation/test/codegen/.test05.mod.swp -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/.test11.mod.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cseteram/Eggompilers/882bd9cf1f04f4cfc1010be5c85d1efbb0f83606/5.Code.Generation/test/codegen/.test11.mod.swp -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/Makefile: -------------------------------------------------------------------------------- 1 | compile: 2 | @echo "snuplc --exe `find . -type f -and -iname \*.mod -exec echo {} \+`" 3 | 4 | clean: 5 | @rm -f *.mod.ast *.mod.ast.dot *.mod.ast.dot.pdf *.mod.tac *.mod.tac.dot *.mod.tac.dot.pdf *.mod.s 6 | @find . -type f -and -executable -exec rm {} \+ 7 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/factorial.mod: -------------------------------------------------------------------------------- 1 | // 2 | // factorial 3 | // 4 | // factorial computation 5 | // 6 | 7 | module factorial; 8 | 9 | var i : integer; 10 | 11 | function fact(n: integer): integer; 12 | begin 13 | if (n <= 0) then 14 | return 0 15 | else 16 | if (n <= 1) then 17 | return n 18 | else 19 | return n*fact(n-1) 20 | end 21 | end 22 | end fact; 23 | 24 | function ReadNumber(str: char[]): integer; 25 | var i: integer; 26 | begin 27 | WriteStr(str); 28 | i := ReadInt(); 29 | return i 30 | end ReadNumber; 31 | 32 | begin 33 | WriteStr("Factorials"); WriteLn(); 34 | WriteLn(); 35 | 36 | i := ReadNumber("Enter a number (0 to exit): "); 37 | 38 | while (i > 0) do 39 | WriteStr("factorial("); WriteInt(i); WriteStr(") = "); 40 | WriteInt(fact(i)); WriteLn(); 41 | 42 | i := ReadNumber("Enter a number (0 to exit): ") 43 | end 44 | end factorial. 45 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/fibonacci.mod: -------------------------------------------------------------------------------- 1 | // 2 | // fibonacci 3 | // 4 | // fibonacci computation 5 | // 6 | 7 | module fibonacci; 8 | 9 | var i : integer; 10 | 11 | function fib(n: integer): integer; 12 | begin 13 | if (n <= 1) then 14 | return n 15 | else 16 | return fib(n-1) + fib(n-2) 17 | end 18 | end fib; 19 | 20 | function ReadNumber(str: char[]): integer; 21 | var i: integer; 22 | begin 23 | WriteStr(str); 24 | i := ReadInt(); 25 | return i 26 | end ReadNumber; 27 | 28 | begin 29 | WriteStr("Fibonacci numbers"); WriteLn(); 30 | WriteLn(); 31 | 32 | i := ReadNumber("Enter a number (0 to exit): "); 33 | 34 | while (i > 0) do 35 | WriteStr("fibonacci("); WriteInt(i); WriteStr(") = "); 36 | WriteInt(fib(i)); WriteLn(); 37 | 38 | i := ReadNumber("Enter a number (0 to exit): ") 39 | end 40 | end fibonacci. 41 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/gcd.mod: -------------------------------------------------------------------------------- 1 | // 2 | // gcd 3 | // 4 | // greatest common divisor 5 | // using the Euclidian algorithm 6 | // 7 | 8 | module gcd; 9 | 10 | var n: integer[2]; 11 | 12 | // gcd(a: integer[2]) 13 | // 14 | // computes the greatest common divisor 15 | // subtraction-based version 16 | function gcd_iter(a: integer[2]): integer; 17 | begin 18 | while (a[0] # a[1]) do 19 | if (a[0] > a[1]) then a[0] := a[0] - a[1] 20 | else a[1] := a[1] - a[0] 21 | end 22 | end; 23 | return a[0] 24 | end gcd_iter; 25 | 26 | // gcd(a: integer[2]) 27 | // 28 | // computes the greatest common divisor 29 | // division-based version 30 | function gcd_mod(a: integer[2]): integer; 31 | var t: integer; 32 | begin 33 | while (a[1] # 0) do 34 | t := a[1]; 35 | a[1] := a[0] - a[0]/t*t; 36 | a[0] := t 37 | end; 38 | return a[0] 39 | end gcd_mod; 40 | 41 | // gcd(a: integer[2]) 42 | // 43 | // computes the greatest common divisor 44 | // recursive version 45 | function gcd_rec(a: integer[2]): integer; 46 | var t: integer; 47 | begin 48 | if (a[1] = 0) then return a[0] 49 | else 50 | //return gcd_rec(a[1], a[0] - a/b*b) 51 | t := a[0]; 52 | a[0] := a[1]; 53 | a[1] := t - t/a[1]*a[1]; 54 | return gcd_rec(a) 55 | end 56 | end gcd_rec; 57 | 58 | procedure ReadNumbers(n: integer[2]); 59 | var i: integer; 60 | begin 61 | WriteStr("Enter first number : "); 62 | n[0] := ReadInt(); 63 | WriteStr("Enter second number: "); 64 | n[1] := ReadInt() 65 | end ReadNumbers; 66 | 67 | begin 68 | WriteStr("Greatest commond divisor"); WriteLn(); 69 | WriteLn(); 70 | 71 | ReadNumbers(n); 72 | 73 | WriteStr(" subtract : "); WriteInt(gcd_iter(n)); WriteLn(); 74 | WriteStr(" divide : "); WriteInt(gcd_mod(n)); WriteLn(); 75 | WriteStr(" recursive : "); WriteInt(gcd_rec(n)); WriteLn() 76 | end gcd. 77 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/hmtest01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // hmtest01 3 | // 4 | // arrays 5 | // 6 | // expected output: "435" "136524" 7 | // 8 | 9 | module hmtest01; 10 | 11 | var a : integer[5]; 12 | b : integer[5][5][5]; 13 | i,j,k : integer; 14 | 15 | procedure fun1(A : integer[]); 16 | var B : integer[5]; 17 | begin 18 | i := 0; 19 | while (i < 5) do 20 | B[4 - i] := A[i]; 21 | i := i + 1 22 | end; 23 | 24 | WriteInt(B[1]); 25 | WriteInt(B[2]); 26 | WriteInt(B[0]); 27 | WriteLn(); 28 | return 29 | end fun1; 30 | 31 | procedure fun2(A : integer[][][]); 32 | var B : integer[5][5][5]; 33 | begin 34 | i := 0; 35 | j := 0; 36 | k := 0; 37 | 38 | while (i < 5) do 39 | j := 0; 40 | while (j < 5) do 41 | k := 0; 42 | while (k < 5) do 43 | B[i][j][k] := A[k][j][i]; 44 | k := k + 1 45 | end; 46 | j := j + 1 47 | end; 48 | i := i + 1 49 | end; 50 | 51 | WriteInt(B[1][0][0]); 52 | WriteInt(B[2][1][0]); 53 | WriteInt(B[3][2][1]); 54 | WriteInt(B[0][3][2]); 55 | WriteInt(B[1][0][1]); 56 | WriteInt(B[0][4][0]); 57 | WriteLn(); 58 | return 59 | end fun2; 60 | 61 | begin 62 | i := 0; 63 | j := 0; 64 | k := 0; 65 | 66 | while (i < 5) do 67 | a[i] := i + 1; 68 | j := 0; 69 | while (j < 5) do 70 | k := 0; 71 | while (k < 5) do 72 | b[i][j][k] := i + j + k; 73 | k := k + 1 74 | end; 75 | j := j + 1 76 | end; 77 | i := i + 1 78 | end; 79 | 80 | fun1(a); 81 | fun2(b); 82 | 83 | return 84 | end hmtest01. 85 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/hmtest02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // hmtest02 3 | // 4 | // arrays of string 5 | // 6 | // expected output: "Hello2Hello1Hello4Hello3" "Hello, World!" 7 | // 8 | 9 | module hmtest02; 10 | 11 | var g_arr : char[7][4]; 12 | 13 | procedure split(str_arr : char [7][4]); 14 | var arr1, arr2, arr3, arr4 : char[7]; 15 | i, j : integer; 16 | begin 17 | i := 0; 18 | while (i < 7) do 19 | arr2[i] := str_arr[i][0]; 20 | arr1[i] := str_arr[i][1]; 21 | arr4[i] := str_arr[i][2]; 22 | arr3[i] := str_arr[i][3]; 23 | i := i + 1 24 | end; 25 | 26 | WriteStr(arr1); 27 | WriteStr(arr2); 28 | WriteStr(arr3); 29 | WriteStr(arr4); 30 | WriteLn(); 31 | return 32 | end split; 33 | 34 | function merge( 35 | str1 : char[7]; 36 | str2 : char[7]; 37 | str3 : char[7]; 38 | str4 : char[7] 39 | ) : boolean; 40 | var str_arr : char[7][4]; 41 | i : integer; 42 | begin 43 | i := 0; 44 | while (i < 7) do 45 | str_arr[i][0] := str1[i]; 46 | str_arr[i][1] := str2[i]; 47 | str_arr[i][2] := str3[i]; 48 | str_arr[i][3] := str4[i]; 49 | i := i + 1 50 | end; 51 | 52 | split(str_arr); 53 | return true 54 | end merge; 55 | 56 | begin 57 | if (merge("Hello1", "Hello2", "Hello3", "Hello4")) then 58 | WriteStr("Hello, World!"); 59 | WriteLn() 60 | end 61 | 62 | end hmtest02. 63 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/instr00.mod: -------------------------------------------------------------------------------- 1 | module instr00; 2 | 3 | var a,b,c : integer; 4 | d0,d1,d2 : boolean; 5 | 6 | begin 7 | 8 | // binary operations 9 | a := b + c; // opAdd 10 | a := b - c; // opSub 11 | a := b * c; // opMul 12 | a := b / c; // opDiv 13 | d0 := d1 && d2; // opAnd 14 | d0 := d1 || d2 // opOr 15 | 16 | end instr00. 17 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/instr01.mod: -------------------------------------------------------------------------------- 1 | module instr01; 2 | 3 | var a, b : integer; 4 | c, d : boolean; 5 | 6 | begin 7 | // unary operators 8 | a := +a; 9 | a := -a; 10 | c := !d 11 | 12 | end instr01. 13 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/instr02.mod: -------------------------------------------------------------------------------- 1 | module instr02; 2 | 3 | var ret : integer; 4 | 5 | procedure f(i : integer; j : boolean; k : char); 6 | begin 7 | end f; 8 | 9 | function g(i : integer; j : boolean; k : char) : integer; 10 | begin 11 | return -1 12 | end g; 13 | 14 | begin 15 | // function-realted instructions 16 | f(0, true, 'a'); 17 | g(0, true, 'a'); 18 | ret := g(1, false, 'b'); 19 | return 20 | end instr02. 21 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/instr03.mod: -------------------------------------------------------------------------------- 1 | module instr03; 2 | 3 | var a : integer[3][4]; 4 | b : boolean[3][4]; 5 | c : char[3][4]; 6 | 7 | procedure f(arr : integer[][]); 8 | begin 9 | end f; 10 | 11 | procedure g(arr : boolean[][]); 12 | begin 13 | end g; 14 | 15 | procedure h(arr : char[][]); 16 | begin 17 | end h; 18 | 19 | begin 20 | // reference instruction 21 | f(a); 22 | g(b); 23 | h(c); 24 | return 25 | end instr03. 26 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pfact.mod: -------------------------------------------------------------------------------- 1 | // 2 | // prime factors 3 | // 4 | 5 | module pfact; 6 | 7 | var n: integer; 8 | 9 | procedure primefactor(n: integer); 10 | var f: integer; 11 | begin 12 | if (n < 1) then return 13 | else 14 | if (n = 1) then WriteStr(" "); WriteInt(1) 15 | else 16 | f := 2; 17 | while (f <= n) do 18 | if (n/f*f = n) then 19 | WriteStr(" "); WriteInt(f); 20 | n := n/f 21 | else 22 | f := f + 1 23 | end 24 | end 25 | end 26 | end 27 | end primefactor; 28 | 29 | begin 30 | WriteStr("Prime factoring"); WriteLn(); 31 | WriteLn(); 32 | WriteStr("Enter number to factor: "); n := ReadInt(); 33 | WriteStr(" prime factors of "); WriteInt(n); WriteStr(": "); 34 | primefactor(n); WriteLn() 35 | end pfact. 36 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/primes.mod: -------------------------------------------------------------------------------- 1 | // 2 | // primes 3 | // 4 | // compute prime numbers 5 | // (not in a very efficient way) 6 | // 7 | 8 | module primes; 9 | 10 | var n, pn: integer; 11 | p: integer[1000000]; 12 | 13 | function CalcPrimes(p: integer[]; n: integer): integer; 14 | var N, pidx, psqrt, v, i: integer; 15 | isprime: boolean; 16 | begin 17 | WriteStr(" computing primes from 1 to "); WriteInt(n); WriteStr("..."); 18 | 19 | N := DIM(p, 1); // size of array 20 | if (N < 1) then return 0 end; 21 | 22 | 23 | p[0] := 1; // 1 is prime 24 | p[1] := 2; // 2 is prime 25 | pidx := 2; // index of next prime in p[] 26 | 27 | psqrt := 1; // index of prime used as square root 28 | 29 | v := 3; // next number to test 30 | 31 | while (v <= n) do 32 | // check whether v is prime by dividing it by all primes 33 | // up to p[psqrt] 34 | isprime := true; 35 | i := 1; 36 | while (isprime && (i <= psqrt)) do 37 | if (v/p[i]*p[i] = v) then 38 | isprime := false 39 | end; 40 | i := i + 1 41 | end; 42 | 43 | // if v is prime store it in p[] 44 | if (isprime = true) then 45 | p[pidx] := v; 46 | pidx := pidx + 1; 47 | if (pidx = N) then 48 | // reached end of array, stop 49 | WriteStr("WARNING: array too small to hold all primes."); 50 | n := 0 51 | end 52 | end; 53 | 54 | v := v + 2; 55 | 56 | if (v > p[psqrt]*p[psqrt]) then 57 | psqrt := psqrt + 1; 58 | if (psqrt >= pidx) then 59 | WriteStr("ERROR."); 60 | n := 0 61 | end 62 | end 63 | end; 64 | 65 | WriteStr("done. "); WriteInt(pidx); WriteStr(" primes found."); WriteLn(); 66 | return pidx 67 | end CalcPrimes; 68 | 69 | procedure PrintPrimes(p: integer[]; n, pn: integer); 70 | var i: integer; 71 | begin 72 | WriteStr("Prime numbers 1 to "); WriteInt(n); WriteLn(); 73 | i := 0; 74 | while (i < pn) do 75 | WriteStr(" "); WriteInt(p[i]); 76 | i := i + 1; 77 | if (i/8*8 = i) then WriteLn() end 78 | end; 79 | WriteLn() 80 | end PrintPrimes; 81 | 82 | begin 83 | WriteStr("Prime numbers"); WriteLn(); 84 | WriteStr("Compute primes up to : "); n := ReadInt(); 85 | pn := CalcPrimes(p, n); 86 | PrintPrimes(p, n, pn) 87 | end primes. 88 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest00.mod: -------------------------------------------------------------------------------- 1 | // pstest00.mod 2 | // this tests the function with boolean return type, 3 | // integer array, and boolean array. 4 | 5 | module pstest00; 6 | 7 | var a : integer[111111]; 8 | b : integer[1111][1111]; 9 | n, m, sum : integer; 10 | 11 | procedure input; 12 | var i, j : integer; 13 | begin 14 | n := ReadInt(); m := ReadInt(); 15 | i := 0; j := 0; 16 | 17 | while (i < n*m) do 18 | a[i] := ReadInt(); 19 | i := i+1 20 | end; 21 | 22 | i := 0; 23 | while (i < n) do 24 | while (j < m) do 25 | b[i][j] := ReadInt(); 26 | j := j+1 27 | end; 28 | i := i+1 29 | end; 30 | 31 | return 32 | end input; 33 | 34 | function div(value : integer ; q : integer) : integer; 35 | begin 36 | return value / q 37 | end div; 38 | 39 | function mod(value : integer ; q : integer) : integer; 40 | begin 41 | return value - value / q * q 42 | end mod; 43 | 44 | function pos(index : integer ; arr : integer[][]) : boolean; 45 | var x : integer; 46 | begin 47 | x := mod(index, n * m); 48 | if (arr[div(x,m)][mod(x,m)] = 0) then 49 | return false 50 | end; 51 | return true 52 | end pos; 53 | 54 | procedure process(); 55 | var i : integer; 56 | begin 57 | i := 0; 58 | 59 | while (pos(a[i], b) && (i < n*m)) do 60 | sum := sum + a[i]; 61 | i := i+1 62 | end 63 | 64 | end process; 65 | 66 | procedure output(); 67 | begin 68 | WriteInt(sum) 69 | end output; 70 | 71 | begin 72 | input(); 73 | process(); 74 | output() 75 | end pstest00. 76 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest01.mod: -------------------------------------------------------------------------------- 1 | // pstest01.mod 2 | // function declaration without return statements 3 | // remark that it is undefined behaviour in c and c++, not compile error 4 | 5 | module pstest01; 6 | 7 | var a : integer; 8 | 9 | function f(a : integer) : integer; 10 | 11 | begin 12 | a := 3; 13 | WriteInt(a) 14 | end f; 15 | 16 | begin 17 | a := ReadInt(); 18 | a := f(a); 19 | WriteInt(a) 20 | end pstest01. 21 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest02.mod: -------------------------------------------------------------------------------- 1 | // pstest02.mod 2 | // statSequence = [ statement { ";" statement } ] 3 | // therefore, statSequence can be empty. 4 | 5 | module pstest02; 6 | 7 | var a : boolean; 8 | 9 | function input() : boolean; 10 | 11 | var x : integer; 12 | 13 | begin 14 | x := ReadInt(); 15 | if (x = 0) then 16 | return false 17 | end; 18 | return true 19 | end input; 20 | 21 | procedure empty; 22 | begin 23 | end empty; 24 | 25 | begin 26 | WriteStr ("module begin"); 27 | WriteStr ("enter a integer. nonzero means true, and zero means false"); 28 | a := input(); 29 | empty(); 30 | 31 | if (a) then end; 32 | if (!a) then end; 33 | WriteStr("if statements end"); 34 | 35 | while (!a) do end; 36 | WriteStr("while statements end"); 37 | 38 | WriteStr("module end") 39 | end pstest02. 40 | 41 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest04.mod: -------------------------------------------------------------------------------- 1 | // pstest04.mod 2 | // tests not matchable array parameter 3 | 4 | module pstest04; 5 | 6 | var a : integer[3][5][5][6]; 7 | 8 | function f(a : integer[][5][][]) : integer; 9 | begin 10 | if (a[0][0][0][0] > a[1][1][1][1]) then 11 | // return a[0][0][0][0] 12 | else 13 | // return a[1][1][1][1] 14 | end; 15 | return -1 16 | end f; 17 | 18 | function g() : integer; 19 | begin 20 | return -1 21 | end g; 22 | 23 | begin 24 | WriteInt(f(a)) 25 | end pstest04. 26 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest06.mod: -------------------------------------------------------------------------------- 1 | // pstest06 2 | // fibonacci seq. 3 | 4 | module pstest06; 5 | 6 | function fib(n : integer) : integer; 7 | begin 8 | if (n < 0) then 9 | WriteStr("number cannot be a negative integer"); 10 | return -1 11 | else 12 | if (n = 0) then 13 | return 0 14 | else 15 | if (n = 1) then 16 | return 1 17 | else 18 | return fib(n-2) + fib(n-1) 19 | end 20 | end 21 | end 22 | end fib; 23 | 24 | begin 25 | 26 | end pstest06. 27 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest07.mod: -------------------------------------------------------------------------------- 1 | // add, minus, mul, div, equal, A+B problem 2 | 3 | module pstest02; 4 | 5 | var a,b,c,d,e,f : integer; g : boolean; 6 | 7 | function add(a:integer; b:integer) : integer; 8 | begin 9 | return a + b 10 | end add; 11 | 12 | function minus(a:integer; b:integer) : integer; 13 | begin 14 | return a - b 15 | end minus; 16 | 17 | function mul(a:integer; b:integer) : integer; 18 | begin 19 | return a * b 20 | end mul; 21 | 22 | function div(a:integer; b:integer) : integer; 23 | begin 24 | return a / b 25 | end div; 26 | 27 | function equal(a:integer; b:integer) : boolean; 28 | begin 29 | return a = b 30 | end equal; 31 | 32 | procedure printAdd(a:integer; b:integer); 33 | begin 34 | WriteInt(a+b) 35 | end printAdd; 36 | 37 | begin 38 | a := 1; b := 2; 39 | c := add(a,b); 40 | d := minus(a,b); 41 | e := mul(a,b); 42 | f := div(a,b); 43 | g := equal(a,b); 44 | printAdd(a,b) 45 | end pstest02. 46 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest08.mod: -------------------------------------------------------------------------------- 1 | // find element in array 2 | 3 | module heehoon; 4 | 5 | var a : integer[111111]; 6 | x,n,i : integer; 7 | 8 | function find (arr : integer[]; elem : integer) : boolean; 9 | var i,N : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | while (i < N) do 13 | if (arr[i] = elem) then 14 | return true 15 | end; 16 | i := i+1 17 | end; 18 | return false 19 | end find; 20 | 21 | begin 22 | n := ReadInt(); 23 | 24 | i := 0; 25 | while (i < n) do 26 | a[i] := ReadInt() 27 | end; 28 | 29 | x := ReadInt(); 30 | 31 | if (find(a,x)) then 32 | WriteStr("Found") 33 | else 34 | WriteStr("Not Found. I EGGER U") 35 | end; 36 | WriteLn() 37 | end heehoon. 38 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest09.mod: -------------------------------------------------------------------------------- 1 | // find 2 | 3 | module pstest04; 4 | 5 | var a : integer[1111][1111]; 6 | n, m, i, j : integer; 7 | 8 | function sum (arr : integer[][]) : integer; 9 | var ret, N, M, i, j : integer; 10 | begin 11 | N := DIM(arr, 1); 12 | M := DIM(arr, 2); 13 | 14 | i := 0; 15 | while (i < N) do 16 | j := 0; 17 | while (j < M) do 18 | ret := ret + arr[i][j]; 19 | j := j+1 20 | end; 21 | i := i+1 22 | end; 23 | return ret 24 | end sum; 25 | 26 | begin 27 | n := ReadInt(); 28 | m := ReadInt(); 29 | 30 | i := 0; 31 | while (i < n) do 32 | j := 0; 33 | while (j < m) do 34 | a[i][j] := ReadInt(); 35 | j := j+1 36 | end; 37 | i := i+1 38 | end; 39 | 40 | WriteInt(sum(a)); 41 | WriteLn() 42 | end pstest04. 43 | 44 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest10.mod: -------------------------------------------------------------------------------- 1 | // pstest10 2 | // https://www.acmicpc.net/problem/12790 3 | 4 | module MiniFantasyWar; 5 | var T, tc, i, ans : integer; 6 | input : integer[8]; 7 | 8 | function solve(stats : integer[]) : integer; 9 | var hp, ehp, mp, emp, atk, eatk, def, edef : integer; 10 | ret : integer; 11 | begin 12 | hp := stats[0]; ehp := stats[1]; mp := stats[2]; emp := stats[3]; 13 | atk := stats[4]; eatk := stats[5]; def := stats[6]; edef := stats[7]; 14 | 15 | ret := 0; 16 | if (hp + ehp >= 1) then 17 | ret := ret + hp + ehp 18 | else 19 | ret := ret + 1 20 | end; 21 | if (mp + emp >= 1) then 22 | ret := ret + 5 * (mp + emp) 23 | else 24 | ret := ret + 5 * 1 25 | end; 26 | if (atk + eatk >= 0) then 27 | ret := 2 * (atk + eatk) 28 | end; 29 | ret := ret + 2 * (def + edef); 30 | 31 | return ret 32 | end solve; 33 | 34 | begin 35 | T := ReadInt(); 36 | 37 | tc := 0; 38 | while (tc < T) do 39 | i := 0; 40 | while (i < 8) do 41 | input[i] := ReadInt(); 42 | i := i + 1 43 | end; 44 | 45 | ans := solve(input); 46 | WriteInt(ans); 47 | WriteLn(); 48 | 49 | tc := tc + 1 50 | end 51 | end MiniFantasyWar. 52 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest12.mod: -------------------------------------------------------------------------------- 1 | // pstest12 2 | // https://www.acmicpc.net/problem/12792 3 | 4 | module jujak_ju_jujak; 5 | 6 | begin 7 | WriteInt(1000003) 8 | end jujak_ju_jujak. 9 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/pstest13.mod: -------------------------------------------------------------------------------- 1 | module pstest13; 2 | 3 | var cond1 : boolean[5]; 4 | cond2 : boolean[7][3]; 5 | cond3 : boolean[9][4][8]; 6 | cond4 : boolean[11][2][3][5]; 7 | ret : boolean; 8 | 9 | function f 10 | (c1 : boolean[]; c2 : boolean[][]; 11 | c3 : boolean[][][]; c4 : boolean[][][][5]) : boolean; 12 | begin 13 | if (c1[3] || c2[3][2] || c3[3][2][1] || c4[3][2][1][0]) then 14 | if (c1[3]) then 15 | return !c1[3] 16 | else 17 | return !(c2[3][2] && c3[3][2][1]) 18 | end 19 | else 20 | return !(c3[3][2][1] || c4[3][2][1][0]) 21 | end; 22 | return !c3[3][2][1]; 23 | return !f(c1, c2, c3, c4); 24 | return f(c1, c2, c3, c4) 25 | end f; 26 | 27 | begin 28 | while (f(cond1, cond2, cond3, cond4)) do 29 | while (!f(cond1, cond2, cond3, cond4)) do 30 | if (cond1[5]) then 31 | ret := !cond3[1][3][2] 32 | else 33 | ret := cond3[3][2][1] && cond2[1][2] 34 | end 35 | end; 36 | while(!cond2[3][4]) do 37 | while(!cond4[9][8][7][6]) do 38 | if (cond3[1][3][2]) then 39 | ret := !true || false 40 | else 41 | ret := !true && true 42 | end 43 | end 44 | end 45 | end; 46 | if (ret && cond1[0]) then 47 | WriteStr("sound, compact"); 48 | WriteLn(); 49 | WriteInt(1) 50 | else 51 | if (ret && !cond1[0]) then 52 | WriteStr("sound, not compact"); 53 | WriteLn(); 54 | WriteInt(1) 55 | else 56 | if (!ret && cond1[0]) then 57 | WriteStr("not sound, compact"); 58 | WriteLn(); 59 | WriteInt(1) 60 | else 61 | WriteStr("not sound, not compact"); 62 | WriteLn(); 63 | WriteInt(0) 64 | end 65 | end 66 | end; 67 | 68 | return 69 | end pstest13. 70 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/ref_bug0.mod: -------------------------------------------------------------------------------- 1 | module a; 2 | 3 | var i : integer; 4 | 5 | begin 6 | i := 4; 7 | WriteInt(i); 8 | WriteLn(); 9 | i := +i; 10 | WriteInt(i); 11 | WriteLn(); 12 | return 13 | end a. 14 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/ref_bug1.mod: -------------------------------------------------------------------------------- 1 | // pstest04.mod 2 | // tests not matchable array parameter 3 | 4 | module pstest04; 5 | 6 | var a : integer[3][5][5][6]; 7 | 8 | function f(a : integer[][5][][]) : integer; 9 | begin 10 | if (a[0][0][0][0] > a[1][1][1][1]) then 11 | // return a[0][0][0][0] 12 | else 13 | // return a[1][1][1][1] 14 | end; 15 | return -2147483648 16 | end f; 17 | 18 | function g() : integer; 19 | begin 20 | return -1 21 | end g; 22 | 23 | begin 24 | WriteInt(f(a)); 25 | WriteLn(); 26 | return 27 | end pstest04. 28 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple00.mod: -------------------------------------------------------------------------------- 1 | module simple00; 2 | 3 | procedure f(a, b : integer); 4 | begin 5 | 6 | end f; 7 | 8 | begin 9 | f(1, 2) 10 | end simple00. 11 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple01.mod: -------------------------------------------------------------------------------- 1 | module simple00; 2 | 3 | var sum : integer; 4 | 5 | function f(a, b : integer) : integer; 6 | begin 7 | return a + b 8 | end f; 9 | 10 | begin 11 | sum := f(1, 2); 12 | WriteInt(sum) 13 | end simple00. 14 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple02.mod: -------------------------------------------------------------------------------- 1 | module simple02; 2 | 3 | var i : integer; 4 | 5 | begin 6 | if (i > 3) then 7 | i := 3 8 | else 9 | i := i 10 | end 11 | end simple02. 12 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple03.mod: -------------------------------------------------------------------------------- 1 | module simple03; 2 | 3 | var i, sum : integer; 4 | 5 | begin 6 | while ((i < 3) && (i < 4)) do 7 | sum := sum + i; 8 | i := i + 1 9 | end 10 | end simple03. 11 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple04.mod: -------------------------------------------------------------------------------- 1 | module simple04; 2 | 3 | var i : boolean; 4 | 5 | begin 6 | if ((4 > 3) && (5 > 3) && (1 + 6 > 3)) then 7 | i := true && true 8 | else 9 | i := true && false 10 | end 11 | end simple04. 12 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple05.mod: -------------------------------------------------------------------------------- 1 | module simple05; 2 | 3 | var i, j, k : boolean; 4 | 5 | begin 6 | i := false || false; 7 | i := (j = k) 8 | end simple05. 9 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple06.mod: -------------------------------------------------------------------------------- 1 | module simple06; 2 | 3 | var i : boolean; 4 | 5 | function f : boolean; 6 | begin 7 | return true 8 | end f; 9 | 10 | begin 11 | if (f()) then 12 | i := f() 13 | end; 14 | 15 | i := (f() && f()) 16 | end simple06. 17 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple07.mod: -------------------------------------------------------------------------------- 1 | module simple07; 2 | 3 | var i : boolean; 4 | 5 | function f(a,b : boolean) : boolean; 6 | begin 7 | return a && b && a && b 8 | end f; 9 | 10 | begin 11 | i := f(true, true) || f(true, false) 12 | end simple07. 13 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple08.mod: -------------------------------------------------------------------------------- 1 | module simple08; 2 | 3 | var i : integer; 4 | j, j0, j1, j2 : boolean; 5 | k : boolean; 6 | l, l0 : boolean; 7 | 8 | begin 9 | 10 | i := (i + 1); 11 | j := (j0 && j1) && j2; 12 | j := j0 && j1; 13 | i := i + i; 14 | k := (i > 2); 15 | l := (l = l0); 16 | 17 | return 18 | 19 | end simple08. 20 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple09.mod: -------------------------------------------------------------------------------- 1 | module simple09; 2 | 3 | var i : integer; 4 | j : boolean; 5 | b1, b2 : boolean; 6 | function f(i : integer) : boolean; 7 | begin 8 | return true 9 | end f; 10 | 11 | procedure g(b : boolean); 12 | begin 13 | 14 | end g; 15 | 16 | begin 17 | i := +i; 18 | i := -i; 19 | j := !j && j; 20 | j := j && !j; 21 | j := !j && !j; 22 | j := !(j && j); 23 | g(!(true || false)); 24 | 25 | j := !(b1 && b2); 26 | j := !j; 27 | j := !f(1); 28 | j := (-i > -i); 29 | i := -2147483648; 30 | 31 | return 32 | end simple09. 33 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple09_2.mod: -------------------------------------------------------------------------------- 1 | module simple09_2; 2 | 3 | var b1,b2,b3,b4,b5 : boolean; 4 | ret : boolean; 5 | 6 | function f(arg : boolean) : boolean; 7 | begin 8 | ret := !(b1 && b2); 9 | ret := !true; 10 | ret := f(!(b1 && b2)); 11 | f(!(b1 && b2)); 12 | if (!(b1 && b2)) then end; 13 | while (!(b1 && b2)) do end; 14 | return (!(b1 && b2)) 15 | end f; 16 | 17 | begin 18 | 19 | end simple09_2. 20 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple10.mod: -------------------------------------------------------------------------------- 1 | module simple10; 2 | 3 | var a : integer[5]; 4 | b : integer[5][5]; 5 | procedure f(a : integer[]); 6 | begin 7 | end f; 8 | 9 | begin 10 | f(a); 11 | f(b[5]); 12 | return 13 | end simple10. 14 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple11.mod: -------------------------------------------------------------------------------- 1 | module simple11; 2 | 3 | var b : boolean; 4 | 5 | begin 6 | b := !b; 7 | if (!b) then 8 | else 9 | end 10 | end simple11. 11 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple12.mod: -------------------------------------------------------------------------------- 1 | module simple12; 2 | 3 | var i, j : boolean; 4 | 5 | begin 6 | 7 | i := i || j || i || j 8 | 9 | end simple12. 10 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple13.mod: -------------------------------------------------------------------------------- 1 | module simple13; 2 | 3 | var res : boolean; 4 | 5 | begin 6 | res := !true || false 7 | end simple13. 8 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple14.mod: -------------------------------------------------------------------------------- 1 | module simple14; 2 | 3 | var i : integer; 4 | b : boolean; 5 | 6 | begin 7 | b := !(i<3); 8 | b := (i<3); 9 | return 10 | end simple14. 11 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple15.mod: -------------------------------------------------------------------------------- 1 | module simple15; 2 | 3 | var i, j, k, l, n, m : boolean; 4 | ret : boolean; 5 | 6 | begin 7 | ret := (i = j) || (k # l) && (!j) || (!n && (n || m)) && true || (!true && (i && (j || (k && (l || (!l || l)))))); 8 | return 9 | end simple15. 10 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple16.mod: -------------------------------------------------------------------------------- 1 | module simple16; 2 | 3 | var i : boolean; 4 | j : integer; 5 | 6 | begin 7 | 8 | i := (j > 3); 9 | i := (j > 3); 10 | return 11 | 12 | end simple16. 13 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple17.mod: -------------------------------------------------------------------------------- 1 | module simple17; 2 | 3 | var i : integer; 4 | 5 | begin 6 | 7 | // i := 2147483648 // error 8 | i := +9999; 9 | i := +(+9999); 10 | i := +(+(+(+(+9999)))); 11 | i := -2147483648; 12 | i := -(-2147483648); 13 | i := -(-(-(-(-2147483648)))); 14 | i := -2147483648 + 3 + (-7) - (-8); 15 | // i := -2147483648 * 3; // error when simple 16 | return 17 | 18 | end simple17. 19 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple19.mod: -------------------------------------------------------------------------------- 1 | module simple19; 2 | 3 | var a, b : boolean; 4 | 5 | begin 6 | 7 | a := !b 8 | 9 | end simple19. 10 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple20.mod: -------------------------------------------------------------------------------- 1 | module simple20; 2 | 3 | var b : boolean; 4 | 5 | function f() : boolean; 6 | begin 7 | end f; 8 | 9 | function g() : boolean; 10 | begin 11 | end g; 12 | 13 | function h() : boolean; 14 | begin 15 | end h; 16 | 17 | begin 18 | 19 | b := f() && g() || h() && g() || !h(); 20 | if (f()) then else end 21 | 22 | end simple20. 23 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple21.mod: -------------------------------------------------------------------------------- 1 | module simple21; 2 | 3 | var b : boolean; 4 | 5 | begin 6 | b := b && b && b && b 7 | end simple21. 8 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple22.mod: -------------------------------------------------------------------------------- 1 | module simple22; 2 | 3 | var a, i : integer; 4 | b : boolean; 5 | 6 | begin 7 | a := i + 3 8 | // b := i > 3; 9 | // b := b || b || b || b 10 | end simple22. 11 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/simple23.mod: -------------------------------------------------------------------------------- 1 | module simple23; 2 | 3 | function f() : integer; 4 | begin 5 | if (true) then 6 | else 7 | end; 8 | return -1 9 | // return -2; 10 | // return -987654321; 11 | // return -12345; 12 | // return -2147483648 13 | end f; 14 | 15 | begin 16 | 17 | end simple23. 18 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/stackframe00.mod: -------------------------------------------------------------------------------- 1 | module stackframe00; 2 | 3 | procedure f(p0 : boolean; p1 : integer; p2 : char; p3 : integer); 4 | begin 5 | end f; 6 | 7 | procedure g(p0 : integer; p1 : integer; p2 : integer; p3 : integer); 8 | begin 9 | end g; 10 | 11 | procedure foo(); 12 | var a,b,c : integer; 13 | begin 14 | end foo; 15 | 16 | procedure foo2(); 17 | var a,b,c,d : integer; 18 | begin 19 | end foo2; 20 | 21 | procedure foo3(); 22 | var a,b,c,d,e : integer; 23 | begin 24 | end foo3; 25 | 26 | procedure foo4(); 27 | var a,b,c,d,e,f : integer; 28 | begin 29 | end foo4; 30 | 31 | procedure foo5(); 32 | var a,b,c,d,e,f : boolean; 33 | begin 34 | end foo5; 35 | 36 | begin 37 | 38 | end stackframe00. 39 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test01.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test01 3 | // 4 | // simple computations with integers 5 | // 6 | // expected output: 710-3 (no newline) 7 | // 8 | 9 | module test01; 10 | 11 | var a : integer; 12 | b : integer; 13 | c : integer; 14 | 15 | begin 16 | a := 2; 17 | b := 5; 18 | 19 | c := a+b; 20 | WriteInt(c); 21 | 22 | c := a*b; 23 | WriteInt(c); 24 | 25 | c := -b+a; 26 | WriteInt(c) 27 | end test01. 28 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test02.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test02 3 | // 4 | // computations with integers arrays 5 | // also test alignment of global data 6 | // 7 | // expected output: 1987654321 (no newline) 8 | // 9 | 10 | module test02; 11 | 12 | var a : integer[10]; 13 | b : boolean; 14 | c : boolean[2]; 15 | i : integer; 16 | 17 | begin 18 | a[0] := 1; 19 | 20 | i := 1; 21 | while (i < 10) do 22 | a[i] := 10-i; 23 | i := i+1 24 | end; 25 | 26 | i := 0; 27 | while (i < 10) do 28 | WriteInt(a[i]); 29 | i := i+1 30 | end 31 | end test02. 32 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test03.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test03 3 | // 4 | // simple computations with booleans 5 | // 6 | // expected output: 010 (no newline) 7 | // 8 | 9 | module test03; 10 | 11 | var a : boolean; 12 | b : boolean; 13 | b1 : integer; 14 | c : boolean; 15 | 16 | begin 17 | a := true; 18 | b := false; 19 | 20 | c := a && b; 21 | if (c) then WriteInt(1) 22 | else WriteInt(0) 23 | end; 24 | 25 | c := a || b; 26 | if (c) then WriteInt(1) 27 | else WriteInt(0) 28 | end; 29 | 30 | c := !(a || b); 31 | if (c) then WriteInt(1) 32 | else WriteInt(0) 33 | end 34 | end test03. 35 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test04.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test04 3 | // 4 | // computations with boolean arrays 5 | // 6 | // expected output: 0001111111 (no newline) 7 | // 8 | // if you get an endless loop, make sure you store 9 | // booleans as 1-byte values. 10 | // 11 | 12 | module test04; 13 | 14 | var a : boolean[10]; 15 | i : integer; 16 | 17 | begin 18 | i := 0; 19 | while (i < 10) do 20 | a[i] := i > 2; 21 | i := i+1 22 | end; 23 | 24 | i := 0; 25 | while (i < 10) do 26 | if (a[i]) then WriteInt(1) 27 | else WriteInt(0) 28 | end; 29 | i := i+1 30 | end 31 | end test04. 32 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test05.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test05 3 | // 4 | // computations with integers arrays 5 | // 6 | // expected output: 1987654321 (no newline) 7 | // 8 | 9 | module test05; 10 | 11 | var a : integer[10]; 12 | 13 | procedure test(a: integer[]); 14 | var i: integer; 15 | begin 16 | a[0] := 1; 17 | 18 | i := 1; 19 | while (i < 10) do 20 | a[i] := 10-i; 21 | i := i+1 22 | end; 23 | 24 | i := 0; 25 | while (i < 10) do 26 | WriteInt(a[i]); 27 | i := i+1 28 | end 29 | end test; 30 | 31 | begin 32 | test(a) 33 | end test05. 34 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test06.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test06 3 | // 4 | // computations with boolean arrays 5 | // 6 | // expected output: 0001111111 (no newline) 7 | // 8 | 9 | module test06; 10 | 11 | var a : boolean[10]; 12 | 13 | procedure test(a: boolean[]); 14 | var i: integer; 15 | begin 16 | i := 0; 17 | while (i < 10) do 18 | a[i] := i > 2; 19 | i := i+1 20 | end; 21 | 22 | i := 0; 23 | while (i < 10) do 24 | if (a[i]) then WriteInt(1) 25 | else WriteInt(0) 26 | end; 27 | i := i+1 28 | end 29 | end test; 30 | 31 | begin 32 | test(a) 33 | end test06. 34 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test07.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test07 3 | // 4 | // strings 5 | // 6 | // expected output: "Hello, world!" 7 | // 8 | 9 | module test07; 10 | 11 | begin 12 | WriteStr("Hello, world!"); WriteLn() 13 | end test07. 14 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test08.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test08 3 | // 4 | // local integer arrays 5 | // 6 | // expected output: 1987654321 (no newline) 7 | // 8 | 9 | module test08; 10 | 11 | procedure test(); 12 | var a : integer[10]; 13 | i: integer; 14 | begin 15 | a[0] := 1; 16 | 17 | i := 1; 18 | while (i < 10) do 19 | a[i] := 10-i; 20 | i := i+1 21 | end; 22 | 23 | i := 0; 24 | while (i < 10) do 25 | WriteInt(a[i]); 26 | i := i+1 27 | end 28 | end test; 29 | 30 | begin 31 | test() 32 | end test08. 33 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test09.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test09 3 | // 4 | // local boolean arrays 5 | // 6 | // expected output: 0001111111 (no newline) 7 | // 8 | 9 | module test09; 10 | 11 | procedure test(); 12 | var a : boolean[10]; 13 | i: integer; 14 | begin 15 | i := 0; 16 | while (i < 10) do 17 | a[i] := i > 2; 18 | i := i+1 19 | end; 20 | 21 | i := 0; 22 | while (i < 10) do 23 | if (a[i]) then WriteInt(1) 24 | else WriteInt(0) 25 | end; 26 | i := i+1 27 | end 28 | end test; 29 | 30 | begin 31 | test() 32 | end test09. 33 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test10.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test10 3 | // 4 | // sum of natural numbers 5 | // 6 | 7 | module test10; 8 | 9 | var i : integer; 10 | 11 | // sum(n): integer 12 | // 13 | // sum of values 0...n 14 | // recursive version 15 | function sum_rec(n: integer): integer; 16 | begin 17 | if (n > 0) then 18 | return n + sum_rec(n-1) 19 | else 20 | return 0 21 | end 22 | end sum_rec; 23 | 24 | // sum(n): integer 25 | // 26 | // sum of values 0...n 27 | // iterative version 28 | function sum_iter(n: integer): integer; 29 | var sum, i: integer; 30 | begin 31 | sum := 0; 32 | i := 0; 33 | while (i <= n) do 34 | sum := sum + i; 35 | i := i+1 36 | end; 37 | return sum 38 | end sum_iter; 39 | 40 | // sum(n): integer 41 | // 42 | // sum of values 0...n 43 | // algorithmic version 44 | function sum_alg(n: integer): integer; 45 | begin 46 | return n * (n+1) / 2 47 | end sum_alg; 48 | 49 | function ReadNumber(str: char[]): integer; 50 | var i: integer; 51 | begin 52 | WriteStr(str); 53 | i := ReadInt(); 54 | return i 55 | end ReadNumber; 56 | 57 | begin 58 | WriteStr("Sum of natural numbers\n\n"); 59 | 60 | i := ReadNumber("Enter a number (0 to exit): "); 61 | 62 | while (i > 0) do 63 | WriteStr(" recursive : "); WriteInt(sum_rec(i)); WriteLn(); 64 | WriteStr(" iterative : "); WriteInt(sum_iter(i)); WriteLn(); 65 | WriteStr(" algorithmic : "); WriteInt(sum_alg(i)); WriteLn(); 66 | 67 | i := ReadNumber("Enter a number (0 to exit): ") 68 | end 69 | end test10. 70 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test11.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test11 3 | // 4 | // variable alignment 5 | // 6 | // expected output: all variables aligned without superfluous 7 | // padding, both on the stack and in the global data section. 8 | // 9 | 10 | module test11; 11 | 12 | var A: integer; 13 | B: boolean; 14 | C: integer; 15 | D: char; 16 | E: integer; 17 | F: boolean; 18 | G: integer[10]; 19 | H: boolean; 20 | I: char[7]; 21 | J: integer; 22 | 23 | procedure foo(); 24 | var a: integer; 25 | b: boolean; 26 | c: integer; 27 | d: char; 28 | e: integer; 29 | f: boolean; 30 | g: integer[10]; 31 | h: boolean; 32 | i: char[7]; 33 | j: integer; 34 | begin 35 | end foo; 36 | 37 | 38 | begin 39 | end test11. 40 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test4_2.mod: -------------------------------------------------------------------------------- 1 | module test4_2; 2 | 3 | var i : integer; 4 | 5 | begin 6 | 7 | while (i < 3) do 8 | i := i; 9 | while (i < 4) do 10 | i := i - 1 11 | end 12 | end 13 | 14 | end test4_2. 15 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test7_2.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test7_2 3 | // 4 | // IR generation 5 | // 6 | 7 | module test7_2; 8 | 9 | var i: integer; 10 | 11 | begin 12 | if (i < 3) then 13 | i := 0; 14 | if (i > 9) then 15 | i := 987654321 16 | else 17 | i := 123456789; 18 | if (i > 11) then 19 | i := 1029384756 20 | else 21 | i := 0192837465 22 | end 23 | end; 24 | i := 0 25 | end 26 | end test7_2. 27 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test7_3.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test7 3 | // 4 | // IR generation 5 | // 6 | 7 | module test7_3; 8 | 9 | var i: integer; 10 | 11 | begin 12 | if ((i < 3) && (i > 0)) then 13 | i := 0; 14 | if ((i > 9) || (i > 7)) then 15 | i := 987654321 16 | else 17 | i := -i; 18 | if (((i > 1111) && (i < 9999)) || (i = 5000)) then 19 | i := 1029384756 20 | else 21 | i := -i + 1 22 | end 23 | end; 24 | i := 0 25 | end 26 | end test7_3. 27 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test8_2.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test8_2 3 | // 4 | // IR generation 5 | // 6 | 7 | module test8_2; 8 | 9 | var i: integer; 10 | b: boolean; 11 | 12 | begin 13 | b := (1 < 3); 14 | b := (1 < 3); 15 | b := (1 < 3); 16 | // if (b) then 17 | // i := 0 18 | // end 19 | return 20 | end test8_2. 21 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test8_3.mod: -------------------------------------------------------------------------------- 1 | // 2 | // test8 3 | // 4 | // IR generation 5 | // 6 | 7 | module test8; 8 | 9 | var i: integer; 10 | b: boolean; 11 | 12 | begin 13 | b := (i < 3); 14 | if (!b) then 15 | i := 0 16 | end 17 | end test8. 18 | -------------------------------------------------------------------------------- /5.Code.Generation/test/codegen/test8_4.mod: -------------------------------------------------------------------------------- 1 | module test8_4; 2 | 3 | procedure f(b : boolean); 4 | begin 5 | 6 | end f; 7 | 8 | begin 9 | f(true = false); 10 | f(true = false); 11 | f(true = false); 12 | f(true); 13 | return 14 | end test8_4. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Eggompilers 2 | ![](https://github.com/cseteram/Eggompilers/blob/images/images/KakaoTalk_20160107_214203206.png) 3 | 4 | ## We are suffering from SNUPL/1 Compilers!!! 5 | > Worked by [cseteram](https://github.com/cseteram), [kalaluthien](https://github.com/kalaluthien) in Compilers(4190.409-001, 2016 spring) of SNU. 6 | 7 | ![](http://www.snu.ac.kr/webdata/boards/enmedia/65da03fbe822bf23d07dbf313349e4cd.jpg) 8 | ![](http://img.ichannela.com/IMAGE/M16/2014/02/02/60529415.2-60529414.2.jpg?rev=1) 9 | -------------------------------------------------------------------------------- /vim_syntax/mod.vim: -------------------------------------------------------------------------------- 1 | " vim syntax file 2 | " for SnuPL/1 language 3 | 4 | if exists ("b:current_syntax") 5 | finish 6 | endif 7 | 8 | syn keyword snuDeclare module procedure function 9 | syn keyword snuKeyword var return begin end 10 | syn keyword snuCond if then else 11 | syn keyword snuLoop while do 12 | 13 | syn keyword snuType integer boolean char 14 | syn keyword snuBool true false 15 | syn keyword snuTodo TODO FIXME NOTE contained 16 | 17 | syn match snuParenError ")" 18 | syn match snuBrakError "\]" 19 | 20 | syn match snuNumber "\<\d\+" 21 | syn match snuString "\".*\"" contains=snuEscape 22 | syn match snuCharacter "\('.'\|'\\.'\)" contains=snuEscape 23 | syn match snuEscape "\\." contained 24 | syn match snuOperator "\(:\|<\|>\)=" 25 | syn match snuOperator "&&\|||" 26 | syn match snuOperator "[+\-=*/!<>=#.;]" 27 | syn match snuComment "//.*$" contains=snuTodo 28 | 29 | syn cluster snuContained contains=snuEscape,snuTodo 30 | 31 | syn region snuParenRegion transparent matchgroup=snuBrace start="(" matchgroup=snuBrace end=")" contains=ALLBUT,@snuContained,snuParenError 32 | syn region snuBrakRegion transparent matchgroup=snuBrace start="\[" matchgroup=snuBrace end="\]" contains=ALLBUT,@snuContained,snuBrakError 33 | 34 | 35 | hi link snuDeclare PreProc 36 | hi link snuKeyword Keyword 37 | hi link snuCond Keyword 38 | hi link snuLoop Keyword 39 | 40 | hi link snuType Type 41 | hi link snuBool Boolean 42 | hi link snuTodo Todo 43 | 44 | hi link snuParenError Error 45 | hi link snuBrakError Error 46 | 47 | hi link snuNumber String 48 | hi link snuString String 49 | hi link snuCharacter String 50 | hi link snuEscape Delimiter 51 | hi link snuOperator Keyword 52 | hi link snuComment Comment 53 | 54 | hi link snuBrace Keyword 55 | 56 | 57 | let b:current_syntax="mod" 58 | --------------------------------------------------------------------------------