Commit 3d71a34d authored by Richard Xiong's avatar Richard Xiong
Browse files

Completed variable declaration section

parent 02150954
No preview for this file type
...@@ -291,24 +291,24 @@ For example, in an \lit*{if} statement where we want to have an empty \lit*{else ...@@ -291,24 +291,24 @@ 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. 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}. The statement must be given a valid WACC type \synt{type}, a variable name \synt{ident} and an initial assignment value \synt{assign-rhs}.
Variable names must not clash with \hl{... ??? ...} Variable names must not clash with \hl{any of the base type, unary opener, pair type, pair element, assigment and statement keywords declared in section 2.1.}
They can consist \hl{... ??? ...} They can consist of \hl{a `_', `a'-`z' or `A'-`Z' character, followed by a sequence of alphanumeric characters or `_'.}
The initial assignment to a variable follows all of the assignment restrictions discussed in detail in the assignment statement section below. The initial assignment to a variable follows all of the assignment restrictions discussed in detail in the assignment statement section below.
A variable must be declared before \hl{... ??? ...} A variable must be declared before \hl{they can be accessed. TODO: Is this what they want?}
Any attempt to access an undeclared variable results in \hl{... ??? ...} Any attempt to access an undeclared variable results in \hl{a syntax error during compilation.}
Additionally, every use of a variable must match the type assigned to that variable when it was declared. Additionally, every use of a variable must match the type assigned to that variable when it was declared.
A variable can only be accessed within the scope of its declaration (or any child scope) and it is destroyed when exiting this scope. A variable can only be accessed within the scope of its declaration (or any child scope) and it is destroyed when exiting this scope.
Variables must be unique within their scope, so a variable cannot be redefined within the same scope. Variables must be unique within their scope, so a variable cannot be redefined within the same scope.
Variables can, however, be redefined within a child scope. Variables can, however, be redefined within a child scope.
In this case \hl{... ??? ...} In this case \hl{any references to the variable after its redefinition will refer to the new variable created in the child scope, instead of the previous variable definition in the parent scope.}
Once the child scope is exited \hl{... ??? ...} Once the child scope is exited \hl{the previous variable definition from the parent scope is restored.}
\fillgap{\hl{Complete the above paragraph}}{5 marks} \fillgap{\hl{Complete the above paragraph}}{5 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