Skip to content

Parser

Mathy parses token arrays into inspectable, transformable, visualizable symbolic trees.

Motivation

A Token array verifies that text maps to some known set of symbols, but not that they are a correct ordering that produces a valid mathematical expression. The mathy Parser class converts tokens into a tree while also validating that the tree follows the expected Order of Operations.

Examples

To help better understand what the parser does, consider a few examples of expressions and their visualized trees:

Text Tree
4x 4 x *
4x / 2y^7 4 x * 2 y 7 ^ * /
4x + (1/3)y + 7x 4 x * 1 3 / y * + 7 x * +
4x + 1/3y + 7x 4 x * 1 3 y * / + 7 x * +
(28 + 1j)(17j + 2y) 28 1 j * + 17 j * 2 y * + *

Last update: November 22, 2020