CISC 672 – Advanced Compiler ConstructionTimo K¨otzingSeptember 9, 2008DisclaimerThe following does not describe the cool-language in depth. It isnot designed to be used as a syntax reference, but rather as anintroduction into programming with cool, and also into objectoriented programming in general.For the purpose of writing your own cool-compiler, please read thecool-manual carefully.Timo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Program?Ia cool-program is a list of cool-classesIclasses may be spread over several filesIone of the classes has to be named “Main”Ithis class has to contain a method named “main”Iexecuting a cool-program is equivalent to evaluating this“Main.main()” functionTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Program?Ia cool-program is a list of cool-classesIclasses may be spread over several filesIone of the classes has to be named “Main”Ithis class has to contain a method named “main”Iexecuting a cool-program is equivalent to evaluating this“Main.main()” functionTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Program?Ia cool-program is a list of cool-classesIclasses may be spread over several filesIone of the classes has to be named “Main”Ithis class has to contain a method named “main”Iexecuting a cool-program is equivalent to evaluating this“Main.main()” functionTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Program?Ia cool-program is a list of cool-classesIclasses may be spread over several filesIone of the classes has to be named “Main”Ithis class has to contain a method named “main”Iexecuting a cool-program is equivalent to evaluating this“Main.main()” functionTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Program?Ia cool-program is a list of cool-classesIclasses may be spread over several filesIone of the classes has to be named “Main”Ithis class has to contain a method named “main”Iexecuting a cool-program is equivalent to evaluating this“Main.main()” functionTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Program?Ia cool-program is a list of cool-classesIclasses may be spread over several filesIone of the classes has to be named “Main”Ithis class has to contain a method named “main”Iexecuting a cool-program is equivalent to evaluating this“Main.main()” functionTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat is a COOL-Class?Ia cool-class is a list of featuresIfeatures are either attributes or methodsIattributes are local variables (with scope of the class)Imethods are global functions, addressed by“< functionName > . < methodName > (...)”Iattributes have to have a type and may be initializedImethods have a (possibly empty) list of formal parameters, areturn type and a bodyTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat are Types in COOL?Ievery class is a typeIthe basic types are the classes “Object”, “IO”, “Int”, “String”and “Bool”Iall classes but Object have to be inherited from exactly oneother class (be a child of this class)Ievery class that does not specify a class to inherit from isinherited from ObjectIthe “is child of”-relation has to be a tree, rooted at ObjectIbasic classes provide several basic functionsI“Int”, “String” and “Bool” may not be inherited fromTimo K¨otzing CISC 672 – Advanced Compiler ConstructionWhat are Types in COOL?Ievery class is a typeIthe basic types are the classes “Object”, “IO”, “Int”, “String”and “Bool”Iall classes but Object have to be inherited from exactly oneother class (be a child of this class)Ievery class that does not specify a class to inherit from isinherited from ObjectIthe “is child of”-relation has to
View Full Document