Package mepk.kernel
Class Expression
java.lang.Object
mepk.kernel.Expression
This class represents an expression, i.e., either a variable, or a constant
applied to a list of subexpressions. Expressions are values: they cannot be
modified after they have been created. They are
equal
if (and only if) they have the same structure. It is only possible to create
an instance using the static methods in this class.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVarNamesTo(Set<String> result) Find all variable names in this expression, and add them to the given set.static ExpressionApp(String constantName, Expression... subexpressions) Create an application of a constant to a list of subexpressions.static ExpressionCreate an application of a constant to a list of variable names.asApp()Cast this expression to a constant-application expression.asVar()Cast this expression to a variable expression.booleanexpand(Abbreviation abbreviation, StatementAbbrExpState accu) Create a new expression by expanding all instances of the given abbreviation, and collect all conditions in accu.Returns theinternal representationof this expression.Return all variables in this expression.inthashCode()booleanIs this a simple App expression, i.e., one that contains no nested App expressions?substitute(String varName, Expression replacement) Create a new expression by replacing a variable by an expression.toString()static ExpressionCreate a new expression saying 'this variable has that type'.static ExpressionType(Expression expr, String typeName) Create a new expression saying 'this expression has that type'.static ExpressionCreate a variable expression.
-
Method Details
-
Var
Create a variable expression.- Parameters:
name- the variable name- Returns:
- the created expression
-
App
Create an application of a constant to a list of subexpressions.- Parameters:
constantName- the constant namesubexpressions- the subexpressions- Returns:
- the created expression
-
AppV
Create an application of a constant to a list of variable names.- Parameters:
constantName- the constant namevariableNames- the variable names- Returns:
- the created expression
-
Type
Create a new expression saying 'this variable has that type'.- Parameters:
varName- the expressiontypeName- the type name- Returns:
- the type expression
-
Type
Create a new expression saying 'this expression has that type'.- Parameters:
expr- the expressiontypeName- the type name- Returns:
- the type expression
-
hashCode
public int hashCode() -
equals
-
toString
-
getInternalExpression
Returns theinternal representationof this expression.- Returns:
- the internal expression
-
getVarNames
Return all variables in this expression.- Returns:
- the variables
-
asVar
Cast this expression to a variable expression.- Returns:
- this expression converted to a
Var, ornullif it is not a variable expression.
-
asApp
Cast this expression to a constant-application expression.- Returns:
- this expression converted to a
App, ornullif it is not a constant-application expression.
-
substitute
Create a new expression by replacing a variable by an expression.- Parameters:
varName- the variable to replacereplacement- the replacement expression- Returns:
- the new expression
-
addVarNamesTo
Find all variable names in this expression, and add them to the given set.- Parameters:
result- the accumulating set
-
isSimpleApp
public boolean isSimpleApp()Is this a simple App expression, i.e., one that contains no nested App expressions?- Returns:
- true or false
-
expand
Create a new expression by expanding all instances of the given abbreviation, and collect all conditions in accu.- Parameters:
abbreviation- the abbreviation to expandaccu- the accumulator for the (expanded) conditions- Returns:
- the new expression
-