QScript  2.1.2
Expression and algorithm evaluator
 All Classes Namespaces Functions Variables Pages
Classes | Public Member Functions | Static Public Member Functions | List of all members
org.qscript.Script Class Reference

Classes

class  ScriptTimer
 

Public Member Functions

float getRunTime ()
 
boolean isParsed ()
 
int traceDelay ()
 
void traceDelay (int delay)
 
boolean isTraceModeOn ()
 
void traceModeOn ()
 
void traceModeOff ()
 
void setTimeLimit (float limit)
 
boolean isStopped ()
 
boolean isPaused ()
 
boolean isRunning ()
 
synchronized void stop ()
 
synchronized void waitFor (int time)
 
synchronized void resume ()
 
Result evaluate ()
 
Result evaluate_ () throws EvaluationException
 
Result finalResult ()
 
void throwSyntaxException (ErrorType etype, Token token) throws SyntaxException
 
void throwEvaluationException (ErrorType etype, Token token) throws EvaluationException
 
void fireEvent (Class<?extends ScriptEvent > eventClass, ErrorType etype, Token token)
 
void fireEvent (Class<?extends ScriptEvent > eventClass, ErrorType etype, Token token, Object extra)
 
void fireEvent (Class<?extends ScriptEvent > eventClass, ErrorType etype, Token token, Object[] extra)
 
boolean addListener (Object listener)
 
boolean removeListener (Object listener)
 
String getLastIdentifier ()
 
void storeVariable (Variable var)
 
void storeVariable (String identifier, Object value)
 
synchronized Variable[] getStoredVariables ()
 
void clearVariables ()
 
Variable getVariable (String identifier)
 
Variable getVariable (Variable var)
 
 Script (String line)
 
 Script (String[] lines)
 
 Script (List< String > lines)
 
void parse ()
 
void parse_ () throws SyntaxException
 
float getParseTime ()
 
void setCode (List< String > lines)
 
void setCode (String[] lines)
 
void setCode (String line)
 
String[] getCode ()
 
void printTokens (String title, List< Token > tokens)
 
void printProgram (String title, List< ScriptStep > steps)
 

Static Public Member Functions

static void defaultTimeLimit (float defaultTimeLimit)
 
static double defaultTimeLimit ()
 

Detailed Description

This class is responsible for managing all the actions necessary to evaluate an expression or algorithm. It will use the Tokenizer, Postix and Compiler classes to create a list of ScriptStep(s) which it will then try to evaluate.

Author
Peter Lager

Member Function Documentation

boolean org.qscript.Script.addListener ( Object  listener)

Add an event listener to this script.

The listener must have a method annotated with this method must have a single parameter of type ScriptEvent.

Parameters
listenerthe event receiver
Returns
true if a listener has been successfully added else false.
void org.qscript.Script.clearVariables ( )

Remove all variables from the data store

static void org.qscript.Script.defaultTimeLimit ( float  defaultTimeLimit)
static

Set the default time limit (seconds) for all subsequent scripts. This is used to stop the script evaluation taking longer than expected. It is useful in the event of an infinite loop.

Parameters
defaultTimeLimitthe maximum time in seconds
static double org.qscript.Script.defaultTimeLimit ( )
static

Get the default script evaluation time limit.

void org.qscript.Script.fireEvent ( Class<?extends ScriptEvent eventClass,
ErrorType  etype,
Token  token 
)

Worker method to create and forward script events to listeners.

Parameters
eventClassthe event class we want to create
etypethe error type (if the event is caused by an error)
tokenthe token that is the source of the event
void org.qscript.Script.fireEvent ( Class<?extends ScriptEvent eventClass,
ErrorType  etype,
Token  token,
Object  extra 
)

Worker method to create and forward script events to listeners.

Parameters
eventClassthe event class we want to create
etypethe error type (if the event is caused by an error)
tokenthe token that is the source of the event
extraone additional object depending on event and error types
void org.qscript.Script.fireEvent ( Class<?extends ScriptEvent eventClass,
ErrorType  etype,
Token  token,
Object[]  extra 
)

Worker method to create and forward script events to listeners.

Parameters
eventClassthe event class we want to create
etypethe error type (if the event is caused by an error)
tokenthe token that is the source of the event
extraadditional objects depending on event and error types
String [] org.qscript.Script.getCode ( )

Get the lines of code for this script.

float org.qscript.Script.getParseTime ( )

Get the time it took parse the script ready for evaluation

Returns
the parse time in seconds
synchronized Variable [] org.qscript.Script.getStoredVariables ( )

Get an array of all the variables stored in the data store.
This is slow because it has to be synchronised with the script. It is better to create your own data store in the main sketch and listen for DataStoreEvents.

Returns
a copy of the data store as an array
Variable org.qscript.Script.getVariable ( String  identifier)

Get a simple variable based on the identifier.

Parameters
identifier
Returns
null if variable is not in the store
Variable org.qscript.Script.getVariable ( Variable  var)

Get a simple variable from the store.

Parameters
var
Returns
null if variable is not in the store
boolean org.qscript.Script.isParsed ( )

See if the script has been successfully parsed

boolean org.qscript.Script.isPaused ( )

Return true of the script has been paused during evaluation.

boolean org.qscript.Script.isRunning ( )

Is the evaluation still going on?

Returns
false if the script has been stopped or paused.
boolean org.qscript.Script.isStopped ( )

Return true of the script has stopped evaluation.

boolean org.qscript.Script.isTraceModeOn ( )

Determines whether this script should fire TraceEvents or not.
If you switch tracing on then the time limit is ignored because it is assumed that you are taking control and will end evaluation with the stop() method when needed.
If you are switching off tracing then the timer is reset and the time limit set equal to the default time limit.
You can adjust the trace speed the with traceDelay(int) method.

Parameters
activateuse true to turn on trace events Find out whether the trace is on or not.
boolean org.qscript.Script.removeListener ( Object  listener)

Remove an event listener to this script.

Parameters
listenerthe event receiver
Returns
true if a listener has been successfully removed else false.
synchronized void org.qscript.Script.resume ( )

This will resume a paused script. Use this to resume a script from the wait state

void org.qscript.Script.setCode ( List< String >  lines)

Set the script lines for this script.
The script will need to be initialized before evaluating.

Parameters
linesthe code as a list of strings
void org.qscript.Script.setCode ( String[]  lines)

Set the script lines for this script.
The script will need to be initialized before evaluating.

Parameters
linesthe code as an array of strings
void org.qscript.Script.setCode ( String  line)

Set the script line for this script.
The script will need to be initialized before evaluating.

Parameters
linesingle line of code
void org.qscript.Script.setTimeLimit ( float  limit)

Sets the time limit for this script. The script will be stopped if this time is reached.

Parameters
limitin seconds
synchronized void org.qscript.Script.stop ( )

Stop the evaluation - result is undefined.

void org.qscript.Script.storeVariable ( Variable  var)

Save a variable to the current score. Only fire an event if the script is running and returns a copy of the variable to avoid concurrency issues

Parameters
var
void org.qscript.Script.storeVariable ( String  identifier,
Object  value 
)

Load the store with a new variable based on the provided identifier and value. The identifier will be prepended with $ if necessary.

Parameters
identifierthe identifier e.g. $x
valuethe value.
void org.qscript.Script.throwEvaluationException ( ErrorType  etype,
Token  token 
) throws EvaluationException

Focal point for all evaluation exception throwing.

Parameters
etypethe error type
tokentoken where the exception occured
Exceptions
SyntaxException
void org.qscript.Script.throwSyntaxException ( ErrorType  etype,
Token  token 
) throws SyntaxException

Focal point for all syntax exception throwing.

Parameters
etypethe error type
tokentoken where the exception occured
Exceptions
SyntaxException
int org.qscript.Script.traceDelay ( )

Get the delay time (in milliseconds) after token has been parsed.

Returns
the traceDelay
void org.qscript.Script.traceDelay ( int  delay)

Set the delay (milliseconds) between processing tokens It does not determine if the trace mode is on or off, this should be done with

traceModeOn()
traceModeOff()
Parameters
delaythe traceDelay (in milliseconds) to set
void org.qscript.Script.traceModeOff ( )

Switches trace mode off

void org.qscript.Script.traceModeOn ( )

Switches the trace mode on. This causes a delay between evaluation of token. The delay time is not included in the script runtime so will not cause the script to time out.

synchronized void org.qscript.Script.waitFor ( int  time)

Will cause the script to pause for the specified time in milliseconds or until resume() method is called, whichever is the sooner. If the parameter time is zero then the script must be resumed by the user.

The wait time is not included in the runtime so will not cause the script to timeout.

If the script is already in a paused state or has stopped then this method does nothing.
It is also called by the script WAAIT operator

Parameters
timetimeout in milliseconds

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