Cool (programming language)
Encyclopedia
Cool, an acronym for Classroom Object Oriented Language, is a computer
Computer
A computer is a programmable machine designed to sequentially and automatically carry out a sequence of arithmetic or logical operations. The particular sequence of operations can be changed readily, allowing the computer to solve more than one kind of problem...

 programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

 language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 designed by Alexander Aiken for use in an undergraduate compiler course project. While small enough for a one term project, Cool still has many of the features of modern programming languages, including objects, automatic memory management, strong static typing and simple reflection.

The reference Cool compiler is written in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, built fully on public domain tools. It generates code for a MIPS
MIPS architecture
MIPS is a reduced instruction set computer instruction set architecture developed by MIPS Technologies . The early MIPS architectures were 32-bit, and later versions were 64-bit...

 simulator, SPIM
SPIM
SPIM is a MIPS processor simulator, designed to run assembly language code for this architecture. The program simulates R2000 and R3000 processors, and was written by James R. Larus while a professor at the University of Wisconsin-Madison...

. Thus, the language should port easily to other platforms. It has been used for teaching compilers at many institutions (such as the University of California at Berkeley
University of California, Berkeley
The University of California, Berkeley , is a teaching and research university established in 1868 and located in Berkeley, California, USA...

, where it was first used) and the software is stable.

Other lecturers such as John Tang Boyland (author of the Sather
Sather
Sather is an object-oriented programming language. It originated circa 1990 at the International Computer Science Institute at the University of California, Berkeley, developed by an international team led by Steve Omohundro...

164 language, precursor of Cool) and Allan Jost have developed some dialects of Cool to be used in their own classes.

This language is unrelated to the COOL language included in CLIPS
CLIPS
CLIPS is a public domain software tool for building expert systems. The name is an acronym for "C Language Integrated Production System." The syntax and name was inspired by Charles Forgy's OPS...

.

Features

As the primary purpose of Cool is instruction, it lacks many of the features common to other, more general programming languages. For instance, the language supports less than comparisons but not greater than. The syntax is very much stripped down, and the "standard library" contains only a few basic classes. Separate compilation is not supported, though the compiler does support multiple source files as input. Every Cool program must define a class Main which must have a no-args constructor in which execution flow begins. Namespaces are not supported.

A simple Cool program for computing factorial follows:

class Main : IO is
Main begin
out_string("Enter an integer greater-than or equal-to 0: ");

let input: Integer := in_int; in
if input < 0 then
out_string("ERROR: Number must be greater-than or equal-to 0\n")
else
out_string("The factorial of ").out_int(input);
out_string(" is ").out_int(factorial(input))
fi
end
end;

factorial(num: Integer): Integer := if num = 0 then 1 else num + factorial(num - 1) fi;
end;


The syntax used in this sample comes out of Cool 2008, a dialect of Cool developed by John Tang Boyland. Other dialects of Cool may have markedly different syntax.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK