sesaparcours
    Preparing search index...

    Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate().

    Note the evaluating arbitrary expressions may involve security risks, see https://mathjs.org/docs/expressions/security.html for more information.

    Syntax:

    math.parse(expr)
    math.parse(expr, options)
    math.parse([expr1, expr2, expr3, ...])
    math.parse([expr1, expr2, expr3, ...], options)
    

    Example:

    const node1 = math.parse('sqrt(3^2 + 4^2)')
    node1.compile().evaluate() // 5
    
    let scope = {a:3, b:4}
    const node2 = math.parse('a * b') // 12
    const code2 = node2.compile()
    code2.evaluate(scope) // 12
    scope.a = 5
    code2.evaluate(scope) // 20
    
    const nodes = math.parse(['a = 3', 'b = 4', 'a * b'])
    nodes[2].compile().evaluate() // 12
    

    See also:

    evaluate, compile
    
    interface ParseFunction {
        isAlpha(c: string, cPrev: string, cNext: string): boolean;
        isDecimalMark(c: string, cNext: string): boolean;
        isDigit(c: string): boolean;
        isDigitDot(c: string): boolean;
        isHexDigit(c: string): boolean;
        isValidLatinOrGreek(c: string): boolean;
        isValidMathSymbol(high: string, low: string): boolean;
        isWhitespace(c: string, nestingLevel: number): boolean;
        (expr: MathExpression, options?: ParseOptions): MathNode;
        (exprs: MathExpression[], options?: ParseOptions): MathNode[];
    }
    • Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();

      Parameters

      Returns MathNode

      A node

    • Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate();

      Parameters

      Returns MathNode[]

      An array of nodes

    Index

    Methods

    • Checks whether the current character c is a valid alpha character:

      • A latin letter (upper or lower case) Ascii: a-z, A-Z
      • An underscore Ascii: _
      • A dollar sign Ascii: $
      • A latin letter with accents Unicode: \u00C0 - \u02AF
      • A greek letter Unicode: \u0370 - \u03FF
      • A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points

      The previous and next characters are needed to determine whether this character is part of a unicode surrogate pair.

      Parameters

      • c: string

        Current character in the expression

      • cPrev: string

        Previous character

      • cNext: string

        Next character

      Returns boolean

    • Test whether the character c is a decimal mark (dot). This is the case when it's not the start of a delimiter '.*', './', or '.^'

      Parameters

      • c: string
      • cNext: string

      Returns boolean

    • checks if the given char c is a digit

      Parameters

      • c: string

        a string with one character

      Returns boolean

    • checks if the given char c is a digit or dot

      Parameters

      • c: string

        a string with one character

      Returns boolean

    • checks if the given char c is a hex digit

      Parameters

      • c: string

        a string with one character

      Returns boolean

    • Test whether a character is a valid latin, greek, or letter-like character

      Parameters

      • c: string

      Returns boolean

    • Check whether given character c is a white space character: space, tab, or enter

      Parameters

      • c: string
      • nestingLevel: number

      Returns boolean