Skip to content

JRB-y/shunting-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Shunting Algorithm js

Shunting-yard algorithm

Parsing mathematical expressions in infix to produce a postfix notation.

1+1   -> 11+
1*2+3 -> 12*3+
1+2*3 -> 123*+
const out = infixToPostfix('1+1+2');
console.log(out);
// {
//   tokens: [
//     { type: 'symbol', val: 1, lab: '1' },
//     { type: 'symbol', val: 1, lab: '1' },
//     { type: 'op', val: [Function: val], precedence: 1, lab: '+' },
//     { type: 'symbol', val: 2, lab: '2' },
//     { type: 'op', val: [Function: val], precedence: 1, lab: '+' }
//   ],
//   toString: '11+2+',
//   eval: 4
// }

TODO

  • from infix to prefix
  • from prefix to infix
  • from postfix to infix
  • write tests

About

Parsing mathematical expressions in infix to produce a postfix notation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published