Commit db5aea40 authored by Luke  Thorpe's avatar Luke Thorpe
Browse files

Corrected answer to 'Gap 11'

parent 638c70d4
No preview for this file type
......@@ -291,7 +291,7 @@ For example, in an \lit*{if} statement where we want to have an empty \lit*{else
A variable declaration statement creates a new program variable in the current scope setting its static type and initial value.
The statement must be given a valid WACC type \synt{type}, a variable name \synt{ident} and an initial assignment value \synt{assign-rhs}.
\hl{Variable names must consist of one or more characters, whereby each character is either alphanumeric or an underscore (with the exception of the first character, which cannot be a digit). However, it is crucial that variable names do not clash with any keywords in the language. For example:} \lit{return} \hl{is an acceptable identifier by the definition provided above, yet using it as such would cause a syntax error, since it already has some designated functionality within the language. More generally, a keyword can be any literal used as part of the program constructs defined in section 2.1. Notably, they include (but are not limited to):}
\hl{Variable names must consist of one or more characters, whereby each character is either alphanumeric or an underscore (with the exception of the first character, which cannot be a digit). However, it is crucial that variable names do not clash with any keywords in the language. For example:} \lit{\hl{return}} \hl{is an acceptable identifier by the definition provided above, yet using it as such would cause a syntax error, since it already has some designated functionality within the language. More generally, a keyword can be any literal used as part of the program constructs defined in section 2.1. Notably, they include (but are not limited to):}
\begin{itemize}
\item Statement delimiters, such as \lit{begin}, \lit{is}, \lit{skip}, \lit{while} or \lit{do}.
\item \lit{newpair} and \lit{call}.
......@@ -369,7 +369,7 @@ The type of the expression given to the return statement must match the return t
Once the return statement is executed, the function is immediately exited.
\paragraph{Exit Statements:}
\hl{An exit statement }\lit{exit}\hl{ is used terminate the execution of the running program with a particular exit code. The statement is given an expression that must evaluate to a value with type }\lit{int}\hl{ (with 0 and 1 typically denoting success and failure respectively).}
\hl{An exit statement }\lit{\hl{exit}}\hl{ is used terminate the execution of the running program with a particular exit code. The statement is given an expression that must evaluate to a value with type }\lit{\hl{int}}\hl{ (with 0 and 1 typically denoting success and failure respectively).}
\hl{Upon encountering an exit statement, a program will terminate immediately after the given expression has been successfully evaluated; any code thereafter will be ignored. }
\fillgap{\hl{define exit statements}}{2 marks}
......@@ -430,7 +430,7 @@ Each of the program branches is executed in its own scope, which are denoted by
A scoping statement introduces a new program scope, which is denoted by the \lit{begin} and \lit{end} tokens.
\paragraph{Sequential Composition:}
\hl{A sequential composition statement }\lit{\hl{;}}\hl{ (infix) is used to concatenate two statements together such that the second executes after the first. For example, we can compose the statements }\lit{\hl{s1}}\hl{ and }\lit{\hl{s2}}\hl{ by writing }\lit{\hl{s1 ; s2}}\hl{. It should be noted that neither }\lit{\hl{s1}}\hl{ nor }\lit{\hl{s2}}\hl{ need necesarily be singleton statements; they can themselves be the result of composition; it is this repeated process of composition that enables the generation of arbitrarily long sequences of statements. }
\hl{A sequential composition statement }\lit{\hl{;}}\hl{ (infix) is used to concatenate two statements together such that the second executes after the first. For example, we can compose the statements }\lit{\hl{s$_1$}}\hl{ and }\lit{\hl{s$_2$}}\hl{ by writing }\lit{\hl{s$_1$ ; s$_2$}}\hl{. It should be noted that neither }\lit{\hl{s$_1$}}\hl{ nor }\lit{\hl{s$_2$}}\hl{ need necesarily be singleton statements; they can themselves be the result of composition; it is this repeated process of composition that enables the generation of arbitrarily long sequences of statements. }
\fillgap{\hl{Define/describe sequential composition} \\ \hl{i.e. }\lit*{\hl{<stat> ; <stat>}} }{2 marks}
\subsection{Expressions}
......@@ -579,10 +579,8 @@ with 1 being the highest and 6 being the lowest.
& \lit*{\hl{bool}} & Less Than \\
\lit{<=} & 3 & \lit*{\hl{char}} / \lit*{\hl{int}} & \lit*{\hl{char}} / \lit*{\hl{int}}
& \lit*{\hl{bool}} & Less Than or Equal \\
\lit{==} & 4 & \lit*{\hl{char}} / \lit*{\hl{int}} / \lit*{\hl{bool}} / \lit*{\hl{pair}}
& \lit*{\hl{char}} / \lit*{\hl{int}} / \lit*{\hl{bool}} / \lit*{\hl{pair}} & \lit*{\hl{bool}} & Equality \\
\lit{!=} & 4 & \lit*{\hl{char}} / \lit*{\hl{int}} / \lit*{\hl{bool}} / \lit*{\hl{pair}}
& \lit*{\hl{char}} / \lit*{\hl{int}} / \lit*{\hl{bool}} / \lit*{\hl{pair}} & \lit*{\hl{bool}} & Inequality \\
\lit{==} & 4 & \lit*{\hl{T$_1$}} & \lit*{\hl{T$_1$}} & \lit*{\hl{bool}} & Equality \\
\lit{!=} & 4 & \lit*{\hl{T$_2$}} & \lit*{\hl{T$_2$}} & \lit*{\hl{bool}} & Inequality \\
\lit{\&\&} & 5 & \lit*{bool} & \lit*{bool} & \lit*{bool} & Logical And \\
\lit{||} & 6 & \lit*{bool} & \lit*{bool} & \lit*{bool} & Logical Or \\
\hline
......
# evaluating string equality
# Output:
# true
# false
# false
# Program:
begin
int[] a1 = [ 1, 2, 3, 4 ] ;
int[] a2 = [ 1, 2, 3, 4 ] ;
int[] a3 = [ 2, 3, 5, 7 ] ;
println a1 == a2 ;
println a2 == a3
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment