Classes | Public Types | Public Member Functions | Properties
RAIN.Representation.Expression Class Reference

Expression is used to represent math calculations that can be evaluated into float numbers. Expressions are usually entered as text representations similar to Java or C# expressions. Expressions may be nested and may contain variables. The variable "deltaTime" always represents time, and is always bound to deltaTime during expression evaluation. Expressions are used throughout RAIN in Goal Oriented Behavior and Behavior Trees. More...

List of all members.

Classes

class  Keywords

Public Types

enum  FunctionType
 FunctionType. More...
enum  OperatorType
 OperatorType represents standard math operators include addition, subtraction, multiplication, and division Support is not currently included for mod or remainder operations. More...

Public Member Functions

 Expression ()
 Default constructor. Initializes to an empty invalid NO_OP expression.
void Clear ()
 Clear any nested expressions and reset state to an empty invalid NO_OP.
void RenameVariable (string originalName, string newName)
 Rename a variable in this and all nested expressions.
void SetInvalid ()
 Invalidate the Expression. Evaluation will return NaN (not a number) for invalid Expressions.
void SetNull ()
 Set the expression to represent null.
void SetConstant (object constant)
 Set the expression to represent a constant value. This expression will always evaluate to the constant.
void SetVariable (string variable)
 Set the expression to represent a variable value. Only a single variable name will be entered. The variable is not checked against the existing variable context, but is just assumed to be bound at runtime. A variable name may be any string, although using non standard (Java/C#) variable names will result in expressions that can't be rewritten and reparsed.
void SetFunction (FunctionType functionType, params Expression[] args)
 SetFunction.
void SetComplex (Expression expr1, OperatorType operatorType, Expression expr2)
 SetComplex will directly set a complex expression as a left-hand-side (lhs, an infix operator, and a right-hand-side (rhs). isAtomic is used to mark the expression so that its terms do not get reordered on subsequent calls to FixOperatorPrecedence. This is equivalent to adding parenthesis around the expression.
ExpressionValue Evaluate (float deltaTime, AIContext actionContext)
 Evaluate calculates the value of the value of this expression as a float.
followed by a term with a
lower precedence the
expression tree may be
rearranged *</summary > *void 
FixOperatorPrecedence ()
void SetAtomic (bool isAtomic)
 SetAtomic marks an expression so that it can't be changed by the FixOperatorPrecedence function. This is the equivalent of surrounding the expression with parenthesis.
override string ToString ()
 ToString() will return a string representation of the Expression which may differ from the original text parsed to create this expression.

Properties

bool IsValid [get]
 Is the expression valid and can it be evaluated successfully?
bool IsNull [get]
 Does the expression represent null?
bool IsConstant [get]
 Does the expression represent a constant?
bool IsVariable [get]
 Does the expression represent a variable?
bool IsFunction [get]
 Does the expression represent a function?
bool IsComplex [get]
 Does the expression represent a complex expression?
string VariableName [get]
 If the expression represents a variable, returns the variable name Returns null otherwise.
string ExpressionAsEntered [get, set]
 ExpressionAsEntered returns the text used to initially describe the Expression, if the expression was created from parsing a script or manual entry. This is useful when supporting user editing of invalid expressions.

Detailed Description

Expression is used to represent math calculations that can be evaluated into float numbers. Expressions are usually entered as text representations similar to Java or C# expressions. Expressions may be nested and may contain variables. The variable "deltaTime" always represents time, and is always bound to deltaTime during expression evaluation. Expressions are used throughout RAIN in Goal Oriented Behavior and Behavior Trees.


Member Enumeration Documentation

FunctionType.

OperatorType represents standard math operators include addition, subtraction, multiplication, and division Support is not currently included for mod or remainder operations.


Constructor & Destructor Documentation

Default constructor. Initializes to an empty invalid NO_OP expression.


Member Function Documentation

Clear any nested expressions and reset state to an empty invalid NO_OP.

ExpressionValue RAIN.Representation.Expression.Evaluate ( float  deltaTime,
AIContext  actionContext 
)

Evaluate calculates the value of the value of this expression as a float.

Parameters:
deltaTimetime to use for expressions utilizing the variable "deltaTime"
actionContextActionContext to use for variable expressions
Returns:
void RAIN.Representation.Expression.RenameVariable ( string  originalName,
string  newName 
)

Rename a variable in this and all nested expressions.

Parameters:
originalNameThe name of the variable to rename
newNameThe new name to replace the original variable name

SetAtomic marks an expression so that it can't be changed by the FixOperatorPrecedence function. This is the equivalent of surrounding the expression with parenthesis.

Parameters:
isAtomic
void RAIN.Representation.Expression.SetComplex ( Expression  expr1,
OperatorType  operatorType,
Expression  expr2 
)

SetComplex will directly set a complex expression as a left-hand-side (lhs, an infix operator, and a right-hand-side (rhs). isAtomic is used to mark the expression so that its terms do not get reordered on subsequent calls to FixOperatorPrecedence. This is equivalent to adding parenthesis around the expression.

Parameters:
expr1The lhs expression
operatorTypeMathematical operator
expr2The rhs expression
isAtomicA value indicating whether FixOperatorPrecedence can reorder terms.
void RAIN.Representation.Expression.SetConstant ( object  constant)

Set the expression to represent a constant value. This expression will always evaluate to the constant.

Parameters:
kThe constant value to use
void RAIN.Representation.Expression.SetFunction ( FunctionType  functionType,
params Expression[]  args 
)

SetFunction.

Parameters:
expr1
operatorType

Invalidate the Expression. Evaluation will return NaN (not a number) for invalid Expressions.

Set the expression to represent null.

void RAIN.Representation.Expression.SetVariable ( string  variable)

Set the expression to represent a variable value. Only a single variable name will be entered. The variable is not checked against the existing variable context, but is just assumed to be bound at runtime. A variable name may be any string, although using non standard (Java/C#) variable names will result in expressions that can't be rewritten and reparsed.

Parameters:
variableA variable name to use when binding at runtime. Variable names are case sensitive.

ToString() will return a string representation of the Expression which may differ from the original text parsed to create this expression.

Returns:
Returns a text representation of the Expressoin

Property Documentation

ExpressionAsEntered returns the text used to initially describe the Expression, if the expression was created from parsing a script or manual entry. This is useful when supporting user editing of invalid expressions.

Does the expression represent a complex expression?

Does the expression represent a constant?

Does the expression represent a function?

Does the expression represent null?

Is the expression valid and can it be evaluated successfully?

Does the expression represent a variable?

If the expression represents a variable, returns the variable name Returns null otherwise.