![]() |
![]() |
![]() |
General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
![]() |
![]() |
Tutorial on Type AnalysisArray TypesWe now add arrays to our language in order to show how types are represented by freely chosen properties (in contrast to the scope property of record types). We only have to extend the grammar by notations for array type denoters and by indexed variables: The following concrete productions are added: Array.con[43]== TypeDenoter: ArrayType. ArrayType: TypeDenoter '[' IntNumber ']'. Variable: Variable '[' Expression ']'. This macro is attached to a product file. Here is an example program that uses arrays, records, and type definitions in combination: ArrayExamp[44]== begin var int k; var int[5] pi, int[5] pj; var record int i, bool b, real[3] r end [2] rv; type bool[4] bt; var bt vbt, bt wbt; var real[6][7] m; pi[1] = k; vbt = wbt; rv[2].b = true; rv[1].r[k] = 3.2; m[1][k] = 1.0; end This macro is attached to a product file. Here, an array type is represented by the type and the number of its elements: Array.pdl[45]== ElemType: DefTableKey [KReset]; ElemNo: int [KReset]; This macro is attached to a product file.
An With respect to equality of type the same considerations apply as were made above for record types.
The properties that characterize the array type are set in a
combined computation establishing the postcondition
ArrayType.lido[46]== SYMBOL ArrayType INHERITS TypeDenotation END; RULE: TypeDenoter ::= ArrayType COMPUTE TypeDenoter.Type = ArrayType.Type; END; TERM IntNumber: int; RULE: ArrayType ::= TypeDenoter '[' IntNumber ']' COMPUTE ArrayType.GotType = ResetElemType (KResetElemNo (KResetTypeName (ArrayType.Type, "array..."), IntNumber), TypeDenoter.Type); END; This macro is attached to a product file.
The type of an indexed variable is the element type of
the array variable. The function Array.lido[47]== RULE: Variable ::= Variable '[' Expression ']' COMPUTE Variable[1].Type = TransDefer (GetElemType (Variable[2].Type, NoKey)); Expression.ReqType = intType; IF (EQ (Variable[1].Type, NoKey), message (ERROR, "index applied to non array", 0, COORDREF)); END; This macro is attached to a product file.
|