Implementation of Edsger Dijkstra's Shunting-yard algorithm
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.editorconfig
.eslintrc.json
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
main.js
package-lock.json
package.json
stryker.conf.js

README.md

infix-rpn-eval

Build Status npm version GitHub forks GitHub issues GitHub license Stryker tested Maintainability Test Coverage

A JavaScript Implementation of Edsger Dijkstra's Shunting-yard algorithm. Works in Node.js and web browsers.

Installation

$ npm install infix-rpn-eval

Usage

Tokens must be space-separated! Unary - goes with its operand, e.g. -4

var infixRpnEval = require("infix-rpn-eval");

infixRpnEval.toPostfix('2 + 3 * 3');       // '2 3 3 * +'
infixRpnEval.toInfix('2 3 3 * +');         // '2 + 3 * 3'
infixRpnEval.evaluatePostfix('2 3 3 * +'); // 11
infixRpnEval.evaluateInfix('2 + 2 * 2');   // 6

API

/**
 * Convert from infix to postfix notation
 * @param {string} infix tokens must be space separated
 * @returns {string}
 */
infixRpnEval.toPostfix = (infix) {...}

/**
 * Convert from postfix to infix notation
 * @param {string} postfix tokens must be space separated
 * @returns {string}
 */
infixRpnEval.toInfix = (postfix) {...}

/**
 * Evaluate postfix expression
 * @param {string} postfix tokens must be space separated
 * @returns {number}
 */
infixRpnEval.evaluatePostfix = (postfix) {...}

/**
 * Evaluate infix expression
 * @param {string} infix tokens must be space separated
 * @returns {number}
 */
infixRpnEval.evaluateInfix = (infix) {...}