Skip to content

Arithmetical expressions parser for JavaScript. 数学者!

License

Notifications You must be signed in to change notification settings

Mazuh/mathematician

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mathematician

Arithmetical expressions parser for JavaScript. 数学者!

Available on NPM: https://www.npmjs.com/package/mathematician

Examples

It splits expressions into atomic symbols for easy programming handling.

parseExpression('-3,14 0.57 +');
// returns them:
[
  { type: SYMBOL_TYPE.NUMBER, value: -3.14 },
  { type: SYMBOL_TYPE.NUMBER, value: 0.57 },
  { type: SYMBOL_TYPE.SUM, value: null },
]

parseExpression('42c');
// throws error indexing failing token:
Error('2')

And may also safely evaluate whole expressions following postfix notation:

evalPostfix('1 1 + 2 + 3 +');
// returns the result:
7

evalPostfix('42 0 /');
// throws error messaging arithmetical inconsistency:
Error('Division by zero')

About

Arithmetical expressions parser for JavaScript. 数学者!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published