next up previous contents
Next: Class definitions Up: Operational Semantics Previous: Environment and the Store   Contents


Syntax for Cool Objects

Every Cool value is an object. Objects contain a list of named attributes, a bit like records in C. In addition, each object belongs to a class. We use the following syntax for values in Cool:

\begin{displaymath}
v = X(a_1=l_1,a_2=l_2,\ldots,a_n=l_n)
\end{displaymath}

Read the syntax as follows: The value $ v$ is a member of class $X$ containing the attributes $a_1, \ldots, a_n$ whose locations are $l_1, \ldots, l_n$. Note that the attributes have an associated location. Intuitively this means that there is some space in memory reserved for each attribute. The value $ v$ has dynamic type $X$.

For base objects of Cool (i.e., Ints, Strings, and Bools) we use a special case of the above syntax. Base objects have a class name, but their attributes are not like attributes of normal classes, because they cannot be modified. Therefore, we describe base objects using the following syntax:


\begin{displaymath}
\begin{array}{l}
Int(5)\\
Bool(true)\\
String(4,\mbox {\tt ''}Cool \mbox {\tt ''})
\end{array}\end{displaymath}

For Ints and Bools, the meaning is obvious. Strings contain two parts, the length and the actual sequence of ASCII characters.


next up previous contents
Next: Class definitions Up: Operational Semantics Previous: Environment and the Store   Contents