Module Simula

Class Expression

java.lang.Object
simula.compiler.syntaxClass.SyntaxClass
simula.compiler.syntaxClass.expression.Expression
Direct Known Subclasses:
ArithmeticExpression, AssignmentOperation, BooleanExpression, ConditionalExpression, Constant, LocalObject, ObjectGenerator, ObjectRelation, QualifiedObject, RelationalOperation, RemoteVariable, TextExpression, TypeConversion, UnaryOperation, VariableExpression

Expression.
 Simula Standard: Chapter 3 Expressions
 
   expression
      = value-expression
      | reference-expression
      | designational-expression
      
   value-expression
      = arithmetic-expression
      | Boolean-expression
      | character-expression
      
   reference-expression
      = object-expression
      | text-expression
 

Syntax used during Parsing:

 Expression  =  SimpleExpression
                   |  IF  BooleanExpression  THEN  SimpleExpression  ELSE  Expression

  SimpleExpression  =  BooleanTertiary  { OR ELSE  BooleanTertiary }
  BooleanTertiary   =  Equivalence  { AND THEN  Equivalence }
  Equivalence       =  Implication  { EQV  Implication }
  Implication       =  BooleanTerm  { IMP  BooleanTerm }
  BooleanTerm       =  BooleanFactor  { OR  BooleanFactor }
  BooleanFactor     =  BooleanSecondary  { AND  BooleanSecondary }
  BooleanSecondary  =  [ NOT ]  BooleanPrimary
  BooleanPrimary    =  TextPrimary  { & TextPrimary }
  TextPrimary       =  SimpleArithmeticExpression  [ RelationOperator  SimpleArithmeticExpression ]
       RelationOperator  =  <  |  <=  |  =  |  >=  |  >  |  <> |  ==  |  =/=
  SimpleArithmeticExpression  =  [ + | - ]  Term  {  ( + | - )  Term }
  Term    =  Factor  {  ( * | / | // )  Factor }
  Factor  =  BasicExpression  { **  BasicExpression }
              
  
  BasicExpression  =  PrimaryExpression  |  {  RemoteIdentifier  |  ObjectRelation  |  QualifiedObject   }
                RemoteIdentifier =  PrimaryExpression  .  AttributeIdentifier
                ObjectRelation   =  PrimaryExpression ( IS | IN )  ClassIdentifier
                QualifiedObject  =  PrimaryExpression  QUA  ClassIdentifier
 
  PrimaryExpression =  ( Expression ) | Constant | ObjectGenerator | LocalObject | Variable | SubscriptedVariable
                Constant = IntegerConstant | RealConstant | CharacterConstant | TextConstant | BooleanConstant | SymbolicValue  
                                BooleanConstant = TRUE | FALSE
                                SymbolicValue   = NONE | NOTEXT
                ... other constants as delivered by the scanner
                ObjectGenerator  =  NEW  Identifier  "("  Expression  {  ,  Expression  }  ")"
                LocalObject = THIS ClassIdentifier
                Variable  =  Identifier
                SubscriptedVariable  =  Identifier  "("  Expression  {  ,  Expression  }  ")"
   
 
Link to GitHub: Source File.
Author:
SIMULA Standards Group, Øystein Myhre Andersen, Stein Krogdahl
  • Field Details

    • type

      public Type type
      The type
  • Constructor Details

    • Expression

      Expression()
      Expression.
  • Method Details

    • toString

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

      public static Expression acceptExpression()
      Accept expression.
       Expression  =  SimpleExpression
                       |  IF  BooleanExpression  THEN  SimpleExpression  ELSE  Expression
       
      Returns:
      Expression or null if no expression is found.
    • expectExpression

      public static Expression expectExpression()
      Expect expression.
       Expression  =  SimpleExpression
                       |  IF  BooleanExpression  THEN  SimpleExpression  ELSE  Expression
       
      If no expression is found an error message is printed.
      Returns:
      Expression or null if no expression is found.
    • acceptSimpleExpression

      private static Expression acceptSimpleExpression()
      Parse simple expression.
        SimpleExpression  =  BooleanTertiary  { OR ELSE  BooleanTertiary }
        BooleanTertiary   =  Equivalence  { AND THEN  Equivalence }
        Equivalence       =  Implication  { EQV  Implication }
        Implication       =  BooleanTerm  { IMP  BooleanTerm }
        BooleanTerm       =  BooleanFactor  { OR  BooleanFactor }
        BooleanFactor     =  BooleanSecondary  { AND  BooleanSecondary }
        BooleanSecondary  =  [ NOT ]  BooleanPrimary
        BooleanPrimary    =  TextPrimary  { & TextPrimary }
        TextPrimary       =  SimpleArithmeticExpression  [ RelationOperator  SimpleArithmeticExpression ]
             RelationOperator  =  <  |  <=  |  =  |  >=  |  >  |  <> |  ==  |  =/=
        SimpleArithmeticExpression  =  [ + | - ]  Term  {  ( + | - )  Term }
        Term    =  Factor  {  ( * | / | // )  Factor }
        Factor  =  BasicExpression  { **  BasicExpression }
       
      Returns:
      Expression or null if no expression is found.
    • acceptANDTHEN

      private static Expression acceptANDTHEN()
      Parse Utility: Accept Boolean AND THEN.
       BooleanTertiary =  Equivalence  { AND THEN  Equivalence }
       
      Returns:
      an expression
    • acceptEQV

      private static Expression acceptEQV()
      Parse Utility: Accept Boolean EQV.
       Equivalence  =  Implication  { EQV  Implication }
       
      Returns:
      an expression
    • acceptIMP

      private static Expression acceptIMP()
      Parse Utility: Accept Boolean IMP.
       Implication =  BooleanTerm  { IMP  BooleanTerm }
       
      Returns:
      an expression
    • acceptOR

      private static Expression acceptOR()
      Parse Utility: Accept Boolean OR.
       BooleanTerm  =  BooleanFactor  { OR  BooleanFactor }
       
      Returns:
      an expression
    • acceptAND

      private static Expression acceptAND()
      Parse Utility: Accept Boolean AND.
       BooleanFactor =  BooleanSecondary  { AND  BooleanSecondary }
       
      Returns:
      an expression
    • acceptNOT

      private static Expression acceptNOT()
      Parse Utility: Accept Boolean NOT.
       BooleanSecondary  =  [ NOT ]  BooleanPrimary
       
      Returns:
      an expression
    • acceptTEXTCONC

      private static Expression acceptTEXTCONC()
      Parse Utility: Accept text concatenation.
       BooleanPrimary  =  TextPrimary  { & TextPrimary }
       
      Returns:
      an expression
    • acceptRelation

      private static Expression acceptRelation()
      Parse Utility: Accept relation.
       TextPrimary =  SimpleArithmeticExpression  [ RelationOperator  SimpleArithmeticExpression ]
          RelationOperator  =  <  |  <=  |  =  |  >=  |  >  |  <> |  ==  |  =/=
       
      Returns:
      an expression
    • acceptAdditiveOperation

      private static Expression acceptAdditiveOperation()
      Parse Utility: Accept additive operation.
       SimpleArithmeticExpression  =  UnaryTerm  {  ( + | - )  Term }
       
      Returns:
      an expression
    • acceptUNIMULDIV

      private static Expression acceptUNIMULDIV()
      Parse Utility: Accept unary plus and minus.
       UnaryTerm  =  [ + | - ]  Term
       
      Returns:
      an expression
    • acceptMULDIV

      private static Expression acceptMULDIV()
      Parse Utility: Accept multiplicative operation.
       Term  =  Factor  {  ( * | / | // )  Factor }
       
      Returns:
      an expression
    • acceptEXPON

      private static Expression acceptEXPON()
      Parse Utility: Accept exponentiation.
       Factor  =  BasicExpression  { **  BasicExpression }
       
      Returns:
      an expression
    • acceptBASICEXPR

      private static Expression acceptBASICEXPR()
      Parse basic expression.
        BasicExpression  =  PrimaryExpression  |  {  RemoteIdentifier  |  ObjectRelation  |  QualifiedObject   }
                      RemoteIdentifier =  PrimaryExpression  .  AttributeIdentifier
                      ObjectRelation   =  PrimaryExpression ( IS | IN )  ClassIdentifier
                      QualifiedObject  =  PrimaryExpression  QUA  ClassIdentifier
       
        PrimaryExpression =  ( Expression ) | Constant | ObjectGenerator | LocalObject | Variable | SubscriptedVariable
                      Constant = IntegerConstant | RealConstant | CharacterConstant | TextConstant | BooleanConstant | SymbolicValue  
                                      BooleanConstant = TRUE | FALSE
                                      SymbolicValue   = NONE | NOTEXT
                      ... other constants as delivered by the scanner
                      ObjectGenerator  =  NEW  Identifier  "("  Expression  {  ,  Expression  }  ")"
                      LocalObject = THIS ClassIdentifier
                      Variable  =  Identifier
                      SubscriptedVariable  =  Identifier  "("  Expression  {  ,  Expression  }  ")"
       
      Returns:
      Expression or null if no expression is found.
    • expectVariable

      private static VariableExpression expectVariable()
      Parse Utility: Expect Variable
       Variable  =  Identifier  |  SubscriptedVariable
              SubscriptedVariable  =  Identifier  "("  Expression  {  ,  Expression  }  ")"
       
      NOTE: That a SubscriptedVariable may be an subscripted array or a function designator.
      Returns:
      the created Variable
    • getWriteableVariable

      public VariableExpression getWriteableVariable()
      Get a writeable variable.

      This method is redefined in Variable, RemoteVariable and TypeConversion

      Returns:
      a writeable variable or null
    • getQualification

      private static ClassDeclaration getQualification(Expression expr)
      Returns the qualification of the given simpleObjectExpression.
      Parameters:
      expr - simpleObjectExpression
      Returns:
      the qualification of the given simpleObjectExpression
    • getQualification

      public static ClassDeclaration getQualification(String classIdentifier)
      Get qualification.
      Parameters:
      classIdentifier - a class identifier
      Returns:
      the ClassDeclaration with same identifier
    • checkCompatibility

      public static boolean checkCompatibility(Expression simpleObjectExpression, String classIdentifier)
      Check compatibility between simpleObjectExpression and a classDeclaration.
      Parameters:
      simpleObjectExpression - a simple object expression
      classIdentifier - a class identifier
      Returns:
      true if compatible, otherwise false
    • evaluate

      public Expression evaluate()
      Try to Compile-time Evaluate this expression
      Returns:
      the resulting evaluated expression
    • maybeStatement

      public abstract boolean maybeStatement()
      Returns true if this expression may be used as a statement.
      Returns:
      true if this expression may be used as a statement
    • get

      protected String get()
      Generate code for getting the value of this Expression
      Returns:
      the resulting Java code
    • put

      String put(String evaluated)
      Generate code for putting the value into this Expression
      Parameters:
      evaluated - a evaluated expression.
      Returns:
      the resulting Java code
    • getNumber

      public Number getNumber()
      Try to evaluate this expression to a number.
      Returns:
      the resulting number or null
    • getInt

      public int getInt()
      Try to evaluate this expression to an integer.
      Returns:
      the resulting int or 0
    • 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