Skip to main content

A package to convert infix expressions to postfix/prefix and evaluate them

Project description

PolStringConvertor

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.

Features

  • 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.

Installation

To install the package, use pip:

pip install PolStringConvertor

This package requires the StrTokenizer package version 1.1.0 to function properly. It will be installed automatically when you install PolStringConvertor.

Usage

Here’s how to use the main features of the package:

1. Validate an Infix Expression

from PolStringConvertor import isExpressionValid

expression = "(a+b)*c"
print(isExpressionValid(expression))  # Returns True or False

2. Convert Infix to Postfix

from PolStringConvertor import infixToPostfix

expression = "(a+b)*c"
postfix = infixToPostfix(expression)
print(postfix)  # Output: ['a', 'b', '+', 'c', '*']

3. Convert Infix to Prefix

from PolStringConvertor import infixToPrefix

expression = "(a+b)*c"
prefix = infixToPrefix(expression)
print(prefix)  # Output: ['*', '+', 'a', 'b', 'c']

4. Evaluate a Postfix Expression

from PolStringConvertor import evaluatePostfixExpression

postfix = ['3', '4', '+', '2', '*', '7', '/']
result = evaluatePostfixExpression(postfix)
print(result)  # Output: 2.0

5. Import All Functions at once

from 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.0

You can install the PolStringConvertor package from PyPI:

Install PolStringConvertor from PyPI

Source Code:

Github Link

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polstringconvertor-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

PolStringConvertor-1.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file polstringconvertor-1.0.0.tar.gz.

File metadata

  • Download URL: polstringconvertor-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for polstringconvertor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bdd93c5178fd06419a22726c501a071550b0c2dcd7d0031272338f1425943a2c
MD5 4e3299f817e5a1539d73f97c4db64963
BLAKE2b-256 5fcf11a22e37c85169fec6c17928b1ae6a61e6f3a5570be8a1e989d13a78d3ca

See more details on using hashes here.

File details

Details for the file PolStringConvertor-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for PolStringConvertor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1efc56c70a1cc69ad19345a67390bb1dfbace55c0b50341c0b306088fb8a08a
MD5 0ce7a2f39002b3542b4bbb45d4110057
BLAKE2b-256 ff4d0eba76ed4058d1e26234d177fb570b0f93a558cd6d1dfb6d03edf939be52

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page