PolStringConvertor is a Python package that provides utilities to convert infix expressions into postfix and prefix forms, and to evaluate postfix expressions. It also includes validation of infix expressions.
- Validate infix expressions for proper operator placement and balanced parentheses.
- Convert infix expressions to postfix notation.
- Convert infix expressions to prefix notation.
- Evaluate postfix expressions.
To install the package, use pip:
pip install PolStringConvertorThis package requires the StrTokenizer package version 1.1.0 to function properly. It will be installed automatically when you install PolStringConvertor.
Here’s how to use the main features of the package:
from PolStringConvertor import isExpressionValid
expression = "(a+b)*c"
print(isExpressionValid(expression)) # Returns True or Falsefrom PolStringConvertor import infixToPostfix
expression = "(a+b)*c"
postfix = infixToPostfix(expression)
print(postfix) # Output: ['a', 'b', '+', 'c', '*']from PolStringConvertor import infixToPrefix
expression = "(a+b)*c"
prefix = infixToPrefix(expression)
print(prefix) # Output: ['*', '+', 'a', 'b', 'c']from PolStringConvertor import evaluatePostfixExpression
postfix = ['3', '4', '+', '2', '*', '7', '/']
result = evaluatePostfixExpression(postfix)
print(result) # Output: 2.0from PolStringConvertor import *
expression = "(a+b)*c"
print(isExpressionValid(expression)) # Returns True or False
postfix = infixToPostfix(expression)
print(postfix) # Output: ['a', 'b', '+', 'c', '*']
prefix = infixToPrefix(expression)
print(prefix) # Output: ['*', '+', 'a', 'b', 'c']
postfix = ['3', '4', '+', '2', '*', '7', '/']
result = evaluatePostfixExpression(postfix)
print(result) # Output: 2.0You can install the PolStringConvertor package from PyPI:
Install PolStringConvertor from PyPI
This project is licensed under the MIT License.