next up previous
Next: Built-in domains Up: Language extensions Previous: Language extensions

Arrays

The ALDOR solution is very elegant. It is based on the following features Of course, we do not plan to implement such features in ALLCOT. But we would like to create arrays of any type in any scope of the source program. However, in order to make such arrays easy to translate into our intermediate language, we can restrict to fixed size arrays. For declaring a variable of an array type, let us modify the Type-rules as follows.
Type $ \longmapsto$ %
Type $ \longmapsto$ id
Type $ \longmapsto$ Array ( id , ArithmeticExpression )
where, in the third rule, id is meant to be a type and ArithmeticExpression is meant to be a positive integer. For initializing an array, we need to add a special form of RightValue, such that the RightValue-rules become
RightValue $ \longmapsto$ FunctionCall
RightValue $ \longmapsto$ ArithmeticExpression
RightValue $ \longmapsto$ BooleanExpression
RightValue $ \longmapsto$ [ RightValueSequence ]
RightValueSequence $ \longmapsto$ RightValue
RightValueSequence $ \longmapsto$ RightValueSequence , RightValue
Then, we need to read and overwrite an element in an array, which means accessing an element in an array. This can be done exactly like in an AttributeCall. Therefore, the following program fragment becomes syntactically valid
x: Array(Integer, 3) := [2,3,6];
i: Integer := 2;
x.i := 5;
Observe that this solution for arrays is coherent for the philosophy of ALLCOT and ALDOR. In fact, the ALLCOT Array can be viewed as a built-in domain constructor.


next up previous
Next: Built-in domains Up: Language extensions Previous: Language extensions
Marc Moreno Maza
2004-12-01