Module Simula

Class BooleanExpression


public final class BooleanExpression extends Expression
Boolean expressions
 Simula Standard: 3.2 Boolean expressions

    Boolean-expression
        =  simple-Boolean-expression
        |  IF Boolean-expression THEN  simple-Boolean-expression  ELSE  Boolean-expression

    simple-Boolean-expression
        =  Boolean-tertiary  { OR ELSE  Boolean-tertiary }

    Boolean-tertiary
        =  equivalence  { AND THEN  equivalence }

    equivalence
        =  implication  { EQV  implication }

    implication
        =  Boolean-term  { IMP  Boolean-term }

    Boolean-term
        =  Boolean-factor  { OR  Boolean-factor }

    Boolean-factor
        =  Boolean-secondary  { AND  Boolean-secondary }

    Boolean-secondary
        =  [ NOT ]  Boolean-primary

    Boolean-primary
        =  logical-value
        |  variable
        |  function-designator
        |  relation
        |  "("  Boolean-expression  ")"
 
A Boolean expression is of type Boolean. It is a rule for computing a logical value. Except for the operators and then and or else (see 3.4) the semantics are entirely analogous to those given for arithmetic expressions.

Variables and function designators entered as Boolean primaries must be of type Boolean. Simula Standard: 3.4 The logical operators

The meaning of the logical operators not, and, or, imp, and eqv is given by the following function table:

        b1               false     false     true      true
        b2               false     true      false     true
      ---------------------------------------------------------
        not  b1          true      true      false     false
        b1 and b2        false     false     false     true
        b1 or b2         false     true      true      true
        b1 imp b2        true      true      false     true
        b1 eqv b2        true      false     false     true
     ----------------------------------------------------------
 
The operation "b1 and then b2" denotes "conditional and". If the value of b1 is false the operation yields the result false, otherwise it yields the result of evaluating b2.

The operation "b1 or else b2" denotes "conditional or". If the value of b1 is true the operator yields the result true, otherwise it yields the result of evaluating b2.

Note: The value of "b1 and then b2" is given by textual substitution of the Boolean expression "(if b1 then b2 else false)". Similarly, the operation "b1 or else b2" is defined by substitution of "(if b1 then true else b2)". These definitions imply that the evaluation of the second operand is suppressed when the evaluation result is already evident from the value of the first operand alone.

Link to GitHub: Source File.

Author:
Simula Standard, Øystein Myhre Andersen
  • Field Details

    • lhs

      private Expression lhs
      The left hand side
    • opr

      private final KeyWord opr
      The Boolean operation
    • rhs

      private Expression rhs
      The right hand side
  • Constructor Details

    • BooleanExpression

      BooleanExpression(Expression lhs, KeyWord opr, Expression rhs)
      Create a new BooleanExpression.
      Parameters:
      lhs - left hand side
      opr - Boolean operation
      rhs - right hand side
  • Method Details

    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Expression