Package mepk.kernel

Class Expression

java.lang.Object
mepk.kernel.Expression

public final class Expression extends Object
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.
  • Method Details

    • Var

      public static Expression Var(String name)
      Create a variable expression.
      Parameters:
      name - the variable name
      Returns:
      the created expression
    • App

      public static Expression App(String constantName, Expression... subexpressions)
      Create an application of a constant to a list of subexpressions.
      Parameters:
      constantName - the constant name
      subexpressions - the subexpressions
      Returns:
      the created expression
    • AppV

      public static Expression AppV(String constantName, String... variableNames)
      Create an application of a constant to a list of variable names.
      Parameters:
      constantName - the constant name
      variableNames - the variable names
      Returns:
      the created expression
    • Type

      public static Expression Type(String varName, String typeName)
      Create a new expression saying 'this variable has that type'.
      Parameters:
      varName - the expression
      typeName - the type name
      Returns:
      the type expression
    • Type

      public static Expression Type(Expression expr, String typeName)
      Create a new expression saying 'this expression has that type'.
      Parameters:
      expr - the expression
      typeName - the type name
      Returns:
      the type expression
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getInternalExpression

      public Expression.Internal getInternalExpression()
      Returns the internal representation of this expression.
      Returns:
      the internal expression
    • getVarNames

      public Set<String> getVarNames()
      Return all variables in this expression.
      Returns:
      the variables
    • asVar

      public Var asVar()
      Cast this expression to a variable expression.
      Returns:
      this expression converted to a Var, or null if it is not a variable expression.
    • asApp

      public App asApp()
      Cast this expression to a constant-application expression.
      Returns:
      this expression converted to a App, or null if it is not a constant-application expression.
    • substitute

      public Expression substitute(String varName, Expression replacement)
      Create a new expression by replacing a variable by an expression.
      Parameters:
      varName - the variable to replace
      replacement - the replacement expression
      Returns:
      the new expression
    • addVarNamesTo

      public void addVarNamesTo(Set<String> result)
      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

      public Expression expand(Abbreviation abbreviation, StatementAbbrExpState accu)
      Create a new expression by expanding all instances of the given abbreviation, and collect all conditions in accu.
      Parameters:
      abbreviation - the abbreviation to expand
      accu - the accumulator for the (expanded) conditions
      Returns:
      the new expression