Skip to content

Latest commit

 

History

History
172 lines (171 loc) · 3.14 KB

README.md

File metadata and controls

172 lines (171 loc) · 3.14 KB

Compiler

testing sample:(path->test/homework_t)

a = 3;
b = 5;
if (a > b){
    t = a;
}
else{
   t = b;
}

testing method:

  1. After u done programming, type "make" in terminal to compile multiple ".C" files at the same time. This is what ya ganna get-> gcc -std=c99 -O0 lexer.c compiler.c main.c -o compiler
  2. Type "./compiler test/homework_test.c -ir -run" to demo ur code.

Result:

PS D:\國立金門大學資訊工程-課程\鍾誠老師課程\系統程式\110710544系統程式\student\sp108b\homework\05-compiler-run>
===================irRun()=======================
00: t1 = 0 (0)
01: s = t1 (0)
02: t1 = 1 (1)
03: i = t1 (1)
04: (L1) (4)
05: t2 = i (1)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (0)
10: t2 = i (1)
11: t3 = t1 + t2 (1)
12: s = t3 (1)
13: t1 = i (1)
14: t2 = 1 (1)
15: t3 = t1 + t2 (2)
16: i = t3 (2)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (2)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (1)
10: t2 = i (2)
11: t3 = t1 + t2 (3)
12: s = t3 (3)
13: t1 = i (2)
14: t2 = 1 (1)
15: t3 = t1 + t2 (3)
16: i = t3 (3)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (3)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (3)
10: t2 = i (3)
11: t3 = t1 + t2 (6)
12: s = t3 (6)
13: t1 = i (3)
14: t2 = 1 (1)
15: t3 = t1 + t2 (4)
16: i = t3 (4)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (4)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (6)
10: t2 = i (4)
11: t3 = t1 + t2 (10)
12: s = t3 (10)
13: t1 = i (4)
14: t2 = 1 (1)
15: t3 = t1 + t2 (5)
16: i = t3 (5)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (5)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (10)
10: t2 = i (5)
11: t3 = t1 + t2 (15)
12: s = t3 (15)
13: t1 = i (5)
14: t2 = 1 (1)
15: t3 = t1 + t2 (6)
16: i = t3 (6)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (6)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (15)
10: t2 = i (6)
11: t3 = t1 + t2 (21)
12: s = t3 (21)
13: t1 = i (6)
14: t2 = 1 (1)
15: t3 = t1 + t2 (7)
16: i = t3 (7)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (7)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (21)
10: t2 = i (7)
11: t3 = t1 + t2 (28)
12: s = t3 (28)
13: t1 = i (7)
14: t2 = 1 (1)
15: t3 = t1 + t2 (8)
16: i = t3 (8)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (8)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (28)
10: t2 = i (8)
11: t3 = t1 + t2 (36)
12: s = t3 (36)
13: t1 = i (8)
14: t2 = 1 (1)
15: t3 = t1 + t2 (9)
16: i = t3 (9)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (9)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (36)
10: t2 = i (9)
11: t3 = t1 + t2 (45)
12: s = t3 (45)
13: t1 = i (9)
14: t2 = 1 (1)
15: t3 = t1 + t2 (10)
16: i = t3 (10)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (10)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (1)
08: ifnot t4 (1)  -- fail
09: t1 = s (45)
10: t2 = i (10)
11: t3 = t1 + t2 (55)
12: s = t3 (55)
13: t1 = i (10)
14: t2 = 1 (1)
15: t3 = t1 + t2 (11)
16: i = t3 (11)
17: goto L1 (4)
04: (L1) (4)
05: t2 = i (11)
06: t3 = 10 (10)
07: t4 = t2 <= t3 (0)
08: ifnot t4 (0) goto L2 (18)
18: (L2) (18)