0.12.1 • Published 4 years ago
Quick Start
const compiler = require('math-compiler')
// compiling
const { compile } = compiler
compile.list // [ 'basic-infix -> basic-prefix', 'basic-infix -> basic-postfix' ]
compile('basic-infix', 'basic-postfix', 'a + b^(c - d)')) // 'a b c d - ^ +'
// lexing
const { lex } = compiler
lex.list // [ 'basic-infix', 'basic-prefix', 'basic-postfix' ]
lex('basic-infix', 'a + b^(c - d)') // [ IdentifierToken { value: 'a' }, OperatorToken { value: '+' }, ... ]
// parsing
const { parse } = compiler
parse.list // [ 'basic-infix', 'basic-prefix', 'basic-postfix' ]
parse('basic-infix', 'a + b^(c - d)') // OperationNode { operator: '+', ... }
// transforming
const { transform } = compiler
transform.list // [ 'basic-infix', 'basic-prefix', 'basic-postfix' ]
transform('basic-infix', OperationNode) // AST (abstract syntax tree)
// generating
const { generate } = compiler
generate.list // [ 'basic-infix', 'basic-prefix', 'basic-postfix' ]
generate('basic-infix', AST) // 'a + b ^ ( c - d )'
Formats
Notes
- Formats with the prefix "basic" have limited functionality and are for educational purposes only.
Compilers
from | to |
---|
'basic-infix' | 'basic-prefix' |
'basic-infix' | 'basic-postfix' |
'basic-infix' | 'exomath' |
'basic-infix' | 'mathcad-prefix' |
'basic-prefix' | 'basic-postfix' |
'basic-prefix' | 'exomath' |
'basic-prefix' | 'mathcad-prefix' |
'basic-postfix' | 'basic-prefix' |
'basic-postfix' | 'exomath' |
'basic-postfix' | 'mathcad-prefix' |
'exomath' | 'mathcad-prefix' |
'mathcad-prefix' | 'exomath' |
Lexers
from |
---|
'basic-infix' |
'basic-prefix' |
'basic-postfix' |
'exomath' |
'mathcad-prefix' |
Parsers
from |
---|
'basic-infix' |
'basic-prefix' |
'basic-postfix' |
'exomath' |
'mathcad-prefix' |
Transformers
from |
---|
'basic-infix' |
'basic-prefix' |
'basic-postfix' |
'exomath' |
'mathcad-prefix' |
Generators
to |
---|
'basic-prefix' |
'basic-postfix' |
'exomath' |
'mathcad-prefix' |
Future Formats
Installation
NPM
$ npm i math-compiler
Yarn
$ yarn add math-compiler