Class VariableExpression


public final class VariableExpression extends Expression

Variable.


Simula Standard: 3.1 Variables
Simula Standard: 3.1.3. Array elements
Simula Standard: 3.1.4. Function designators

variable = simple-variable | subscripted-variable | simple-object-expression . variable

   simple-object-expression = NONE | variable | function-designator | object-generator
                            | local-object | qualified-object | ( object-expression )
                            
   simple-variable = identifier

   subscripted-variable = function-designator | array-element

      function-designator = procedure-identifier ( [ actual-parameter-part ] )
 
         actual-parameter-part = actual-parameter { , actual-parameter }
         
            actual-parameter = expression | array-identifier1 
                             | switch-identifier1 | procedure-identifier1
                             
               identifier1 = identifier | remote-identifier
               
                  remote-identifier = simple-object-expression . attribute-identifier
                                    | text-primary . attribute-identifier

      array-element = array-identifier [ subscript-list ]
      
         subscript-list = arithmetic-expression { , arithmetic-expression }

Function designators:

A function designator defines a value which results through the application of a given set of rules defined by a procedure declaration (see 5.4) to a fixed set of actual parameters. The rules governing specification of actual parameters are given in 4.6.

Note: Not every procedure declaration defines rules for determining the value of a function designator (cf. 5.4.1).

Array elements:

Subscripted variables designate values which are components of multi- dimensional arrays. Each arithmetic expression of the subscript list occupies one subscript position of the subscripted variable and is called a subscript. The complete list of subscripts is enclosed by the subscript parentheses ( ). The array component referred to by a subscripted variable is specified by the actual value of its subscripts.

Each subscript position acts like a variable of type integer and the evaluation of the subscript is understood to be equivalent to an assignment to this fictitious variable. The value of the subscripted variable is defined only if the actual integer value of each subscript expression is within the associated subscript bounds of the array. A subscript expression value outside its associated bounds causes a run time error.

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • identifier

      public String identifier
      The variable's identifier.
    • meaning

      public Meaning meaning
      The meaning of this variable.
    • remotelyAccessed

      private boolean remotelyAccessed
      Indicates that this variable is remotely accessed.
    • params

      The parsed parameters.
    • checkedParams

      public Vector<Expression> checkedParams
      The checked parameters set by doChecking.
  • Constructor Details

    • VariableExpression

      public VariableExpression(String identifier)
      Create a new Variable.
      Parameters:
      identifier - the variable's identifier
    • VariableExpression

      public VariableExpression()
      Default constructor used by Attribute File I/O.
  • Method Details

    • hasArguments

      public boolean hasArguments()
      Returns true if this variable has arguments.
      Returns:
      true if this variable has arguments
    • getJavaIdentifier

      public String getJavaIdentifier()
      Returns a suitable java identifier for this variable.
      Returns:
      a suitable java identifier
    • setRemotelyAccessed

      void setRemotelyAccessed(Meaning meaning)
      This variable is remotely accessed through 'meaning'.
      Parameters:
      meaning - before dot
    • getMeaning

      public Meaning getMeaning()

      Returns the meaning.

      If meaning is not set by setRemotelyAccessed then meaning by identifier will be set.

      Returns:
      the meaning
    • expectVariable

      public static VariableExpression expectVariable(String ident)

      Parse Utility: Expect Variable.

      Variable  =  Identifier  |  SubscriptedVariable
      	SubscriptedVariable  =  Identifier  "("  Expression  {  ,  Expression  }  ")"
      

      Precondition: Identifier is already read.

      Parameters:
      ident - the variable identifier
      Returns:
      the created Variable
    • getWriteableVariable

      public VariableExpression getWriteableVariable()
      Description copied from class: Expression

      Get a writeable variable.

      This method is redefined in Variable, RemoteVariable and TypeConversion.

      Overrides:
      getWriteableVariable in class Expression
      Returns:
      a writeable variable or null
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass

      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • maybeStatement

      public boolean maybeStatement()
      Description copied from class: Expression
      Returns true if this expression may be used as a statement.
      Specified by:
      maybeStatement in class Expression
      Returns:
      true if this expression may be used as a statement
    • toJavaCode

      public String toJavaCode()
      Description copied from class: SyntaxClass
      Generate Java code for this Syntax Class.
      Overrides:
      toJavaCode in class SyntaxClass
      Returns:
      Java code
    • doGetELEMENT

      public String doGetELEMENT(String var)
      Java coding utility: doGetELEMENT.
      Parameters:
      var - the variable
      Returns:
      a suitable java code
    • doPutELEMENT

      public String doPutELEMENT(String var, String rightPart)
      Java coding utility: doPutELEMENT.
      Parameters:
      var - the variable
      rightPart - the right hand side
      Returns:
      a suitable java code
    • put

      public String put(String rightPart)
      Description copied from class: Expression
      Generate code for putting the value into this Expression
      Overrides:
      put in class Expression
      Parameters:
      rightPart - a evaluated expression.
      Returns:
      the resulting Java code
    • get

      public String get()
      Description copied from class: Expression
      Generate code for getting the value of this Expression
      Overrides:
      get in class Expression
      Returns:
      the resulting Java code
    • editVariable

      private String editVariable(String rightPart)
      Java Coding Utility: Edit this Variable.
      Parameters:
      rightPart - When destination, this is the right part of the assignment
      Returns:
      the resulting Java source code
    • edIdentifierAccess

      public String edIdentifierAccess(boolean destination)
      Java coding utility: Edit identifier access.
      Parameters:
      destination - true if this variable is a destination
      Returns:
      a suitable java code
    • edIdentifierAccess

      private String edIdentifierAccess(String id, boolean destination)
      Java Coding Utility: Edit identifier access.
      Parameters:
      id - the identifier
      destination - true if destination
      Returns:
      a suitable java code
    • buildIdentifierAccess

      public void buildIdentifierAccess(boolean destination, CodeBuilder codeBuilder)
      ClassFile Coding Utility: Edit identifier access.
      Parameters:
      destination - true if destination
      codeBuilder - the CodeBuilder
    • buildEvaluation

      public void buildEvaluation(Expression rightPart, CodeBuilder codeBuilder)
      ClassFile Coding Utility: Build this Variable.
      Specified by:
      buildEvaluation in class Expression
      Parameters:
      rightPart - When destination, this is the right part of the assignment
      codeBuilder - the CodeBuilder
    • getFieldRefEntry

      public FieldRefEntry getFieldRefEntry(ConstantPoolBuilder pool)
      ClassFile Coding Utility: Return the field ref entry for this variable.
      Parameters:
      pool - the ConstantPoolBuilder to use.
      Returns:
      the field ref entry for this variable.
    • buildEvaluateParameter

      private void buildEvaluateParameter(Parameter par, Expression inspectedVariable, Expression rightPart, CodeBuilder codeBuilder)
      ClassFile Coding Utility: Build this Parameter.
      Parameters:
      par - the Parameter
      inspectedVariable - then inspected variable or null
      rightPart - When destination, this is the right part of the assignment
      codeBuilder - the CodeBuilder
    • printTree

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

      public String toString()
      Overrides:
      toString in class Expression
    • writeObject

      public void writeObject(AttributeOutputStream oupt) throws IOException
      Description copied from class: SyntaxClass
      Write a SyntaxClass object to a AttributeOutputStream.
      Overrides:
      writeObject in class SyntaxClass
      Parameters:
      oupt - the AttributeOutputStream to write to.
      Throws:
      IOException - if something went wrong.
    • readObject

      public static VariableExpression readObject(AttributeInputStream inpt) throws IOException
      Read and return a VariableExpression object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the VariableExpression object read from the stream.
      Throws:
      IOException - if something went wrong.