Skip to content

Commit

Permalink
updating
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtr1037 committed Feb 21, 2024
1 parent 2d55e33 commit 3be006d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Binary file modified exercises/ex3/ex3.pdf
Binary file not shown.
52 changes: 27 additions & 25 deletions exercises/ex3/ex3.tex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ \subsubsection{Classes}
%even if \verb"d" is defined \textit{after} \verb"M" in the class.
Table \ref{Table_Code_Examples_Use_Before_Def} summarizes these facts.
\begin{table}[h]
\caption{Referring to classes, methods and data members
\label{Table_Code_Examples_Use_Before_Def}}
\centering
\begin{tabular}{|l|l|l|}
\hline
Expand Down Expand Up @@ -149,15 +151,15 @@ \subsubsection{Classes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Referring to classes, methods and data members
\label{Table_Code_Examples_Use_Before_Def}}
\end{table}
\paragraph{Methods overloading} is \textit{illegal} in \plname,
with the obvious exception of overriding a method in a derived class.
Similarly, it is illegal to define a variable with the same name of
a previously defined variable (shadowing), or a previously defined method.
Table \ref{Table_Code_Examples_Overload_Override} summarizes these facts.
\begin{table}[h]
\caption{Method overloading and variable shadowing are both illegal in \plname.
\label{Table_Code_Examples_Overload_Override}}
\centering
\begin{tabular}{|l|l|l|}
\hline
Expand Down Expand Up @@ -222,14 +224,14 @@ \subsubsection{Classes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Method overloading and variable shadowing are both illegal in \plname.
\label{Table_Code_Examples_Overload_Override}}
\end{table}
\paragraph{Inheritance} if class \verb"Son" is derived from class \verb"Father",
then any place in the program that semantically allows an expression of type \verb"Father",
should semantically allow an expression of type \verb"Son".
For example,
For example, see Table~\ref{Table_Code_Examples_Son_Class_Instead_Of_Father_Class}.
\begin{table}[h]
\caption{Class Son is a semantically valid input for foo.
\label{Table_Code_Examples_Son_Class_Instead_Of_Father_Class}}
\centering
\begin{tabular}{ | l | l | }
\hline
Expand All @@ -241,14 +243,15 @@ \subsubsection{Classes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Class Son is a semantically valid input for foo.
\label{Table_Code_Examples_Son_Class_Instead_Of_Father_Class}}
\end{table}

\paragraph{Nil expressions} any place in the program that
semantically allows an expression of type class,
should semantically allow \verb"nil" instead.
For instance,
For example, see Table~\ref{Table_Code_Examples_nil_Instead_Of_Any_Class}.
\begin{table}[h]
\caption{nil sent instead of a (Father) class is semantically allowed.
\label{Table_Code_Examples_nil_Instead_Of_Any_Class}}
\centering
\begin{tabular}{ | l | l | }
\hline
Expand All @@ -259,16 +262,14 @@ \subsubsection{Classes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{nil sent instead of a (Father) class is semantically allowed.
\label{Table_Code_Examples_nil_Instead_Of_Any_Class}}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-SUB-SECTION :: Arrays %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Arrays}
\label{subsubsection_Arrays}
Arrays can only be defined in the uppermost (global) scope.
They are defined with respect to some previously defined type, as in the following example:
They are defined with respect to some previously defined type (that can't be the type \textit{void}), as in the following example:
\[
\verb"array IntArray = int[];"
\]
Expand All @@ -277,8 +278,11 @@ \subsubsection{Arrays}
\verb"array IntArray = int[]; array IntMat = IntArray[];"
\]
In addition, any place in the program that semantically allows an expression of type array,
should semantically allow \verb"nil" instead. For instance,
should semantically allow \verb"nil" instead.
For example, see Table~\ref{Table_Code_Examples_nil_Instead_Of_Any_Array}.
\begin{table}[h]
\caption{nil sent instead of an integer array is semantically allowed.
\label{Table_Code_Examples_nil_Instead_Of_Any_Array}}
\centering
\begin{tabular}{ | l | l | }
\hline
Expand All @@ -289,16 +293,16 @@ \subsubsection{Arrays}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{nil sent instead of an integer array is semantically allowed.
\label{Table_Code_Examples_nil_Instead_Of_Any_Array}}
\end{table}
\paragraph{Note} that allocating arrays with the new operator
must be done with an \textit{integral size} (if the size expression is \textbf{constant}, it must be greater than zero).
Similarly, accessing an array entry is semantically valid
only when the \textit{subscript expression has an integer type}.
Note further that if two arrays of type \verb"T" are defined,
they are \textit{not} interchangeable:
they are \textit{not} interchangeable (see Table~\ref{Table_Code_Examples_nil_Instead_Of_Any_Array}).
\begin{table}[h]
\caption{Non interchangeable array types.
\label{Table_Code_Examples_nil_Instead_Of_Any_Array}}
\centering
\begin{tabular}{ | l | l | }
\hline
Expand All @@ -315,8 +319,6 @@ \subsubsection{Arrays}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Non interchangeable array types.
\label{Table_Code_Examples_nil_Instead_Of_Any_Array}}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-SECTION :: Assignments %
Expand All @@ -338,6 +340,8 @@ \subsection{Assignments}
can be used, and even a simple expression like $5+6$ is forbidden.
Table \ref{Table_Code_Examples_Assignments} summarizes these facts.
\begin{table}[h]
\caption{Assignments.}
\label{Table_Code_Examples_Assignments}
\centering
\begin{tabular}{|l|l|l|}
\hline
Expand Down Expand Up @@ -397,8 +401,6 @@ \subsection{Assignments}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Assignments.
\label{Table_Code_Examples_Assignments}}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-SECTION :: If and While Statements %
Expand Down Expand Up @@ -443,6 +445,8 @@ \subsection{Equality Testing}
The resulting type of a semantically valid comparison is the primitive type int.
Table \ref{Table_Code_Examples_Equality_Testing} summarizes these facts.
\begin{table}[h]
\caption{Equality testing.}
\label{Table_Code_Examples_Equality_Testing}
\centering
\begin{tabular}{|l|l|l|}
\hline
Expand Down Expand Up @@ -480,8 +484,6 @@ \subsection{Equality Testing}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Equality testing.
\label{Table_Code_Examples_Equality_Testing}}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-SECTION :: Binary Operations %
Expand All @@ -495,6 +497,8 @@ \subsection{Binary Operations}
with the single exception of adding two strings, where the resulting type is a string.
Table \ref{Table_Code_Examples_Binary_Operations} summarizes these facts.
\begin{table}[h]
\caption{Binary Operations.}
\label{Table_Code_Examples_Binary_Operations}
\centering
\begin{tabular}{|l|l|l|}
\hline
Expand Down Expand Up @@ -531,8 +535,6 @@ \subsection{Binary Operations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Binary Operations.
\label{Table_Code_Examples_Binary_Operations}}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-SECTION :: Scope Rules %
Expand Down Expand Up @@ -584,6 +586,8 @@ \subsection{Library Functions}
\\
Library functions are treated as if they are defined in the global (main) scope.
\begin{table}[h]
\caption{Scope Rules.}
\label{Table_Code_Examples_Scope_Rules}
\centering
\begin{tabular}{|l|l|l|}
\hline
Expand Down Expand Up @@ -640,8 +644,6 @@ \subsection{Library Functions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\end{tabular}
\caption{Scope Rules.
\label{Table_Code_Examples_Scope_Rules}}
\end{table}

%%%%%%%%%%%%%%%%%%%%
Expand Down

0 comments on commit 3be006d

Please sign in to comment.