-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
171 lines (158 loc) · 3.94 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Author : Owen min ([email protected])
Version : 0.6
Webpage : https://github.com/owenwater/compiler
Get the lastest version by:
git clone git://github.com/owenwater/compiler.git
Compile and Install:
make
Run my own test cases:
./run.sh
All my test cases are put in the directory "test"
For each test case, there are:
decafe source : test[i]
MIPS code : a[i].s
error msg : err[i]
all test result will be print to stdout except quicksort.decaf
since it's too big
the result will be same as ./test_result
Run other decafe source:
./decafcc [file-name]
the MIPS code will be put into [file-name].o
NEW Feature:
0) more freedom while declare variable.
0.0) declare variable with initialization with comma.
e.g.
int a = 4, b = 5;
0.1) declare local variable with initialization and
local array just like golbal variable
0.2) global variable and array now placed in heap.
0.3) variable can be initialized with expression.
0.4) declare the local variable everywhere.
But variable can only be used in the following line
of the declaration.
e.g.
int a;
a = 3;
int b = a + a; (vaild)
========================
int a = 4, b = a + a;(invaild)
int c = d + d, c = 5 (invaild)
1) more freedom with assignment.
1.0) enable assignment with operator, inlucding:
+= -= *= /= %= &= |= >>= <<= ^=
1.1) expression now can also be assignment.
it means the compiler now support something like:
a = b += c -= 3;
2) user comment, including /**/ and //
3) the statement now can also be expression, it will release the
register automatically for:
3.0) expression.
e.g.
3+4;
3.1) method call
int main(){ f();}
int f() {return 3;}
4) more operators support.
4.0) self increment and decrement with ++, --.
P.S. both ++a, a++ will increase a by one and return a+1
e.g.
a = 3;
b = a++; //a = 4, b = 4
=====
a = 3
b = ++a; //a = 4, b = 4
and it is same with --.
4.1) unary sign operator + (only has - before)
e.g.
+a+3
4.2) get address of function, variable or array with &
e.g.
int main
{
int a;
&a;
&f;
}
int f(){}
4.3) xor with operator: ^, also support ^=(1.0) .
5) new type of variable "fun". Used to record the address of function
6) transmit function address as parameter
e.g.
int main()
{
g(&f);
}
int g(fun a)
{
a()
}
int f()
{
}
see more details about how it work in:
./test/fun_pointer.decaf
7) reference
transmit variable's address and can modify the variable outside
the function.
e.g.
int main()
{
int a;
a = 3;
f(&a)
callout("print_int", a);
}
int f(&a)
{
a = 4;
}
This program will output 4.
see more details in ./test/test24
8) more wisdom output, see Current Feature 5)
Current Feature:
0) global variable and array global declare and initialize
1) all method declare, "void main" shall be first
2) block nested
3) local variable declare (in stack)
4) statements including:
4.0) assignment
4.1) if-then, if-then-else
4.2) while
4.3) for
4.4) break
4.5) continue
4.6) return
5) system method call including:
5.0) print_int
5.1) print_str
print_int and print str accept several argument,
separate by space and end with newline character.
Just like print in Python
e.g.
"callout("print_int", 2,3,4);"
will output:
2 3 4
and a '\n'
5.2) read_int
6) expression including:
6.0) left value (an id or one slot of an array)
6.1) method call
6.3) plus, minus, multiply, div, mod, negate,
and, or, not, leftshift, rightshift,
less, less or equal, larger, larger or equal
equal, not equal
6.4) paren
except:
6.a) rot
7) constant including:
7.0) int
7.0) bool
7.0) char
7.0) string
8) user method call and return
8.0) parameter transmit
8.1) recursive
TODO List:
1) rot(6.a)
2) type check
3) "void main" function check