In the class we considered a type-system for a simple language that had only one type. We extended this type system with a subrange type and considered how and when we could assign between subranges and integers. In this assignment we will consider adding one-dimentional arrays to the type system.
Examples of variables of array types are:
a: array 0..10 of int;
b: array 0..100 of 0..10;
Note that in the declaration of an array, the index type is a subrange type. More specifically array "a" has 11 elements, that can be accessed as a[0]...a[10]. The element type of an array may be a subrange type or an integer type.
Give the subtype rule(s) for arrays whose element types are integers (i.e., not subranges). What run-time and compile-time checks are needed to enforce your rule(s)? Briefly describe the motivation for your rule(s).
Give the subtype rule(s) for arrays whose element types may be integers or subrange types. What run-time and compile-time checks are needed to enforce the rule(s)? Briefly describe the motivation for your rule(s).
Note that there is no single correct answer to these question; I’m looking for well-reasoned thoughtful responses.
Exercise 2.5.1, page 31 in text. Support your answer by quoting the appropriate sentences from the C++ and Java language definitions (available in the interesting links section of the web page).