Commit 148068d7 authored by lh5918's avatar lh5918
Browse files

Made minor edits to several answers

parent 705d2d75
No preview for this file type
......@@ -365,7 +365,11 @@ 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{... ??? ...}
\hl{If in a function body, an exit statement must be at the very end, or a semantic error will be thrown.
In the main program, everything after the exit statement will not be processed.
The expression given to the exit statement must evaluate to an integer. Once the
exit statement is executed, the function/program is immediately exited with exit code
given by the integer that its sub-expression evaluates to.}
\fillgap{\hl{define exit statements}}{2 marks}
\paragraph{Print Statements:}
......@@ -452,7 +456,7 @@ A character literal \synt{char-liter} is a single ASCII character between two \l
A \lit{\char`\\} can be used to escape the character that immediately follows the \lit{\char`\\}.
The meaning of each escaped character is shown in Table~\ref{tab:escapedcharacters}.
\fillgap{\hl{Fill in Table}~\ref{tab:escapedcharacters}}{2 marks}
%
%TODO:highlight \b \t \n \f
\begin{table}
\centering
\begin{tabular}{cclc}
......@@ -460,10 +464,10 @@ The meaning of each escaped character is shown in Table~\ref{tab:escapedcharacte
Representation & ASCII Value & Description & Symbol \\
\hline
\lit*{\char`\\ 0} & \lit*{0x00} & null terminator & NUL \\
\\lit*{hl{\char`\\ b}} & \lit*{0x08} & \hl{backspace} & \hl{BS} \\
\\lit*{hl{\char`\\ t}} & \lit*{0x09} & \hl{horizontal tab} & \hl{HT}\ \\
\\lit*{hl{\char`\\ n}} & \lit*{0x0a} & \hl{line feed} & \hl{LF} \\
\\lit*{hl{\char`\\ f}} & \lit*{0x0c} & \hl{form feed} & \hl{FF} \\
\lit*{\char`\\ b} & \lit*{0x08} & \hl{backspace} & \hl{BS} \\
\lit*{\char`\\ t} & \lit*{0x09} & \hl{horizontal tab} & \hl{HT}\ \\
\lit*{\char`\\ n} & \lit*{0x0a} & \hl{line feed} & \hl{LF} \\
\lit*{\char`\\ f} & \lit*{0x0c} & \hl{form feed} & \hl{FF} \\
\lit*{\char`\\ r} & \hl{0x0d} & carriage return & CR \\
\lit*{\char`\\ "} & \hl{0x22} & double quote & " \\
\lit*{\char`\\ '} & \hl{0x27} & single quote & ' \\
......@@ -520,8 +524,8 @@ All unary operators have the same precedence, they are evaluated from right to l
\lit{!} & \lit*{bool} & \lit*{bool} & Logical Not \\
\lit{-} & \lit*{int} & \lit*{int} & Negation \\
\lit{len} & T\lit*{[]} & \lit*{int} & Array Length \\
\lit{ord} & \hl{???} & \hl{???} & \hl{???} \\
\lit{chr} & \hl{???} & \hl{???} & \hl{???} \\
\lit{ord} & \hl{char} & \hl{int} & \hl{ASCII value} \\
\lit{chr} & \hl{int} & \hl{char} & \hl{Character with corresponding ASCII value} \\
\hline
\end{tabulary}
\caption{The unary operators of the WACC language with their types and meanings.}
......@@ -536,9 +540,11 @@ returning \lit{true} if the sub-expression evaluates to \lit{false} and vice-ver
\item The \lit{len} operator returns the length of the array referenced by the evaluation of its sub-expression.
\item The \lit{ord} operator \hl{... ??? ...} \fillgap{\hl{Define/describe the }\lit{\hl{ord}} \hl{operator}}{1 mark}
\item The \lit{ord} operator \hl{returns the ASCII value of the} \lit*{\hl{char}} \hl{referenced by the evaluation
of its sub-expression.} \fillgap{\hl{Define/describe the }\lit{\hl{ord}} \hl{operator}}{1 mark}
\item The \lit{chr} operator \hl{... ??? ...} \fillgap{\hl{Define/describe the }\lit{\hl{chr}} \hl{operator}}{1 mark}
\item The \lit{chr} operator {\hl{returns the} \lit*{\hl{char}} \hl{with ASCII value that of the integer referenced
by the evaluation of its sub-expression.}} \fillgap{\hl{Define/describe the }\lit{\hl{chr}} \hl{operator}}{1 mark}
\end{itemize}
......@@ -560,12 +566,12 @@ with 1 being the highest and 6 being the lowest.
\lit{\%} & 1 & \lit*{int} & \lit*{int} & \lit*{int} & Modulus \\
\lit{+} & 2 & \lit*{int} & \lit*{int} & \lit*{int} & Plus \\
\lit{-} & 2 & \lit*{int} & \lit*{int} & \lit*{int} & Minus \\
\lit{>} & 3 & \hl{???} & \hl{???} & \hl{???} & Greater Than \\
\lit{>=} & 3 & \hl{???} & \hl{???} & \hl{???} & Greater Than or Equal \\
\lit{<} & 3 & \hl{???} & \hl{???} & \hl{???} & Less Than \\
\lit{<=} & 3 & \hl{???} & \hl{???} & \hl{???} & Less Than or Equal \\
\lit{==} & 4 & \hl{???} & \hl{???} & \hl{???} & Equality \\
\lit{!=} & 4 & \hl{???} & \hl{???} & \hl{???} & Inequality \\
\lit{>} & 3 & \hl{???} & \hl{???} & \lit*{\hl{bool}} & Greater Than \\
\lit{>=} & 3 & \hl{???} & \hl{???} & \lit*{\hl{bool}} & Greater Than or Equal \\
\lit{<} & 3 & \hl{???} & \hl{???} & \lit*{\hl{bool}} & Less Than \\
\lit{<=} & 3 & \hl{???} & \hl{???} & \lit*{\hl{bool}} & Less Than or Equal \\
\lit{==} & 4 & \hl{???} & \hl{???} & \lit*{\hl{bool}} & Equality \\
\lit{!=} & 4 & \hl{???} & \hl{???} & \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
......@@ -615,7 +621,11 @@ Any other type of occurrence of whitespace is ignored by the compiler.
Note, in particular, that the code indentation in the example programs has no meaning, it simply aids readability.
Also note that whitespace inside a string or character literal is preserved by the compiler.
\hl{... ??? ...}
\hl{Comments are denote by the} \lit*{\lit{\hl{\#}}} \hl{character which must be on the same line.
A comment must be preceded by the hashtag. For example,} \lit*{\lit{\hl{\#this is a comment}}} \hl{is a valid comment, but}
\\*\lit*{\lit{\hl{this is treated as program statement \#comment}}} \hl{will throw a syntax error, with only `comment'
evaluated as a comment. Comments can be written above or below program statements, in-line, or after the} \lit*{\hl{;}}
\hl{character as well.}
\fillgap{\hl{Define/describe comments}}{3 marks}
......
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