Class AST

  • All Implemented Interfaces:
    it.unibo.alchemist.model.sapere.dsl.ITree , java.io.Serializable

    
    public final class AST
     implements ITree
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      AST(ITreeNode<out Object> root) Builds a new AST given its root node.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      AST assignVarValue(Map<HashString, ITreeNode<out Object>> matches) This method substitutes variables present in matches map with their values.
      double evaluation(Map<HashString, ITreeNode<out Object>> matches) This evaluates the expression.
      ITreeNode<out Object> getRoot() Return the root Node of the tree.
      HashString toHashString() Similar to toString(), but returns a HashString.
      String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AST

        AST(ITreeNode<out Object> root)
        Builds a new AST given its root node.
        Parameters:
        root - the root node
    • Method Detail

      • assignVarValue

         AST assignVarValue(Map<HashString, ITreeNode<out Object>> matches)

        This method substitutes variables present in matches map with their values. It must involve only node of Typ=Var. The method must also recognize the values type stored in the map (they can be Const or Num).

        Parameters:
        matches - the map with variable values already assigned.
        Returns:

        a new ITree containing the instantiated variable

      • evaluation

         double evaluation(Map<HashString, ITreeNode<out Object>> matches)

        This evaluates the expression. If the matches map contains values which are not instanced, and the expression value cannot consequently be computed, 0d is returned.

        Parameters:
        matches - the map that binds each variable with its own value
        Returns:

        A number representing the value for this expression. If the expression can't be computed, an exception is thrown.

      • toHashString

         HashString toHashString()

        Similar to toString(), but returns a HashString.

        Returns:

        a HashString representation of this Object