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
public abstract sealed class Expression
extends SyntaxClass
permits VariableExpression, ArithmeticExpression, AssignmentOperation, BooleanExpression, ConditionalExpression, Constant, LocalObject, ObjectGenerator, ObjectRelation, QualifiedObject, RelationalOperation, RemoteVariable, TextExpression, TypeConversion, UnaryOperation
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 Summary
Modifier and TypeFieldDescriptionThis Expression is part of backLink Expression/Statement.The typeFields inherited from class simula.compiler.syntaxClass.SyntaxClass
lineNumber
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static Expression
Parse Utility: Accept additive operation.private static Expression
Parse Utility: Accept Boolean AND.private static Expression
Parse Utility: Accept Boolean AND THEN.private static Expression
Parse basic expression.private static Expression
Parse Utility: Accept Boolean EQV.private static Expression
Parse Utility: Accept exponentiation.static Expression
Accept expression.private static Expression
Parse Utility: Accept Boolean IMP.private static Expression
Parse Utility: Accept multiplicative operation.private static Expression
Parse Utility: Accept Boolean NOT.private static Expression
acceptOR()
Parse Utility: Accept Boolean OR.private static Expression
Parse Utility: Accept relation.private static Expression
Parse simple expression.private static Expression
Parse Utility: Accept text concatenation.private static Expression
Parse Utility: Accept unary plus and minus.static boolean
checkCompatibility
(Expression simpleObjectExpression, String classIdentifier) Check compatibility between simpleObjectExpression and a classDeclaration.evaluate()
Try to Compile-time Evaluate this expressionstatic Expression
Expect expression.private static VariableExpression
Parse Utility: Expect Variableprotected String
get()
Generate code for getting the value of this Expressionint
getInt()
Try to evaluate this expression to an integer.Try to evaluate this expression to a number.static ClassDeclaration
getQualification
(String classIdentifier) Get qualification.private static ClassDeclaration
getQualification
(Expression expr) Returns the qualification of the given simpleObjectExpression.Get a writeable variable.abstract boolean
Returns true if this expression may be used as a statement.void
printTree
(int indent) Utility print syntax tree method.(package private) String
Generate code for putting the value into this ExpressiontoString()
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, doChecking, doDeclarationCoding, doJavaCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, print, SET_SEMANTICS_CHECKED, toJavaCode
-
Field Details
-
type
The type -
backLink
This Expression is part of backLink Expression/Statement.
-
-
Constructor Details
-
Expression
Expression()Expression.
-
-
Method Details
-
toString
-
acceptExpression
Accept expression.Expression = SimpleExpression | IF BooleanExpression THEN SimpleExpression ELSE Expression
- Returns:
- Expression or null if no expression is found.
-
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
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
Parse Utility: Accept Boolean AND THEN.BooleanTertiary = Equivalence { AND THEN Equivalence }
- Returns:
- an expression
-
acceptEQV
Parse Utility: Accept Boolean EQV.Equivalence = Implication { EQV Implication }
- Returns:
- an expression
-
acceptIMP
Parse Utility: Accept Boolean IMP.Implication = BooleanTerm { IMP BooleanTerm }
- Returns:
- an expression
-
acceptOR
Parse Utility: Accept Boolean OR.BooleanTerm = BooleanFactor { OR BooleanFactor }
- Returns:
- an expression
-
acceptAND
Parse Utility: Accept Boolean AND.BooleanFactor = BooleanSecondary { AND BooleanSecondary }
- Returns:
- an expression
-
acceptNOT
Parse Utility: Accept Boolean NOT.BooleanSecondary = [ NOT ] BooleanPrimary
- Returns:
- an expression
-
acceptTEXTCONC
Parse Utility: Accept text concatenation.BooleanPrimary = TextPrimary { & TextPrimary }
- Returns:
- an expression
-
acceptRelation
Parse Utility: Accept relation.TextPrimary = SimpleArithmeticExpression [ RelationOperator SimpleArithmeticExpression ] RelationOperator = < | <= | = | >= | > | <> | == | =/=
- Returns:
- an expression
-
acceptAdditiveOperation
Parse Utility: Accept additive operation.SimpleArithmeticExpression = UnaryTerm { ( + | - ) Term }
- Returns:
- an expression
-
acceptUNIMULDIV
Parse Utility: Accept unary plus and minus.UnaryTerm = [ + | - ] Term
- Returns:
- an expression
-
acceptMULDIV
Parse Utility: Accept multiplicative operation.Term = Factor { ( * | / | // ) Factor }
- Returns:
- an expression
-
acceptEXPON
Parse Utility: Accept exponentiation.Factor = BasicExpression { ** BasicExpression }
- Returns:
- an 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
Parse Utility: Expect VariableVariable = Identifier | SubscriptedVariable SubscriptedVariable = Identifier "(" Expression { , Expression } ")"
NOTE: That a SubscriptedVariable may be an subscripted array or a function designator.- Returns:
- the created Variable
-
getWriteableVariable
Get a writeable variable.This method is redefined in Variable, RemoteVariable and TypeConversion
- Returns:
- a writeable variable or null
-
getQualification
Returns the qualification of the given simpleObjectExpression.- Parameters:
expr
- simpleObjectExpression- Returns:
- the qualification of the given simpleObjectExpression
-
getQualification
Get qualification.- Parameters:
classIdentifier
- a class identifier- Returns:
- the ClassDeclaration with same identifier
-
checkCompatibility
Check compatibility between simpleObjectExpression and a classDeclaration.- Parameters:
simpleObjectExpression
- a simple object expressionclassIdentifier
- a class identifier- Returns:
- true if compatible, otherwise false
-
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
Generate code for getting the value of this Expression- Returns:
- the resulting Java code
-
put
Generate code for putting the value into this Expression- Parameters:
evaluated
- a evaluated expression.- Returns:
- the resulting Java code
-
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 classSyntaxClass
- Parameters:
indent
- number of spaces leading the lines
-