Class Expression
-
- All Implemented Interfaces:
-
it.unibo.alchemist.model.sapere.dsl.IExpression
,java.io.Serializable
,java.lang.Cloneable
public final class Expression implements IExpression
-
-
Constructor Summary
Constructors Constructor Description Expression(ITree tree)
This constructor does not do any parsing, and thus is much faster than the other one. Expression(ITreeNode<out Object> n)
Expression(String s)
This constructor parses the String into an Expression.
-
Method Summary
Modifier and Type Method Description ITree
getAST()
ITreeNode<out Object>
getRootNode()
ITreeNode<out Object>
calculate(Map<HashString, ITreeNode<out Object>> map)
ITreeNode<out Object>
getLeftChildren()
ITreeNode<out Object>
getRightChildren()
Object
getRootNodeData()
Type
getRootNodeType()
boolean
matches(IExpression expr, Map<HashString, ITreeNode<out Object>> matches)
Tries to match this expression with expr. boolean
mayMatch(IExpression expr)
This match method test whether or not two expressions might match. boolean
syntacticMatch(IExpression e)
Runs a syntactic match against the e. String
toString()
ITree
updateMatchedVar(Map<HashString, ITreeNode<out Object>> matches)
-
-
Constructor Detail
-
Expression
Expression(ITree tree)
This constructor does not do any parsing, and thus is much faster than the other one.- Parameters:
tree
- the ITree which represents this Expression
-
Expression
Expression(String s)
This constructor parses the String into an Expression.- Parameters:
s
- The String representing the expression
-
-
Method Detail
-
getRootNode
ITreeNode<out Object> getRootNode()
- Returns:
the root note of the AST of this expression
-
calculate
ITreeNode<out Object> calculate(Map<HashString, ITreeNode<out Object>> map)
- Parameters:
map
- the map of the matches.- Returns:
The evaluation of the expression
-
getLeftChildren
ITreeNode<out Object> getLeftChildren()
- Returns:
the left children of the root element.
-
getRightChildren
ITreeNode<out Object> getRightChildren()
- Returns:
the right children of the root element.
-
getRootNodeData
Object getRootNodeData()
- Returns:
the first AST Node Data.
-
getRootNodeType
Type getRootNodeType()
- Returns:
the first AST Node Data.
-
matches
boolean matches(IExpression expr, Map<HashString, ITreeNode<out Object>> matches)
Tries to match this expression with expr. The matching rules are: (i) a variable matches everything; (ii) a constant value matches an identical constant value; (iii) a number matches an identical number or an operator, (iv) operators match everything but constants, (v) comparators match numbers and operators (verifying the values); (vi) expr type can't be comparator; (vii) add and rem operators work only with lists.
- Parameters:
expr
- the expression to match- Returns:
true if this expression can "match" with expr.
-
mayMatch
boolean mayMatch(IExpression expr)
This match method test whether or not two expressions might match. It can be used to evaluate dependencies in a general fashion, it does not check if all the relations are satisfied (e.g. if applying the comparators) but makes a sort of "type checking". If you want to compare two templates, this is the way to go.
- Parameters:
expr
- the expression to verify the possibility of future matches- Returns:
true if this expression can "match" with expr.
-
syntacticMatch
boolean syntacticMatch(IExpression e)
Runs a syntactic match against the e.
- Parameters:
e
- the expression to match with- Returns:
true if the passed IExpression matches this one
-
updateMatchedVar
ITree updateMatchedVar(Map<HashString, ITreeNode<out Object>> matches)
- Returns:
the new ast with variable instantiated.
-
-
-
-