Class BooleanExpression
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 Summary
FieldsModifier and TypeFieldDescriptionprivate Expression
The left hand sideprivate int
The Boolean operationprivate Expression
The right hand sideFields inherited from class simula.compiler.syntaxClass.expression.Expression
backLink, type
Fields inherited from class simula.compiler.syntaxClass.SyntaxClass
CHECKED, lineNumber, OBJECT_SEQU
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Default constructor used by Attribute File I/O(package private)
BooleanExpression
(Expression lhs, int opr, Expression rhs) Create a new BooleanExpression. -
Method Summary
Modifier and TypeMethodDescriptionvoid
buildEvaluation
(Expression rightPart, CodeBuilder codeBuilder) ClassFile coding utility: Build Evaluation Code.void
Perform semantic checking.boolean
Returns true if this expression may be used as a statement.static BooleanExpression
Read and return a BooleanExpression.Generate Java code for this Syntax Class.toString()
void
Write a SyntaxClass object to a AttributeOutputStream.Methods inherited from class simula.compiler.syntaxClass.expression.Expression
acceptExpression, checkCompatibility, evaluate, expectExpression, get, getInt, getNumber, getQualification, getWriteableVariable, printTree, put
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, buildByteCode, doDeclarationCoding, doJavaCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, print, SET_SEMANTICS_CHECKED, setLineNumber
-
Field Details
-
lhs
The left hand side -
opr
private int oprThe Boolean operation -
rhs
The right hand side
-
-
Constructor Details
-
BooleanExpression
BooleanExpression(Expression lhs, int opr, Expression rhs) Create a new BooleanExpression.- Parameters:
lhs
- left hand sideopr
- Boolean operationrhs
- right hand side
-
BooleanExpression
private BooleanExpression()Default constructor used by Attribute File I/O
-
-
Method Details
-
doChecking
public void doChecking()Description copied from class:SyntaxClass
Perform semantic checking.
This must be redefined in every subclass.
- Overrides:
doChecking
in classSyntaxClass
-
maybeStatement
public boolean maybeStatement()Description copied from class:Expression
Returns true if this expression may be used as a statement.- Specified by:
maybeStatement
in classExpression
- Returns:
- true if this expression may be used as a statement
-
toJavaCode
Description copied from class:SyntaxClass
Generate Java code for this Syntax Class.- Overrides:
toJavaCode
in classSyntaxClass
- Returns:
- Java code
-
buildEvaluation
Description copied from class:Expression
ClassFile coding utility: Build Evaluation Code.- Specified by:
buildEvaluation
in classExpression
- Parameters:
rightPart
- expressioncodeBuilder
- the codeBuilder used.
-
toString
- Overrides:
toString
in classExpression
-
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 a BooleanExpression.- Parameters:
inpt
- the AttributeInputStream to read from- Returns:
- the BooleanExpression read from the stream.
- Throws:
IOException
- if something went wrong.
-