FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/src/expression/function/parser.js at develop · husayt/mathjs · GitHub
husayt
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
src
/
expression
/
function
/
parser.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (53 loc) · 1.75 KB
Breadcrumbs
mathjs
/
src
/
expression
/
function
/
parser.js
Copy path
File metadata and controls
55 lines (53 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import
{
factory
}
from
'../../utils/factory.js'
const
name
=
'parser'
const
dependencies
=
[
'typed'
,
'Parser'
]
export
const
createParser
=
/* #__PURE__ */
factory
(
name
,
dependencies
,
(
{
typed
,
Parser
}
)
=>
{
/**
* Create a `math.Parser` object that keeps a context of variables and their values, allowing the evaluation of expressions in that context.
*
* 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('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') // 3.5
* 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
(
)
}
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL