due: Friday, February 25, in class
NodeVisitor
and adding one method to the Node
class that is the superclass
of all AST node classes.
A ` id : T : T1 |
A + {id : T}` (S2; ...; Sn) : Tn |
|
A ` (id : T; S2; ...; Sn) : Tn |
Environments are constructed in the static semantics by an binary operation A + A' that is undefined if the second environment (A') duplicates any entries from the first (A). Why is this? Give an example of some code that is not allowed by the given semantics, but would be if the second environment overrode the first.
Suppose we extended the static semantics with the following rule:
A ` E : none |
|
A ` E : T |
Give an example of an expression or statement that is well-typed using the extended semantics but is not under the given semantics, and draw its proof tree. Is this static semantics sound -- that is, can this example result in a run-time type error? Argue briefly.
x:(int, bool, string)
creates a variable
x
containing a 3-tuple. The elements of a tuple are immutable and cannot be changed, although
x
could be assigned to an entirely new value of this tuple type. The individual elements of the tuple can be accessed in a manner similar to array elements. For example, thex[0]
has type int
, x[1]
has type
bool
, and x[2]
has type string
.
Tuples are unlike arrays in that the index expression
must be a constant, and the elements cannot be assigned to.x[n]
.a[0] + a[1]
: int