QScript  2.1.2
Expression and algorithm evaluator
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
org.qscript.operator.Operator Class Referenceabstract

Inherits org.qscript.Token.

Inherited by org.qscript.operator.AbsFunction, org.qscript.operator.AcosFunction, org.qscript.operator.AdditionSymbol, org.qscript.operator.AndSymbol, org.qscript.operator.AngleBetweenFunction, org.qscript.operator.AsinFunction, org.qscript.operator.AssignmentSymbol, org.qscript.operator.Atan2Function, org.qscript.operator.AtanFunction, org.qscript.operator.CeilFunction, org.qscript.operator.CommaSymbol, org.qscript.operator.ComplexFunction, org.qscript.operator.ConjugateFunction, org.qscript.operator.CosFunction, org.qscript.operator.CoshFunction, org.qscript.operator.CrossFunction, org.qscript.operator.DegreesToRadians, org.qscript.operator.DivisionSymbol, org.qscript.operator.DotFunction, org.qscript.operator.E_constant, org.qscript.operator.EOL_constant, org.qscript.operator.EqualSymbol, org.qscript.operator.ExpFunction, org.qscript.operator.ExpressionSeperatorSymbol, org.qscript.operator.False_constant, org.qscript.operator.FloorFuction, org.qscript.operator.FlowOperator, org.qscript.operator.GreaterThanOrEqualSymbol, org.qscript.operator.GreaterThanSymbol, org.qscript.operator.ImagFunction, org.qscript.operator.IntFunction, org.qscript.operator.LeftParenSymbol, org.qscript.operator.LerpFunction, org.qscript.operator.LessThanOrEqualSymbol, org.qscript.operator.LessThanSymbol, org.qscript.operator.Log10_Function, org.qscript.operator.Log_Function, org.qscript.operator.LogE_Function, org.qscript.operator.MagFunction, org.qscript.operator.MaxFunction, org.qscript.operator.MinFunction, org.qscript.operator.ModuloSymbol, org.qscript.operator.MultiplicationSymbol, org.qscript.operator.NegFunction, org.qscript.operator.NormalizeFunction, org.qscript.operator.NotEqualSymbol, org.qscript.operator.NotFuntion, org.qscript.operator.OrSymbol, org.qscript.operator.PI_constant, org.qscript.operator.PowerFunction, org.qscript.operator.PrintFunction, org.qscript.operator.PrintlnFunction, org.qscript.operator.RadiansToDegrees, org.qscript.operator.RandomComplexFunction, org.qscript.operator.RandomFunction, org.qscript.operator.RandomVectorFunction, org.qscript.operator.RealFunction, org.qscript.operator.RightParenSymbol, org.qscript.operator.RoundFunction, org.qscript.operator.RuntimeFunction, org.qscript.operator.SignumFunction, org.qscript.operator.SinFunction, org.qscript.operator.SinhFunction, org.qscript.operator.SqrtFunction, org.qscript.operator.SqrtzFunction, org.qscript.operator.SubtractionSymbol, org.qscript.operator.TanFunction, org.qscript.operator.TanhFunction, org.qscript.operator.True_constant, org.qscript.operator.V000_constant, org.qscript.operator.V001_constant, org.qscript.operator.V010_constant, org.qscript.operator.V100_constant, org.qscript.operator.VectorFunction, org.qscript.operator.VectorXFunction, org.qscript.operator.VectorYFunction, org.qscript.operator.VectorZFunction, org.qscript.operator.WAIT_operator, and org.qscript.operator.XorSymbol.

Public Member Functions

 Operator (String symbol, int nbrArgs, int priority, int type)
 
abstract Argument resolve (Script script, Token token, Argument[] args, Object...objects) throws EvaluationException
 
String getSymbol ()
 
int getNbrArgs ()
 
int getPriority ()
 
int getOpType ()
 
boolean isOperator ()
 
String forListing ()
 
String toString ()
 
- Public Member Functions inherited from org.qscript.Token
void setTextPosition (int charStart, int charWidth)
 
void setTextPosition (int line, int charStart, int charWidth)
 
int getLine ()
 
int getCharStart ()
 
int getCharWidth ()
 
boolean isArgument ()
 
boolean isFlowAction ()
 
boolean isVariable ()
 
boolean isThing ()
 
boolean isOperator ()
 
boolean isFlowOperator ()
 
String forListing ()
 

Static Public Attributes

static final int MARKER = 0
 
static final int CONSTANT = 1
 
static final int INFIX_SYMBOL = 2
 
static final int FUNCTION = 3
 
- Static Public Attributes inherited from org.qscript.Token
static final Token DUMMY = new Argument(null)
 

Protected Member Functions

boolean testForUninitialisedVars (Script script, Argument[] args) throws EvaluationException
 
boolean testForUninitialisedVar (Script script, Argument arg) throws EvaluationException
 
void handleInvalidArguments (Script script, Token token) throws EvaluationException
 
- Protected Member Functions inherited from org.qscript.Token
 Token ()
 

Additional Inherited Members

- Protected Attributes inherited from org.qscript.Token
int line
 
int charStart
 
int charWidth
 

Detailed Description

This is the base class for all operators to be recognized by the expression parser.
There are four operator types -
MARKER
These do not perform any evaluation themselves so they do not require any arguments. Examples include WEND, ELSE, comma, parenthesis.
CONSTANT
These are simply named values (e.g. PI, E, EOL) so they have no arguments to process but must have a high priority (40) so that its value is retrieved before further evaluation.
INFIX_SYMBOL
An infix symbols is any symbol that sits between the two operands it has to process. These include the


It does mean that infix symbols always require exactly two arguments.
FUNCTION
A function is any symbol that takes one or more arguments and evaluates them. All functions have the format

symbol(comma separated list of arguments)


These include all the common mathematical functions such as sqrt, cos, sin; but the library also has some extras such as rnd, pow
All functions have the same priority (30)

It is possible to create user defined operators and add them to the standard set.

Author
Peter Lager

Constructor & Destructor Documentation

org.qscript.operator.Operator.Operator ( String  symbol,
int  nbrArgs,
int  priority,
int  type 
)

This is the constructor used to create an operator object.

Parameters
symbolthe symbol/name that identifies this operator.
nbrArgsthe number of arguments needed by this operator
prioritythe value used to determine the order of precedence
typethe operator type

Member Function Documentation

String org.qscript.operator.Operator.forListing ( )

Used in Script and Parser classes when listings

int org.qscript.operator.Operator.getNbrArgs ( )

Get the number of arguments needed by this operator

int org.qscript.operator.Operator.getOpType ( )

Get the operator type

int org.qscript.operator.Operator.getPriority ( )

Get the operator priority value. This is used to determine the order that operators are evaluated.

String org.qscript.operator.Operator.getSymbol ( )

Get the operator identifying symbol

void org.qscript.operator.Operator.handleInvalidArguments ( Script  script,
Token  token 
) throws EvaluationException
protected

Call this method if the arguments are the incorrect types for the operator

Parameters
scriptthe Script object responsible for evaluation
charNo
charWidth
Exceptions
EvaluationException
boolean org.qscript.operator.Operator.isOperator ( )

Returns true

abstract Argument org.qscript.operator.Operator.resolve ( Script  script,
Token  token,
Argument[]  args,
Object...  objects 
) throws EvaluationException
pure virtual
Parameters
scriptthe Script object responsible for evaluation
tokenthe current token being evaluated
argsthe arguments for this operator
objectsignore it has been included for possible future use
Returns
the result of this operation or null if there is no need to store the result
Exceptions
SyntaxException
EvaluationException

Implemented in org.qscript.operator.END_operator, org.qscript.operator.SqrtFunction, org.qscript.operator.SqrtzFunction, org.qscript.operator.AssignmentSymbol, org.qscript.operator.PowerFunction, org.qscript.operator.WAIT_operator, org.qscript.operator.AsinFunction, org.qscript.operator.DivisionSymbol, org.qscript.operator.ELSE_operator, org.qscript.operator.ImagFunction, org.qscript.operator.MultiplicationSymbol, org.qscript.operator.NegFunction, org.qscript.operator.SubtractionSymbol, org.qscript.operator.WEND_operator, org.qscript.operator.AcosFunction, org.qscript.operator.AtanFunction, org.qscript.operator.CosFunction, org.qscript.operator.CoshFunction, org.qscript.operator.ENDIF_operator, org.qscript.operator.ExpFunction, org.qscript.operator.IF_operator, org.qscript.operator.LogE_Function, org.qscript.operator.PrintFunction, org.qscript.operator.PrintlnFunction, org.qscript.operator.RandomComplexFunction, org.qscript.operator.RandomVectorFunction, org.qscript.operator.RealFunction, org.qscript.operator.REPEAT_operator, org.qscript.operator.SinFunction, org.qscript.operator.SinhFunction, org.qscript.operator.TanFunction, org.qscript.operator.TanhFunction, org.qscript.operator.UNTIL_operator, org.qscript.operator.V000_constant, org.qscript.operator.V001_constant, org.qscript.operator.V010_constant, org.qscript.operator.V100_constant, org.qscript.operator.VectorXFunction, org.qscript.operator.VectorYFunction, org.qscript.operator.VectorZFunction, org.qscript.operator.WHILE_operator, org.qscript.operator.AbsFunction, org.qscript.operator.AndSymbol, org.qscript.operator.Atan2Function, org.qscript.operator.CeilFunction, org.qscript.operator.CommaSymbol, org.qscript.operator.ConjugateFunction, org.qscript.operator.DegreesToRadians, org.qscript.operator.E_constant, org.qscript.operator.EOL_constant, org.qscript.operator.EqualSymbol, org.qscript.operator.False_constant, org.qscript.operator.GreaterThanOrEqualSymbol, org.qscript.operator.GreaterThanSymbol, org.qscript.operator.IntFunction, org.qscript.operator.LeftParenSymbol, org.qscript.operator.LessThanOrEqualSymbol, org.qscript.operator.LessThanSymbol, org.qscript.operator.Log10_Function, org.qscript.operator.MaxFunction, org.qscript.operator.MinFunction, org.qscript.operator.ModuloSymbol, org.qscript.operator.NotEqualSymbol, org.qscript.operator.NotFuntion, org.qscript.operator.OrSymbol, org.qscript.operator.PI_constant, org.qscript.operator.RadiansToDegrees, org.qscript.operator.RandomFunction, org.qscript.operator.RightParenSymbol, org.qscript.operator.RoundFunction, org.qscript.operator.RuntimeFunction, org.qscript.operator.SignumFunction, org.qscript.operator.True_constant, org.qscript.operator.XorSymbol, org.qscript.operator.ExpressionSeperatorSymbol, org.qscript.operator.AdditionSymbol, org.qscript.operator.AngleBetweenFunction, org.qscript.operator.LerpFunction, org.qscript.operator.CrossFunction, org.qscript.operator.MagFunction, org.qscript.operator.NormalizeFunction, org.qscript.operator.DotFunction, org.qscript.operator.VectorFunction, org.qscript.operator.Log_Function, org.qscript.operator.FloorFuction, and org.qscript.operator.ComplexFunction.

boolean org.qscript.operator.Operator.testForUninitialisedVar ( Script  script,
Argument  arg 
) throws EvaluationException
protected

This method checks to see if a variable has been initialized.

Parameters
scriptthe Script object responsible for evaluation
argslist of Arguments to check
Returns
true if the variable has been initialized
Exceptions
SyntaxException
EvaluationException
boolean org.qscript.operator.Operator.testForUninitialisedVars ( Script  script,
Argument[]  args 
) throws EvaluationException
protected

This method checks for uninitialized variables and should be called by the first statement in the method resolve().

The only exception is the Assignment class where the left hand operand may be an uninitialized variable.

Parameters
scriptthe Script object responsible for evaluation
argslist of Arguments to check
Exceptions
SyntaxException
EvaluationException

The documentation for this class was generated from the following file: