PrefixParser

Namespace

JXG.PrefixParser namespace provides a prefix expression parser, i.e. a poor man's parser. This is a simple prefix parser for measurements and expressions of measurements, see Measurement. An expression is given as

  • array starting with an operator as first element, followed by one or more operands,
  • number.

Possible operators are:

  • '+', '-', '*', '/': binary operators
  • 'Area', 'Radius', 'Value', 'V', 'L': arbitrary methods of JSXGraph elements, supplied as strings.
  • 'exec': call a function

Possible operands are:

  • numbers
  • strings
  • JSXGraph elements in case the operator is a method. Example: ['Area', circle] calls the method Circle.Area.
  • prefix expressions (for binary operators)
  • 'exec': call functions. Example: ['exec', 'sin', ['V', slider]] computes Math.sin(slider.Value()). As functions only functions in Math or JXG.Math are allowed.
Methods

Own

(static) dimension(term)

Determine the dimension of the resulting value, i.e. ['L', obj] as well as ['+', ['L', obj1], ['L', obj2]] have dimension 1.

['+', ['Area', obj1], ['L', obj2]] will retrun NaN, because the two operands have conflicting dimensions.

If an element is a measurement element, then it's dimension can be set as attribute. This overrules the computed dimension.

Parameters

Name Type Description
term Array | Number

Prefix expression

Returns

Number

Details

Source
parser/prefix.js, line 191

(private, static) getParents(term)

Determine parent elements of a prefix expression.

Parameters

Name Type Description
term Array | Number

prefix expression

Returns

Array

Details

Source
parser/prefix.js, line 360

(static) parse(term, action) → {Number}

Parse a prefix expression and apply an action.

Parameters

Name Type Description
term array | number

Expression

action String

Determines what to do. So far, the only action available is 'execute', which evaluates the expression.

Returns

What ever the action does.

Type
Number

Details

Source
parser/prefix.js, line 102

(static) toPrefix(term) → {Array|Number}

Convert a prefix expression into a new prefix expression in which JSXGraph elements have been replaced by their ids.

Parameters

Name Type Description
term Array | Number

Returns

Type
Array | Number

Details

Source
parser/prefix.js, line 319

Inherited

none

Details

PrefixParser

Source
parser/prefix.js, line 94
Examples
['+', 100, 200]
var p1 = board.create('point', [1, 1]);
var p2 = board.create('point', [1, 3]);
var seg = board.create('segment', [[-2,-3], [-2, 3]]);

// Valid prefix expression: ['L', seg]
var p1 = board.create('point', [1, 1]);
var p2 = board.create('point', [1, 3]);
var seg = board.create('segment', [[-2,-3], [-2, 3]]);
var ci = board.create('circle', [p1, 7]);

// Valid prefix expression:  ['+', ['Radius', ci], ['L', seg]]
var ang = board.create('angle', [[4, 0], [0, 0], [2, 2]]);
// Valid prefix expression:  ['V', ang, 'degrees']);