Class ArrayDeclaration
Array Declaration.
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-expression
An 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Utility Class to hold a BoundPair. -
Field Summary
FieldsModifier 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
CHECKED, lineNumber, OBJECT_SEQU
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor used by Attribute File I/Oprivate
ArrayDeclaration
(String identifier, Type type, Vector<ArrayDeclaration.BoundPair> boundPairList) Create a new ArrayDeclaration -
Method Summary
Modifier and TypeMethodDescriptionvoid
arrayGetElement
(VariableExpression var, boolean isParameter, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_getELEMENT.static void
arrayGetElement
(Type type, String arrayIdent, boolean isParameter, Vector<Expression> checkedParams, Meaning meaning, DeclarationScope declaredIn, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_getELEMENT.static void
arrayGetElement2
(Type type, String arrayIdent, Vector<Expression> checkedParams, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_getELEMENT.void
arrayPutElement
(VariableExpression var, boolean isParameter, Expression rhs, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_putELEMENT.static void
arrayPutElement
(Meaning meaning, String arrayIdent, boolean isParameter, Vector<Expression> checkedParams, Expression rhs, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_putELEMENT.static void
arrayPutElement2
(Meaning meaning, Vector<Expression> checkedParams, Expression rhs, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_putELEMENT.void
buildDeclaration
(ClassBuilder classBuilder, BlockDeclaration encloser) Output Java ByteCode.void
buildDeclarationCode
(CodeBuilder codeBuilder) Output Java ByteCode.private static void
buildGetArrayField
(Type type, Meaning meaning, DeclarationScope declaredIn, String arrayIdent, boolean isParameter, CodeBuilder codeBuilder) ClassFile coding utility: Build 'Get Array Field'void
buildInitAttribute
(CodeBuilder codeBuilder) Output Java ByteCode.void
Perform semantic checking.void
Output possible declaration Java 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.static ClassDesc
getClassDesc
(Type type) Get the ClassDescr.ClassFile coding utility: get getFieldIdentifier.private static void
prepIndexing
(Vector<Expression> checkedParams, CodeBuilder codeBuilder) ClassFile coding utility: Prepare for indexing.void
Utility print syntax tree method.static ArrayDeclaration
Read and return an ArrayDeclaration object.toString()
void
Write a SyntaxClass object to a AttributeOutputStream.Methods inherited from class simula.compiler.syntaxClass.declaration.Declaration
acceptDeclaration, checkAlreadyDefined, getJavaIdentifier, isCompatibleClasses, verifyTree
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, buildByteCode, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, print, SET_SEMANTICS_CHECKED, setLineNumber, 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 Attribute File I/O
-
-
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 Java code.- Overrides:
doDeclarationCoding
in classSyntaxClass
-
buildDeclaration
Description copied from class:Declaration
Output Java ByteCode. Treat Declaration.- Overrides:
buildDeclaration
in classDeclaration
- Parameters:
classBuilder
- the classBuilder to use.encloser
- the owning block.
-
buildInitAttribute
Description copied from class:Declaration
Output Java ByteCode. Build init code for an Attribute.- Overrides:
buildInitAttribute
in classDeclaration
- Parameters:
codeBuilder
- the codeBuilder to use.
-
getFieldIdentifier
Description copied from class:Declaration
ClassFile coding utility: get getFieldIdentifier.- Overrides:
getFieldIdentifier
in classDeclaration
- Returns:
- the resulting String.
-
getClassDesc
-
buildDeclarationCode
Description copied from class:Declaration
Output Java ByteCode. Build declaration code for an Attribute.- Overrides:
buildDeclarationCode
in classDeclaration
- Parameters:
codeBuilder
- the codeBuilder to use.
-
buildGetArrayField
private static void buildGetArrayField(Type type, Meaning meaning, DeclarationScope declaredIn, String arrayIdent, boolean isParameter, CodeBuilder codeBuilder) ClassFile coding utility: Build 'Get Array Field'- Parameters:
type
- the array type.meaning
- the meaning.declaredIn
- the owner.arrayIdent
- the array identifier.isParameter
- true: array is a parameter.codeBuilder
- the codeBuilder to use.
-
prepIndexing
ClassFile coding utility: Prepare for indexing.- Parameters:
checkedParams
- the checked parameterscodeBuilder
- the codeBuilder to use.
-
arrayPutElement
public void arrayPutElement(VariableExpression var, boolean isParameter, Expression rhs, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_putELEMENT.
Example: A.putELEMENT(A.index(2,5,9),666); aload_0 getfield #7 // Field A:Lsimula/runtime/RTS_INTEGER_ARRAY; dup *** prepIndexing *** iconst_3 // boundPairList.size() newarray int dup iconst_0 iconst_2 iastore dup iconst_1 iconst_5 iastore dup iconst_2 bipush 9 iastore invokevirtual #33 // Method simula/runtime/RTS_INTEGER_ARRAY.index:([I)I sipush 666 invokevirtual #37 // Method simula/runtime/RTS_INTEGER_ARRAY.putELEMENT:(II)I
- Parameters:
var
- the variableisParameter
- true: variable is a parameterrhs
- expression.codeBuilder
- the codeBuilder to use.
-
arrayPutElement
public static void arrayPutElement(Meaning meaning, String arrayIdent, boolean isParameter, Vector<Expression> checkedParams, Expression rhs, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_putELEMENT.- Parameters:
meaning
- variable's meaning.arrayIdent
- array's identifierisParameter
- true: variable is a parametercheckedParams
- checked parameters.rhs
- expression.codeBuilder
- the codeBuilder to use.
-
arrayPutElement2
public static void arrayPutElement2(Meaning meaning, Vector<Expression> checkedParams, Expression rhs, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_putELEMENT.- Parameters:
meaning
- variable's meaning.checkedParams
- checked parameters.rhs
- expression.codeBuilder
- the codeBuilder to use.
-
arrayGetElement
ClassFile coding utility: Build invoke ARRAY_getELEMENT.- Parameters:
var
- the variableisParameter
- true: variable is a parametercodeBuilder
- the codeBuilder to use.
-
arrayGetElement
public static void arrayGetElement(Type type, String arrayIdent, boolean isParameter, Vector<Expression> checkedParams, Meaning meaning, DeclarationScope declaredIn, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_getELEMENT.- Parameters:
type
- array's typearrayIdent
- array's identifierisParameter
- true: variable is a parametercheckedParams
- checked parameters.meaning
- variable's meaning.declaredIn
- array's ownercodeBuilder
- the codeBuilder to use.
-
arrayGetElement2
public static void arrayGetElement2(Type type, String arrayIdent, Vector<Expression> checkedParams, CodeBuilder codeBuilder) ClassFile coding utility: Build invoke ARRAY_getELEMENT.- Parameters:
type
- array's typearrayIdent
- array's identifiercheckedParams
- checked parameters.codeBuilder
- the codeBuilder to use.
-
printTree
Description copied from class:SyntaxClass
Utility print syntax tree method.- Overrides:
printTree
in classSyntaxClass
- Parameters:
indent
- number of spaces leading the lineshead
- the head of the tree.
-
toString
-
writeObject
Description copied from class:SyntaxClass
Write a SyntaxClass object to a AttributeOutputStream.- Overrides:
writeObject
in classSyntaxClass
- Parameters:
oupt
- the AttributeOutputStream to write to.- Throws:
IOException
- if something went wrong.
-
readObject
Read and return an ArrayDeclaration object.- Parameters:
inpt
- the AttributeInputStream to read from- Returns:
- the object read from the stream.
- Throws:
IOException
- if something went wrong.
-