- All Implemented Interfaces:
Externalizable
,Serializable
Simula Standard: 5.2 Array declaration array-declaration = [ type ] ARRAY array-segment { , array-segment } array-segment = array-identifier { , array-identifier } "(" bound-pair-list ")" array-identifier = identifier bound-pair-list = bound-pair { , bound-pair } bound-pair = arithmetic-expression : arithmetic-expressionAn array declaration declares one or several identifiers to represent multi-dimensional arrays of subscripted variables and gives the dimensions of the arrays, the bounds of the subscripts, and the type of the variables.
The subscript bounds for any array are given in the first subscript brackets following the identifier of this array in the form of a bound pair list. Each bound pair gives the lower bound of a subscript followed by : followed by the upper bound. The bound pair list gives the bounds of all subscripts taken in order from left to right.
NOTE: An initial "-" in upper bound may follow : directly (cf. 1.3). The scanner will treat ":-" within parentheses (round brackets) as two separate symbols ":" and "-" thus solving this ambiguity in the syntax.
The dimension is given as the number of entries in the bound pair lists.
All arrays declared in one declaration are of the same quoted type. If no type declarator is given the type real is understood.
The expressions are evaluated in the same way as subscript expressions. This evaluation takes place once at each entrance into the block through the block head. The expressions cannot include any identifier that is declared, either explicitly or implicitly, in the same block head as the array in question.
An array has elements only when the values of all upper bounds are not smaller than those of the corresponding lower bounds. If any lower bound value is greater than the corresponding upper bound value, the array has no elements. An attempt to access an element of an empty array leads to a run-time error. The array may, however, be created at block entry and it may be passed as a parameter.
The value of an array identifier is the ordered set of values of the corresponding array of subscripted variables.
Examples integer array a(2:20) ! 19 elements; real array q(-7:if c < 0 then 2 else 1) ! 10 or 9 elements; array a,b,c(7:n,2:m), s(-2:10) ! any value of n or m legal;Link to GitHub: Source File.
- Author:
- SIMULA Standards Group, Øystein Myhre Andersen
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
Utility Class to hold a BoundPair.Nested classes/interfaces inherited from class simula.compiler.syntaxClass.declaration.Declaration
Declaration.Kind
-
Field Summary
Modifier and TypeFieldDescriptionprivate Vector
<ArrayDeclaration.BoundPair> The list of BoundPair.int
Number of dimensions.Fields inherited from class simula.compiler.syntaxClass.declaration.Declaration
declarationKind, declaredIn, externalIdent, identifier, isProtected, type
Fields inherited from class simula.compiler.syntaxClass.SyntaxClass
lineNumber
-
Constructor Summary
ModifierConstructorDescriptionDefault constructor used by Externalization.private
ArrayDeclaration
(String identifier, Type type, Vector<ArrayDeclaration.BoundPair> boundPairList) Create a new ArrayDeclaration -
Method Summary
Modifier and TypeMethodDescriptionvoid
Perform semantic checking.void
Output possible declaration code.void
Output Java code.(package private) static void
expectArrayDeclaration
(Type type, DeclarationList declarationList) Parse an array declaration and add it to the given declaration list.void
printTree
(int indent) Utility print syntax tree method.void
readExternal
(ObjectInput inpt) toString()
void
writeExternal
(ObjectOutput oupt) Methods inherited from class simula.compiler.syntaxClass.declaration.Declaration
getJavaIdentifier, isCompatibleClasses, modifyIdentifier, parseDeclaration
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, print, SET_SEMANTICS_CHECKED, toJavaCode
-
Field Details
-
nDim
public int nDimNumber of dimensions. -
boundPairList
The list of BoundPair.
-
-
Constructor Details
-
ArrayDeclaration
private ArrayDeclaration(String identifier, Type type, Vector<ArrayDeclaration.BoundPair> boundPairList) Create a new ArrayDeclaration- Parameters:
identifier
- the array identifiertype
- the array typeboundPairList
- The list of BoundPair
-
ArrayDeclaration
public ArrayDeclaration()Default constructor used by Externalization.
-
-
Method Details
-
expectArrayDeclaration
Parse an array declaration and add it to the given declaration list.Syntax: ArrayDeclaration = [ Type ] ARRAY ArraySegment { , ArraySegment } ArraySegment = IdentifierList "(" BoundPairList ")" IdentifierList = Identifier { , Identifier } BoundPairList = BoundPair { , BoundPair } BoundPair = ArithmeticExpression : ArithmeticExpression
Precondition: [ Type ] ARRAY is already read.- Parameters:
type
- the array's typedeclarationList
- the given declaration list
-
doChecking
public void doChecking()Description copied from class:SyntaxClass
Perform semantic checking.This must be redefined in every subclass.
- Overrides:
doChecking
in classSyntaxClass
-
doJavaCoding
public void doJavaCoding()Description copied from class:SyntaxClass
Output Java code.- Overrides:
doJavaCoding
in classSyntaxClass
-
doDeclarationCoding
public void doDeclarationCoding()Description copied from class:SyntaxClass
Output possible declaration code.- Overrides:
doDeclarationCoding
in classSyntaxClass
-
printTree
public void printTree(int indent) Description copied from class:SyntaxClass
Utility print syntax tree method.- Overrides:
printTree
in classSyntaxClass
- Parameters:
indent
- number of spaces leading the lines
-
toString
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-