Class JXG.JessieCode
↳ JXG.JessieCode
Defined in: JessieCode.js.
Constructor Attributes | Constructor Name and Description |
---|---|
JXG.JessieCode(code, geonext)
A JessieCode object provides an interfacce to the parser and stores all variables and objects used within a JessieCode script.
|
Field Attributes | Field Name and Description |
---|---|
The board which currently is used to create and look up elements.
|
|
Built-in functions and constants
|
|
Returns a element creator function which takes two parameters: the parents array and the attributes object.
|
|
lhs flag, used by JXG.JessieCode#replaceNames
|
|
<private> |
Store the left hand side of an assignment.
|
Maximum number of seconds the parser is allowed to run.
|
|
<private> |
Whenever an element attribute is set via element.attribute = 'something';, the element is stored
in here, so following attribute changes can be set without the element: .attribute = 'something else';.
|
<private> |
The current scope of the object literal stack JXG.JessieCode#propstack.
|
<private> |
Used to store the property-value definition while parsing an object literal.
|
<private> |
Determines the parameter stack scope.
|
<private> |
A stack used to store the parameter lists for function definitions and calls.
|
<private> |
Defines the current variable scope.
|
<private> |
Stores all variables, local and global.
|
The id of an HTML node in which innerHTML all warnings are stored (if no console object is available).
|
Method Attributes | Method Name and Description |
---|---|
<private> |
_debug(log)
Output a debugging message.
|
<private> |
_error(msg)
Throws an exception with the given error message.
|
<private> |
_lex(PCB)
Internal lexer method.
|
<private> |
_parse(src, err_off, err_la)
Internal parse tree generator.
|
<private> |
_warn(msg)
Output a warning message using JXG#debug and precedes the message with "Warning: ".
|
collectDependencies(node, result)
Search the parse tree below node for stationary dependencies, i.e.
|
|
<private> |
compile(node, js)
Compiles a parse tree back to JessieCode.
|
createNode(type, value, children)
Create a new parse tree node.
|
|
createReplacementNode(node)
Replaces node_var nodes with node_op>op_execfun nodes, calling the internal $() function with the id of the
element accessed by the node_var node.
|
|
Defines built in methods and constants.
|
|
dist(p1, p2)
This is used as the global dist() function.
|
|
<private> |
execute(node)
Executes a parse subtree.
|
getElementById(id)
Looks up an JXG.GeometryElement by its id.
|
|
getvar(vname, local)
Looks up the value of the given variable.
|
|
getvarJS(vname, local)
Looks up a variable identifier in various tables and generates JavaScript code that could be eval'd to get the value.
|
|
isBuiltIn(vname)
Returns true if the given identifier is a builtIn variable/function.
|
|
isCreator(vname)
Checks if the given variable name is a valid creator method.
|
|
isLocalVariable(vname)
Checks if the given variable name can be found in JXG.JessieCode#sstack.
|
|
isMathMethod(vname)
Checks if the given variable identifier is a valid member of the JavaScript Math Object.
|
|
L(e)
This is used as the global L() function.
|
|
letvar(vname, value)
Assigns a value to a variable in the current scope.
|
|
mul(a, b)
Multiplication of vectors and numbers
|
|
node(type, value, children)
Create a new parse tree node.
|
|
parse(code, geonext)
Parses JessieCode
|
|
replaceIDs(node)
Traverses through the given subtree and changes all values of nodes with the replaced flag set by
JXG.JessieCode#replaceNames to the name of the element (if not empty).
|
|
replaceNames(node)
Traverses through the given subtree and changes all elements referenced by names through referencing them by ID.
|
|
setProp(what, value, value)
Sets the property what of JXG.JessieCode#propobj to value
|
|
snippet(code, funwrap, varname, geonext)
Parses a JessieCode snippet, e.g.
|
|
utf8_encode(string)
Encode characters outside the ASCII table into HTML Entities, because JavaScript or JS/CC can't handle a RegEx
applied to a string with unicode characters.
|
|
V(e)
This is used as the global V() function.
|
|
X(e)
This is used as the global X() function.
|
|
Y(e)
This is used as the global Y() function.
|
Class Detail
JXG.JessieCode(code, geonext)
A JessieCode object provides an interfacce to the parser and stores all variables and objects used within a JessieCode script.
The optional argument code is interpreted after initializing. To evaluate more code after initializing a JessieCode instance
please use JXG.JessieCode#parse. For code snippets like single expressions use JXG.JessieCode#snippet.
- Parameters:
- {String} code Optional
- Code to parse.
- {Boolean} geonext Optional, Default: false
- Geonext compatibility mode.
Field Detail
{JXG.Board}
board
The board which currently is used to create and look up elements.
{Object}
builtIn
Built-in functions and constants
{function}
creator
Returns a element creator function which takes two parameters: the parents array and the attributes object.
{Boolean}
isLHS
lhs flag, used by JXG.JessieCode#replaceNames
- Default Value:
- false
<private>
{Array}
lhs
Store the left hand side of an assignment. If an element is constructed and no attributes are given, this is
used as the element's name.
{Number}
maxRuntime
Maximum number of seconds the parser is allowed to run. After that the interpreter is stopped.
- Default Value:
- 10000
<private>
{JXG.GeometryElement}
propobj
Whenever an element attribute is set via element.attribute = 'something';, the element is stored
in here, so following attribute changes can be set without the element: .attribute = 'something else';.
<private>
{Number}
propscope
The current scope of the object literal stack JXG.JessieCode#propstack.
<private>
{Array}
propstack
Used to store the property-value definition while parsing an object literal.
<private>
{Number}
pscope
Determines the parameter stack scope.
<private>
{Array}
pstack
A stack used to store the parameter lists for function definitions and calls.
<private>
{Number}
scope
Defines the current variable scope.
<private>
{Array}
sstack
Stores all variables, local and global. The current scope is determined by JXG.JessieCode#scope.
{String}
warnLog
The id of an HTML node in which innerHTML all warnings are stored (if no console object is available).
- Default Value:
- 'jcwarn'
Method Detail
<private>
_debug(log)
Output a debugging message. Uses debug console, if available. Otherwise an HTML element with the
id "debug" and an innerHTML property is used.
- Parameters:
- {String} log
<private>
_error(msg)
Throws an exception with the given error message.
- Parameters:
- {String} msg
- Error message
<private>
_lex(PCB)
Internal lexer method.
- Parameters:
- PCB
<private>
_parse(src, err_off, err_la)
Internal parse tree generator.
- Parameters:
- {String} src
- source code
- {Array} err_off
- The positions where the errors occured are stored here.
- {Array} err_la
- What the parser expected will be stored here.
<private>
_warn(msg)
Output a warning message using JXG#debug and precedes the message with "Warning: ".
- Parameters:
- {String} msg
collectDependencies(node, result)
Search the parse tree below node for stationary dependencies, i.e. dependencies hard coded into
the function.
- Parameters:
- {Object} node
- {Object} result
- An object where the referenced elements will be stored. Access key is their id.
<private>
compile(node, js)
Compiles a parse tree back to JessieCode.
- Parameters:
- {Object} node
- {Boolean} js Optional, Default: false
- Currently ignored. Compile either to JavaScript or back to JessieCode (required for the UI).
- Returns:
- Something
createNode(type, value, children)
Create a new parse tree node. Basically the same as node(), but this builds
the children part out of an arbitrary number of parameters, instead of one
array parameter.
- Parameters:
- {String} type
- Type of node, e.g. node_op, node_var, or node_const
- value
- The nodes value, e.g. a variables value or a functions body.
- children
- Arbitrary number of parameters; define the child nodes.
{Object}
createReplacementNode(node)
Replaces node_var nodes with node_op>op_execfun nodes, calling the internal $() function with the id of the
element accessed by the node_var node.
- Parameters:
- {Object} node
- Returns:
- {Object} op_execfun node
{Object}
defineBuiltIn()
Defines built in methods and constants.
- Returns:
- {Object} BuiltIn control object
{Number}
dist(p1, p2)
This is used as the global dist() function.
- Returns:
- {Number}
<private>
execute(node)
Executes a parse subtree.
- Parameters:
- {Object} node
- Returns:
- Something
{JXG.GeometryElement}
getElementById(id)
Looks up an JXG.GeometryElement by its id.
- Parameters:
- {String} id
- Returns:
- {JXG.GeometryElement}
getvar(vname, local)
Looks up the value of the given variable.
- Parameters:
- {String} vname
- Name of the variable
- local
getvarJS(vname, local)
Looks up a variable identifier in various tables and generates JavaScript code that could be eval'd to get the value.
- Parameters:
- {String} vname
- Identifier
- {Boolean} local Optional, Default: false
- Don't resolve ids and names of elements
{Boolean}
isBuiltIn(vname)
Returns true if the given identifier is a builtIn variable/function.
- Parameters:
- {String} vname
- Returns:
- {Boolean}
{Boolean}
isCreator(vname)
Checks if the given variable name is a valid creator method.
- Parameters:
- {String} vname
- Returns:
- {Boolean}
{Number}
isLocalVariable(vname)
Checks if the given variable name can be found in JXG.JessieCode#sstack.
- Parameters:
- {String} vname
- Returns:
- {Number} The position in the local variable stack where the variable can be found. -1 if it couldn't be found.
{Boolean}
isMathMethod(vname)
Checks if the given variable identifier is a valid member of the JavaScript Math Object.
- Parameters:
- {String} vname
- Returns:
- {Boolean}
{Number}
L(e)
This is used as the global L() function.
- Parameters:
- {JXG.Line} e
- Returns:
- {Number}
letvar(vname, value)
Assigns a value to a variable in the current scope.
- Parameters:
- {String} vname
- Variable name
- {%} value
- Anything
{Number|Array}
mul(a, b)
Multiplication of vectors and numbers
- Parameters:
- {Number|Array} a
- {Number|Array} b
- Returns:
- {Number|Array} (Inner) product of the given input values.
node(type, value, children)
Create a new parse tree node.
- Parameters:
- {String} type
- Type of node, e.g. node_op, node_var, or node_const
- value
- The nodes value, e.g. a variables value or a functions body.
- {Array} children
- Arbitrary number of child nodes.
parse(code, geonext)
Parses JessieCode
- Parameters:
- {String} code
- {Boolean} geonext Optional, Default: false
- Geonext compatibility mode.
replaceIDs(node)
Traverses through the given subtree and changes all values of nodes with the replaced flag set by
JXG.JessieCode#replaceNames to the name of the element (if not empty).
- Parameters:
- {Object} node
replaceNames(node)
Traverses through the given subtree and changes all elements referenced by names through referencing them by ID.
An identifier is only replaced if it is not found in all scopes above the current scope and if it
has not been blacklisted within the codeblock determined by the given subtree.
- Parameters:
- {Object} node
setProp(what, value, value)
Sets the property what of JXG.JessieCode#propobj to value
- Parameters:
- {String} what
- {%} value
- value
snippet(code, funwrap, varname, geonext)
Parses a JessieCode snippet, e.g. "3+4", and wraps it into a function, if desired.
- Parameters:
- {String} code
- A small snippet of JessieCode. Must not be an assignment.
- {Boolean} funwrap
- If true, the code is wrapped in a function.
- {String} varname
- Name of the parameter(s)
- {Boolean} geonext Optional, Default: false
- Geonext compatibility mode.
{String}
utf8_encode(string)
Encode characters outside the ASCII table into HTML Entities, because JavaScript or JS/CC can't handle a RegEx
applied to a string with unicode characters.
- Parameters:
- {String} string
- Returns:
- {String}
{%}
V(e)
This is used as the global V() function.
- Returns:
- {%}
{Number}
X(e)
This is used as the global X() function.
- Returns:
- {Number}
{Number}
Y(e)
This is used as the global Y() function.
- Returns:
- {Number}