Simula Standard: 3.5 Arithmetic expressions arithmetic-expression = simple-arithmetic-expression | if-clause simple-arithmetic-expression else arithmetic-expression simple-arithmetic-expression = [ + | - ] term { ( + | - ) term } term = factor { ( * | / | // ) factor } factor = primary { ** primary } primary = unsigned-number | variable | function-designator | "(" arithmetic-expression ")"An arithmetic expression is a rule for computing a numerical value. In the case of simple arithmetic expressions this value is obtained by executing the indicated arithmetic operations on the actual numerical values of the primaries of the expression, as explained in detail in 3.5.1 below. The value of a primary is obvious in the case of numbers. For variables it is the current value (assigned last in the dynamic sense), and for function designators it is the value arising from the computing rules defining the procedure when applied to the current values of the procedure parameters given in the expression. Finally, for arithmetic expressions enclosed by parentheses the value must through a recursive analysis be expressed in terms of the values of primaries of the other three kinds.
In the more general arithmetic expressions, which include if-clauses, one out of several simple arithmetic expressions is selected on the basis of the actual values of the Boolean expressions (see 3.2). This selection is made as follows: The Boolean expressions of the if-clauses are evaluated one by one in sequence from left to right until one having the value true is found. The value of the arithmetic expression is then the value of the first arithmetic expression following this Boolean (the longest arithmetic expression found in this position is understood). If none of the Boolean expressions has the value true, then the value of the arithmetic expression is the value of the expression following the final else.
In evaluating an arithmetic expression, all primaries within that expression are evaluated with the following exceptions:
- Primaries that occur within any expression governed by an if-clause but not selected by it. - Primaries that occur within a Boolean expression 1) after the operator or else when the evaluation of a preceding Boolean tertiary results in false, or 2) after the operator and then when the evaluation of a preceding equivalence results in false. - Primaries that occur after a function designator, and the evaluation of the function terminates with a goto-statement. In this case the evaluation of the arithmetic expression is abandoned.Primaries are always evaluated in strict lexical order. NOTE: The implementation of EXP '**' deviates from the definition in Simula Standard. It is always evaluated in long real and the result is converted to the appropriate type.
Link to GitHub: Source File.
- Author:
- Simula Standard, Øystein Myhre Andersen
-
Field Summary
Modifier and TypeFieldDescriptionprivate Expression
The left hand sideprivate final KeyWord
The arithmetic operationprivate Expression
The right hand sideFields inherited from class simula.compiler.syntaxClass.expression.Expression
backLink, type
Fields inherited from class simula.compiler.syntaxClass.SyntaxClass
lineNumber
-
Constructor Summary
ModifierConstructorDescriptionprivate
ArithmeticExpression
(Expression lhs, KeyWord opr, Expression rhs) Create a new ArithmeticExpression -
Method Summary
Modifier and TypeMethodDescription(package private) static Expression
create
(Expression lhs, KeyWord opr, Expression rhs) Create a new ArithmeticExpression.void
Perform semantic checking.evaluate()
Try to Compile-time Evaluate this expressionboolean
Returns true if this expression may be used as a statement.Generate Java code for this Syntax Class.toString()
Methods inherited from class simula.compiler.syntaxClass.expression.Expression
acceptExpression, checkCompatibility, expectExpression, get, getInt, getNumber, getQualification, getWriteableVariable, printTree, put
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, doDeclarationCoding, doJavaCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, print, SET_SEMANTICS_CHECKED
-
Field Details
-
lhs
The left hand side -
opr
The arithmetic operation -
rhs
The right hand side
-
-
Constructor Details
-
ArithmeticExpression
Create a new ArithmeticExpression- Parameters:
lhs
- left hand sideopr
- arithmetic operationrhs
- right hand side
-
-
Method Details
-
create
Create a new ArithmeticExpression.- Parameters:
lhs
- the left hand sideopr
- the arithmetic operationrhs
- the right hand side- Returns:
- the newly created ArithmeticExpression
-
evaluate
Description copied from class:Expression
Try to Compile-time Evaluate this expression- Overrides:
evaluate
in classExpression
- Returns:
- the resulting evaluated expression
-
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
-
toString
- Overrides:
toString
in classExpression
-