simple-math-ast
Introduction
Simple Math AST serves two purposes:
- Splitting math expression into the array of smallest units (tokens).
- Building Math AST using tokens via Shunting-Yard Algorithm
Read my blog posts about tokenizer & parser construction
Math AST: Tokenizer
Math AST: Parser
Install
npm install @djthoms/simple-math-ast
yarn add @djthoms/simple-math-ast
pnpm add @djthoms/simple-math-ast
Use
Code example
import { build } from "@djthoms/simple-math-ast";
const tree = build("2.5 * x + (sin(pi / 2) / cosx) ^ 3 - 4 * 2");
console.log(tree);
import { tokenize } from "@djthoms/simple-math-ast/tokenize";
import { tokenize } from "@djthoms/simple-math-ast";
const tokens = tokenize("2.5 * x + (sin(pi / 2) / cosx) ^ 3 - 4 * 2");
console.log(tokens);
Credits & Acknowledgements
Originally written by
Esimov Miras.