IGLib  1.5
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
IG.Lib.ExpressionEvaluatorCompiled Class Referenceabstract

Base class for expression evaluators that utilize the functionality of CodeDomProvider class. More...

+ Inheritance diagram for IG.Lib.ExpressionEvaluatorCompiled:
+ Collaboration diagram for IG.Lib.ExpressionEvaluatorCompiled:

Public Member Functions

 ExpressionEvaluatorCompiled ()
 Initializes ID and calls the main initialization method (which will typically be overridden in every subclass). More...
 
virtual object EvalToObject (string code)
 Evaluates JavaScript code and returns result as object. More...
 
virtual int EvalToInteger (string code)
 Evaluates (interprets) JavaScript code and returns integer result of evaluation. Code must be such that result of evaluation can be interpreted as integer. More...
 
virtual double EvalToDouble (string code)
 Evaluates (interprets) JavaScript code and returns double result of evaluation. Code must be such that result of evaluation can be interpreted as double. More...
 
virtual string EvalToString (string code)
 Evaluates (interprets) JavaScript code and returns string result of evaluation. Code must be such that result of evaluation can be interpreted as string. More...
 
string GetRepairedCommand (string command)
 Repairs the specified command and returns the repaired command string. More...
 
virtual void RepairCommand (ref string command)
 Repairs the specified command and returns the repaired command string. More...
 
virtual string Execute (string inputCode)
 Executes the specified code and returns the result. Throws exception if errors occur when interpreting code. After execution, the code is appended to the complete code that has been executed up to this point. More...
 
virtual string Compile (string inputDefinitions)
 Recompiles the basic script where evaluatin is plugged in, with added definitions. Throws exceptions if errors occur when compiling code. After execution, user definitions are added to the base script if compilatin is successful, so that they can be used in subsequent evaluations of code. More...
 
void Reset ()
 Resets the code evaluator (clears variable definitions, etc.). More...
 
virtual void PrintHelpCommandLine ()
 Prints help for the command-line JavaScript interpreter to the standard output. More...
 
virtual void PrintDefinitions ()
 Prints all definitions (preinstalled and user defined). More...
 
virtual void PrintCompleteCode ()
 Prints the complete code that has been input up to now to the console. More...
 
virtual void SaveCompleteCode (string filePath, bool append)
 Prints the complete code inserter up to this moment. More...
 
virtual void UserSaveCompleteCode (bool append)
 Saves or appends the complete code evaluated up to now to a file specified by the user. User is promped for the file to which code is saved. More...
 
virtual void SaveUserDefinitions (string filePath, bool append)
 Saves or appends to the specified file all valid user definitions added to the evaluator up to this point. More...
 
virtual void UserSaveUserDefinitions (bool append)
 Saves or appends the all valid user definitions added to the evaluator up to this point. User is promped for the file to which definitions are saved. More...
 
virtual void CommandLine ()
 Command-line utility where user can successively enter JavaScrit expressions or general portions of code, and evaluates them. Displays prompt to instruct the user, and result of operations. More...
 

Protected Member Functions

abstract void InitExpressionEvaluator ()
 
virtual string CompileBase ()
 Compiles the base script where evaluation is plugged in, and loads the generated assembly and necessary objects. More...
 
virtual string CompileBase (string inputDefinitions)
 Compiles the base script where evaluation is plugged in, and loads the generated assembly and necessary objects. More...
 
virtual string ExecuteUser (string command)
 Executes the code, prints results and reports eventual errors. Also appends the code to the complete valid code that has been interpreted up to now. More...
 
virtual string CompileUser (string inputDefinitions)
 Compiles the specified new definitions. If compilation is successful, the definitions are added to existing definitinos and user is notified through console. Otherwise, error is reported on console. More...
 
virtual string ExecuteUser (ref string inpDefinitions, ref string inpCode)
 Compiles definitions, if any specified, and executes code, if any specified. Eventual results and errors are reported in console. After execution, code and definitions are set to null. More...
 

Protected Attributes

string _language = "unknown"
 
string _packageName = "Evaluator"
 
string _className = "EvaluatorClass"
 
string _evaluationFunctionName = "Eval"
 
string _inputMark = "Calc> "
 
char _multiLineCharacter = '\\'
 
string _commandLineHead
 
string _commandLineStopNote
 
string _helpCommandLineHeading
 
string _helpCommandLine
 

Properties

int Id [get]
 Returns object's Id that is unique within a given type. More...
 
object Lock [get]
 Used for locking internal fields. More...
 
virtual string Language [get, protected set]
 Programming language in use. More...
 
virtual string PackageName [get, protected set]
 Name of the JavaScript package in which evaluated code is executed. More...
 
virtual string ClassName [get, protected set]
 Name of the JavaScript class that is compiled to execute the evaluated code. More...
 
virtual string EvaluationFunctionName [get, protected set]
 Name of the function used for evaluation of expressions. More...
 
virtual string BaseDefinitions [get, protected set]
 A set of pre-defined definitions that can be used in the evaluated code. More...
 
string CompleteCode [get, protected set]
 All valid user code inserted up to this point. Only code that compiled and executed without errors is taken into account. More...
 
virtual string UserDefinitions [get, protected set]
 A set of definitions inserted by users. More...
 
virtual string NewUserDefinitions [get, set]
 New user definitions that are added temporarily for testing. More...
 
virtual string Definitions [get]
 All definitions (pre-defined and user-defined) that can be used in the evaluated code. More...
 
abstract string ScriptBase [get]
 Container for interpreted code. More...
 
virtual string HelpCommandLine [get]
 Returns textual help for JavaScript command-line interpreter. More...
 
- Properties inherited from IG.Lib.ILockable
object Lock [get]
 
- Properties inherited from IG.Lib.IIdentifiable
int Id [get]
 Returns unique ID (in the scope of a given type) of the current object. More...
 

Private Attributes

int _id = -1
 
object _lock = new object()
 
string _baseDefinitions = ""
 
string _userDefinitions = ""
 
string _newUserDefinitions = ""
 
string _completeCode = ""
 
object _evaluator = null
 
Type _evaluatorType = null
 
string _definitionsMark = "Def> "
 
string _multilineMark = "Calc ml> "
 
string _resultMark = " = "
 
string _helpCommand = "?"
 
string _printDefinitionsCommand = "/pd"
 
string _printDefinitionsCommand1 = "/printdefinitions"
 
string _printCodeCommand = "/pc"
 
string _printCodeCommand1 = "/printcode"
 
string _evaluationCommand = "/e"
 
string _evaluationCommand1 = "/evaluate"
 
string _definitionsCommand = "/d"
 
string _definitionsCommand1 = "/def"
 
string _multilineCommand = "/m"
 
string _multilineCommand1 = "/multiline"
 
string _saveCodeCommand = "/sc"
 
string _appendCodeCommand = "/ac"
 
string _saveDefinitionsComand = "/sd"
 
string _appendDefinitionsComand = "/ad"
 
string _resetCommand = "/reset"
 
string _quitCommand = "/exit"
 
string _quitCommand1 = "/q"
 
string _quitCommand2 = "/quit"
 
char _commandCharacter = '/'
 

Static Private Attributes

static int _lastId = 0
 
static object _idLock = new object()
 

Detailed Description

Base class for expression evaluators that utilize the functionality of CodeDomProvider class.

Constructor & Destructor Documentation

IG.Lib.ExpressionEvaluatorCompiled.ExpressionEvaluatorCompiled ( )
inline

Initializes ID and calls the main initialization method (which will typically be overridden in every subclass).

Member Function Documentation

abstract void IG.Lib.ExpressionEvaluatorCompiled.InitExpressionEvaluator ( )
protectedpure virtual
virtual string IG.Lib.ExpressionEvaluatorCompiled.CompileBase ( )
inlineprotectedvirtual

Compiles the base script where evaluation is plugged in, and loads the generated assembly and necessary objects.

Returns
Eventual compilation results.
virtual string IG.Lib.ExpressionEvaluatorCompiled.CompileBase ( string  inputDefinitions)
inlineprotectedvirtual

Compiles the base script where evaluation is plugged in, and loads the generated assembly and necessary objects.

Parameters
inputDefinitionsNew definitions that are added to the base script and will not yet be part of permanent definitions (but will become part of them if compilation is successful).
virtual object IG.Lib.ExpressionEvaluatorCompiled.EvalToObject ( string  code)
inlinevirtual

Evaluates JavaScript code and returns result as object.

Parameters
codeJavaScript code to be evaluated.
Returns
Object that is result of evaluaton of code.
virtual int IG.Lib.ExpressionEvaluatorCompiled.EvalToInteger ( string  code)
inlinevirtual

Evaluates (interprets) JavaScript code and returns integer result of evaluation. Code must be such that result of evaluation can be interpreted as integer.

Parameters
codeCode that is evaluated.
Returns
virtual double IG.Lib.ExpressionEvaluatorCompiled.EvalToDouble ( string  code)
inlinevirtual

Evaluates (interprets) JavaScript code and returns double result of evaluation. Code must be such that result of evaluation can be interpreted as double.

Parameters
codeCode that is evaluated.
Returns
virtual string IG.Lib.ExpressionEvaluatorCompiled.EvalToString ( string  code)
inlinevirtual

Evaluates (interprets) JavaScript code and returns string result of evaluation. Code must be such that result of evaluation can be interpreted as string.

Parameters
codeCode that is evaluated.
Returns
string IG.Lib.ExpressionEvaluatorCompiled.GetRepairedCommand ( string  command)
inline

Repairs the specified command and returns the repaired command string.

Reparations serve for easier insertion of commands and for addition of syntactic cookies.

Parameters
commandCommand to be repaired.
virtual void IG.Lib.ExpressionEvaluatorCompiled.RepairCommand ( ref string  command)
inlinevirtual

Repairs the specified command and returns the repaired command string.

Reparations serve for easier insertion of commands and for addition of syntactic cookies.

Parameters
commandCommand to be repaired.

Reimplemented in IG.Lib.ExpressionEvaluatorJs.

virtual string IG.Lib.ExpressionEvaluatorCompiled.Execute ( string  inputCode)
inlinevirtual

Executes the specified code and returns the result. Throws exception if errors occur when interpreting code. After execution, the code is appended to the complete code that has been executed up to this point.

Parameters
codeCode that is exected by the JavaScript interpreter.
Returns
Result of code execution as string.
virtual string IG.Lib.ExpressionEvaluatorCompiled.Compile ( string  inputDefinitions)
inlinevirtual

Recompiles the basic script where evaluatin is plugged in, with added definitions. Throws exceptions if errors occur when compiling code. After execution, user definitions are added to the base script if compilatin is successful, so that they can be used in subsequent evaluations of code.

Parameters
inputDefinitionsUser definitions that are compiled and added to the code.
Returns
void IG.Lib.ExpressionEvaluatorCompiled.Reset ( )
inline

Resets the code evaluator (clears variable definitions, etc.).

virtual void IG.Lib.ExpressionEvaluatorCompiled.PrintHelpCommandLine ( )
inlinevirtual

Prints help for the command-line JavaScript interpreter to the standard output.

virtual void IG.Lib.ExpressionEvaluatorCompiled.PrintDefinitions ( )
inlinevirtual

Prints all definitions (preinstalled and user defined).

virtual void IG.Lib.ExpressionEvaluatorCompiled.PrintCompleteCode ( )
inlinevirtual

Prints the complete code that has been input up to now to the console.

virtual void IG.Lib.ExpressionEvaluatorCompiled.SaveCompleteCode ( string  filePath,
bool  append 
)
inlinevirtual

Prints the complete code inserter up to this moment.

Parameters
filePath
append
virtual void IG.Lib.ExpressionEvaluatorCompiled.UserSaveCompleteCode ( bool  append)
inlinevirtual

Saves or appends the complete code evaluated up to now to a file specified by the user. User is promped for the file to which code is saved.

Parameters
append
virtual void IG.Lib.ExpressionEvaluatorCompiled.SaveUserDefinitions ( string  filePath,
bool  append 
)
inlinevirtual

Saves or appends to the specified file all valid user definitions added to the evaluator up to this point.

Parameters
filePathPath to the file that definitions saved to.
appendIf true then definitions are appended to the file (old content is preserved).
virtual void IG.Lib.ExpressionEvaluatorCompiled.UserSaveUserDefinitions ( bool  append)
inlinevirtual

Saves or appends the all valid user definitions added to the evaluator up to this point. User is promped for the file to which definitions are saved.

Parameters
appendIf true then definitions are appended to the file (old content is preserved).
virtual string IG.Lib.ExpressionEvaluatorCompiled.ExecuteUser ( string  command)
inlineprotectedvirtual

Executes the code, prints results and reports eventual errors. Also appends the code to the complete valid code that has been interpreted up to now.

Parameters
commandCommand to be executed.
Returns
virtual string IG.Lib.ExpressionEvaluatorCompiled.CompileUser ( string  inputDefinitions)
inlineprotectedvirtual

Compiles the specified new definitions. If compilation is successful, the definitions are added to existing definitinos and user is notified through console. Otherwise, error is reported on console.

Parameters
inputDefinitionsUser definitions to be added and compiled.
Returns
Eventual results of compilation.
virtual string IG.Lib.ExpressionEvaluatorCompiled.ExecuteUser ( ref string  inpDefinitions,
ref string  inpCode 
)
inlineprotectedvirtual

Compiles definitions, if any specified, and executes code, if any specified. Eventual results and errors are reported in console. After execution, code and definitions are set to null.

Parameters
inpDefinitionsUser definitions that must be added to existing definitions. If specified then the evaluation code is re-compiled.
inpCodeUser code that is evaluated.
Returns
Eventual results of evaluation.
virtual void IG.Lib.ExpressionEvaluatorCompiled.CommandLine ( )
inlinevirtual

Command-line utility where user can successively enter JavaScrit expressions or general portions of code, and evaluates them. Displays prompt to instruct the user, and result of operations.

Member Data Documentation

int IG.Lib.ExpressionEvaluatorCompiled._lastId = 0
staticprivate
object IG.Lib.ExpressionEvaluatorCompiled._idLock = new object()
staticprivate
int IG.Lib.ExpressionEvaluatorCompiled._id = -1
private
object IG.Lib.ExpressionEvaluatorCompiled._lock = new object()
private
string IG.Lib.ExpressionEvaluatorCompiled._language = "unknown"
protected
string IG.Lib.ExpressionEvaluatorCompiled._packageName = "Evaluator"
protected
string IG.Lib.ExpressionEvaluatorCompiled._className = "EvaluatorClass"
protected
string IG.Lib.ExpressionEvaluatorCompiled._evaluationFunctionName = "Eval"
protected
string IG.Lib.ExpressionEvaluatorCompiled._baseDefinitions = ""
private
string IG.Lib.ExpressionEvaluatorCompiled._userDefinitions = ""
private
string IG.Lib.ExpressionEvaluatorCompiled._newUserDefinitions = ""
private
string IG.Lib.ExpressionEvaluatorCompiled._completeCode = ""
private
object IG.Lib.ExpressionEvaluatorCompiled._evaluator = null
private
Type IG.Lib.ExpressionEvaluatorCompiled._evaluatorType = null
private
string IG.Lib.ExpressionEvaluatorCompiled._inputMark = "Calc> "
protected
string IG.Lib.ExpressionEvaluatorCompiled._definitionsMark = "Def> "
private
string IG.Lib.ExpressionEvaluatorCompiled._multilineMark = "Calc ml> "
private
string IG.Lib.ExpressionEvaluatorCompiled._resultMark = " = "
private
string IG.Lib.ExpressionEvaluatorCompiled._helpCommand = "?"
private
string IG.Lib.ExpressionEvaluatorCompiled._printDefinitionsCommand = "/pd"
private
string IG.Lib.ExpressionEvaluatorCompiled._printDefinitionsCommand1 = "/printdefinitions"
private
string IG.Lib.ExpressionEvaluatorCompiled._printCodeCommand = "/pc"
private
string IG.Lib.ExpressionEvaluatorCompiled._printCodeCommand1 = "/printcode"
private
string IG.Lib.ExpressionEvaluatorCompiled._evaluationCommand = "/e"
private
string IG.Lib.ExpressionEvaluatorCompiled._evaluationCommand1 = "/evaluate"
private
string IG.Lib.ExpressionEvaluatorCompiled._definitionsCommand = "/d"
private
string IG.Lib.ExpressionEvaluatorCompiled._definitionsCommand1 = "/def"
private
string IG.Lib.ExpressionEvaluatorCompiled._multilineCommand = "/m"
private
string IG.Lib.ExpressionEvaluatorCompiled._multilineCommand1 = "/multiline"
private
string IG.Lib.ExpressionEvaluatorCompiled._saveCodeCommand = "/sc"
private
string IG.Lib.ExpressionEvaluatorCompiled._appendCodeCommand = "/ac"
private
string IG.Lib.ExpressionEvaluatorCompiled._saveDefinitionsComand = "/sd"
private
string IG.Lib.ExpressionEvaluatorCompiled._appendDefinitionsComand = "/ad"
private
string IG.Lib.ExpressionEvaluatorCompiled._resetCommand = "/reset"
private
string IG.Lib.ExpressionEvaluatorCompiled._quitCommand = "/exit"
private
string IG.Lib.ExpressionEvaluatorCompiled._quitCommand1 = "/q"
private
string IG.Lib.ExpressionEvaluatorCompiled._quitCommand2 = "/quit"
private
char IG.Lib.ExpressionEvaluatorCompiled._multiLineCharacter = '\\'
protected
char IG.Lib.ExpressionEvaluatorCompiled._commandCharacter = '/'
private
string IG.Lib.ExpressionEvaluatorCompiled._commandLineHead
protected
Initial value:
= @"
Command-line Calculator:
Insert expressions or commands!
/m for multiline mode, /d for definitions, /e to evaluate, /q to exit!
End line with '\\' to input multiline code, ? for help!
"
string IG.Lib.ExpressionEvaluatorCompiled._commandLineStopNote
protected
Initial value:
= @"
Command-line calculator stopped.
"
string IG.Lib.ExpressionEvaluatorCompiled._helpCommandLineHeading
protected
Initial value:
= @"
Command-line Expression Evaluator Help:
Insert valid code or special commands one line after another!
Quit with '\q' ."
string IG.Lib.ExpressionEvaluatorCompiled._helpCommandLine
protected
Initial value:
= @"
Special commands must be inserted without leading spaces.
End lines with '\\' in order to insert multiline code.
List of commands:
? : prints this help
/e or /evaluate : insertion and evaluation of code
/m or /multiline : insertion and evaluation of multiple lines
/d or /def : insertion of definitions (multiline)
/pc or /printcode: prints the current code contained in the buffer
/pd or /printdefinitions: prints definitions (user and predefined)
/sc : saves the evaluated code to a file (file path prompted)
/ac : appends the evaluated code to a file (file path prompted)
/sd : saves all added definitions to a file (file path prompted)
/ad : appends all added definitons to a file (file path prompted)
/reset : resets the evaluator
/q or /quit or /exit : exits command-line evaluator
Syntactic specifics:
Automatic variable declaration does not work.
All variables must be declared with 'var'.
Invalid code is ignored (with error report launched).
This enables you to re-enter corrected code.
The last valid result will be returned.
The last expression does not need to (but it can) end with semicolon.
"

Property Documentation

int IG.Lib.ExpressionEvaluatorCompiled.Id
get

Returns object's Id that is unique within a given type.

object IG.Lib.ExpressionEvaluatorCompiled.Lock
get

Used for locking internal fields.

virtual string IG.Lib.ExpressionEvaluatorCompiled.Language
getprotected set

Programming language in use.

virtual string IG.Lib.ExpressionEvaluatorCompiled.PackageName
getprotected set

Name of the JavaScript package in which evaluated code is executed.

virtual string IG.Lib.ExpressionEvaluatorCompiled.ClassName
getprotected set

Name of the JavaScript class that is compiled to execute the evaluated code.

virtual string IG.Lib.ExpressionEvaluatorCompiled.EvaluationFunctionName
getprotected set

Name of the function used for evaluation of expressions.

virtual string IG.Lib.ExpressionEvaluatorCompiled.BaseDefinitions
getprotected set

A set of pre-defined definitions that can be used in the evaluated code.

string IG.Lib.ExpressionEvaluatorCompiled.CompleteCode
getprotected set

All valid user code inserted up to this point. Only code that compiled and executed without errors is taken into account.

virtual string IG.Lib.ExpressionEvaluatorCompiled.UserDefinitions
getprotected set

A set of definitions inserted by users.

virtual string IG.Lib.ExpressionEvaluatorCompiled.NewUserDefinitions
getsetprotected

New user definitions that are added temporarily for testing.

virtual string IG.Lib.ExpressionEvaluatorCompiled.Definitions
get

All definitions (pre-defined and user-defined) that can be used in the evaluated code.

abstract string IG.Lib.ExpressionEvaluatorCompiled.ScriptBase
getprotected

Container for interpreted code.

When overridden in subclasses, this property will be dynamic (i.e. each get accessor will generate the value anew), and the value will depend on current values of the package, class and function name as well as additonal definitions input by user.

virtual string IG.Lib.ExpressionEvaluatorCompiled.HelpCommandLine
get

Returns textual help for JavaScript command-line interpreter.

Returns

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