Version: 0.0.20.1.00.2.00.3.00.4.00.5.00.6.00.7.00.7.10.7.20.8.00.8.10.8.20.9.00.9.10.10.00.11.00.11.10.12.00.12.10.13.00.14.00.15.00.16.00.17.00.17.10.18.00.18.10.19.00.20.00.21.00.21.10.22.00.23.00.24.10.25.00.26.00.27.01.0.01.0.11.1.01.1.11.2.01.3.01.4.01.5.01.5.11.5.21.6.01.7.01.7.12.0.02.0.12.1.02.1.12.2.02.3.02.4.02.4.12.4.22.5.02.6.02.7.03.0.03.1.03.1.13.1.23.1.33.1.43.2.03.2.13.3.03.4.03.4.13.5.03.5.13.5.23.5.33.6.03.7.03.8.03.8.13.9.03.9.13.9.23.9.33.10.03.10.13.10.23.10.33.11.03.11.13.11.23.11.33.11.43.11.53.12.03.12.13.12.23.12.33.13.03.13.13.13.23.13.33.14.03.14.13.14.23.15.03.16.03.16.13.16.23.16.33.16.43.16.53.17.03.18.03.18.13.19.03.20.03.20.13.20.24.0.0-rc.14.0.0-rc.24.0.04.0.14.1.04.1.14.1.24.2.04.2.14.2.24.3.04.4.04.4.14.4.25.0.05.0.15.0.25.0.35.0.45.1.05.1.15.1.25.2.05.2.15.2.25.2.35.3.05.3.15.4.05.4.15.4.25.5.05.6.05.7.05.8.05.9.05.10.05.10.15.10.25.10.36.0.0-beta.06.0.0-beta.16.0.0-beta.26.0.0-beta.36.0.06.0.16.0.26.0.36.0.46.1.06.2.06.2.16.2.26.2.36.2.46.2.56.3.06.4.06.5.06.6.06.6.16.6.26.6.36.6.46.6.57.0.07.0.17.0.27.1.07.2.07.3.07.4.07.5.07.5.17.6.08.0.0-beta.08.0.0-beta.18.0.08.0.18.1.08.1.19.0.09.1.09.2.09.3.09.3.19.3.29.4.09.4.19.4.29.4.39.4.49.4.59.5.09.5.19.5.210.0.010.0.110.0.210.1.010.1.110.2.010.3.010.4.010.4.110.4.210.4.310.5.010.5.110.5.210.5.310.6.010.6.110.6.210.6.310.6.411.0.011.0.111.1.011.2.011.2.111.3.011.3.111.3.211.3.311.4.011.5.011.5.111.6.011.7.011.8.011.8.111.8.211.9.011.9.111.10.011.10.111.11.011.11.111.11.211.12.012.0.012.1.012.2.012.2.112.3.012.3.112.3.212.4.012.4.112.4.2
import { factory } from '../../utils/factory'
const name = 'parser'
const dependencies = ['typed', 'Parser']
export const createParser = /* #__PURE__ */ factory(name, dependencies, ({ typed, Parser }) => {
/**
* Create a parser. The function creates a new `math.Parser` object.
*
* Syntax:
* math.parser()
* Examples:
* const parser = new math.parser()
* // evaluate expressions
* const a = parser.evaluate('sqrt(3^2 + 4^2)') // 5
* const b = parser.evaluate('sqrt(-4)') // 2i
* const c = parser.evaluate('2 inch in cm') // 5.08 cm
* const d = parser.evaluate('cos(45 deg)') // 0.7071067811865476
* // define variables and functions
* parser.evaluate('x = 7 / 2') // 3.5
* parser.evaluate('x + 3') // 6.5
* parser.evaluate('function f(x, y) = x^y') // f(x, y)
* parser.evaluate('f(2, 3)') // 8
* // get and set variables and functions
* const x = parser.get('x') // 7
* const f = parser.get('f') // function
* const g = f(3, 2) // 9
* parser.set('h', 500)
* const i = parser.evaluate('h / 2') // 250
* parser.set('hello', function (name) {
* return 'hello, ' + name + '!'
* })
* parser.evaluate('hello("user")') // "hello, user!"
* // clear defined functions and variables
* parser.clear()
* See also:
* evaluate, compile, parse
* @return {Parser} Parser
*/
return typed(name, {
'': function () {
return new Parser()
}
})