infix-to-postfix-converter

1.0.0 • Public • Published

Infix to Postfix Converter

This is a simple infix to prefix generator that also logs the steps of the conversion.

Check the link to see an example: https://infix-to-postfix-converter.vercel.app/

To convert an expression:

Features

  • Checks for empty expressions
  • Accepts Alphanumeric characters as operands
  • Checks if expression contains anything that is not Alphanumeric or not a math operator
  • Timeline for every step in the conversion.

Usage/Examples

const converter = require("infixtopostfix");

let expression = new converter()

console.log(expression.convert("3+2+7"))
//32+7+

console.log(expression.getLog())
/*
┌─────────┬─────────┬──────────────┬────────────────────────────────────────────────────────┐                           
│ (index) │    0    │      1       │                           2                            │                           
├─────────┼─────────┼──────────────┼────────────────────────────────────────────────────────┤                           
│    0    │   '3'   │ 'Stack: []'  │                      "print('3')"                      │                           
│    1    │   '3'   │ 'Stack: [+]' │                      "push('+')"                       │                           
│    2    │  '32'   │ 'Stack: [+]' │                      "print('2')"                      │                           
│    3    │  '32+'  │ 'Stack: []'  │                  "pop('+') and print"                  │                           
│    4    │  '32+'  │ 'Stack: [+]' │                      "push('+')"                       │                           
│    5    │ '32+7'  │ 'Stack: [+]' │                      "print('7')"                      │                           
│    6    │ '32+7'  │ 'Stack: [+]' │ 'popping and printing remaining elements in the stack' │                           
│    7    │ '32+7+' │ 'Stack: []'  │                   'pop(+) and print'                   │                           
│    8    │ '32+7+' │ 'Stack: []'  │                   'Conversion Done'                    │                           
└─────────┴─────────┴──────────────┴────────────────────────────────────────────────────────┘ 

getLog() will return a list so use it after convert() or it will return an empty list.
*/

Readme

Keywords

Package Sidebar

Install

npm i infix-to-postfix-converter

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

8.42 kB

Total Files

3

Last publish

Collaborators

  • aceburgundy