Module Simula

Class ArrayDeclaration

All Implemented Interfaces:
Externalizable, Serializable

public final class ArrayDeclaration extends Declaration implements Externalizable
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
See Also:
  • Field Details

  • Constructor Details

    • ArrayDeclaration

      private ArrayDeclaration(String identifier, Type type, Vector<ArrayDeclaration.BoundPair> boundPairList)
      Create a new ArrayDeclaration
      Parameters:
      identifier - the array identifier
      type - the array type
      boundPairList - The list of BoundPair
    • ArrayDeclaration

      public ArrayDeclaration()
      Default constructor used by Externalization.
  • Method Details

    • expectArrayDeclaration

      static void expectArrayDeclaration(Type type, DeclarationList declarationList)
      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 type
      declarationList - 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 class SyntaxClass
    • doJavaCoding

      public void doJavaCoding()
      Description copied from class: SyntaxClass
      Output Java code.
      Overrides:
      doJavaCoding in class SyntaxClass
    • doDeclarationCoding

      public void doDeclarationCoding()
      Description copied from class: SyntaxClass
      Output possible declaration code.
      Overrides:
      doDeclarationCoding in class SyntaxClass
    • printTree

      public void printTree(int indent)
      Description copied from class: SyntaxClass
      Utility print syntax tree method.
      Overrides:
      printTree in class SyntaxClass
      Parameters:
      indent - number of spaces leading the lines
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • writeExternal

      public void writeExternal(ObjectOutput oupt) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput inpt) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException