Skip to content

A basic implementation of the Polish notation evaluation algorithm on Wikipedia.

License

Notifications You must be signed in to change notification settings

ethan-t/polish-notation-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polish Notation Calculator

A calculator, written in Python, that evaluates mathematical expressions written in Polish notation. It implements the following algorithm that processes the expression left to right, taken from Wikipedia:

for each token in the prefix expression:
  if token is an operator:
    push token onto the operator stack
    pending_operand ← False
  else if token is an operand:
    operand ← token
    if pending_operand is True:
      while the operand stack is not empty:
        operand_1 ← pop from the operand stack
        operator ← pop from the operator stack
        operand ← evaluate operator with operand_1 and operand
    push operand onto the operand stack
    pending_operand ← True
result ← pop from the operand stack

Stack

This was essentially created to use the Stack implementation from my algorithms repository.

Todo (maybe)

  • Support for parentheses
  • More operations

About

A basic implementation of the Polish notation evaluation algorithm on Wikipedia.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages