02-01
will be for teaching language cool compiler, the cool compiled into MIPS assembly language. Will be divided into five parts to explain, the first is to write a cool program, the program itself will be an interpreter. This is followed by lexical analysis, syntactic analysis, semantic analysis, and code generation. These parts are separated. That is, when we implement our own parsing, we embed our own completed parts into a reference compiler. There are already other parts in the reference compiler. This makes it easy to exclude errors independently of each part.
Some cool code examples to familiarize yourself with the cool language.
class main{ Main (): Int {1};};
class main{ <- new IO; Main (): Int {{i.out_string ("Hello world!\n"1;}}; };
class main{ <- new IO; Main (): IO {i.out_string ("Hello world!\n")}; };
class main{ <- new IO; Main (): Object {i.out_string ("Hello world!\n")}; };
class main{ Main (): Object {(new IO). Out_string ("Hello world!\n" ) }; };
class Main inherits IO { Main (): Object {self.out_string ("Hello world!\n" ) }; };
class Main inherits IO { Main (): Object {out_string ("Hello world!\n" ) }; };
Compiler method: Assume that the code name is 1.cl, the following two lines of code can be run.
11. s
After note: This point of things to see two hours ah, this is where the computer class, which is clearly foreign language class Ah, fell!
"Compiler" Stanford Open Class study 2