Skip to content

owenwater/compiler

Repository files navigation

Author  : Owen min (zmin@sfu.ca)
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





About

decafe with mips

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published