Infix and Postfix Numeric Expressions

This project may need some explanation by an instructor

Introduction

A numerical expression is a mathematical statement that involves numbers and operation symbols.

Infix expressions are characterized by the placement of operators between operands. (e.g. 6 + 3)

Postfix expressions are characterized by placement of operators after the operands. (e.g. 6 3 +)

Reverse Polish notation (RPN) is postfix notation.

The description "Polish" refers to the nationality of logician Jan Ɓukasiewicz, who invented Polish notation in 1924.

For example:

Infix
Expression
ResultsReverse Polish
Notation
Expression
Notes
5 + 2 + 8 155 2 + 8 + same operator precedence
5 + 2 * 8 215 2 8 * + different operator precedences
(5 + 2) * 8 565 2 + 8 * sub-expression
2 ** 4 + 5212 4 ** 5 + mult-character (**) operator
(10 / 2) * 315 10 2 / 3 *sub-expression
((2 * 3) - (4 - 8 * 2))18 2 3 * 4 8 2 * - -sub-expression
((2 * 3) - (4 * 8 - 2))-24 2 3 * 4 8 * 2 - -sub-expression
2**3 - 4 * 20 2 3 ** 4 2 * -mult-character (**) operator

For hints, code examples, etc. click HERE .

Project #0a

What is the difference between the Python "collections.deque" and "Queue" modules?

Project #0b

Using the Python "collections.deque" module, create a stack class (LIFO queue). Implement the following methods:

Note: TOS is Top Of Stack.

Create an interactive program to demonstrate the stack methods.

Are there any other methods that are needed?

Project #0c

Using the Python "collections.deque" module, create a queue class (FIFO queue). Implement the following methods:

Note: FOQ = Front Of Queue; BOQ = Back Of Queue.

Create an interactive program to demonstrate the queue methods.

Are there any other methods that are needed?

Project #0d

Create an interactive program to tokenize an infix numerical expression.

  1. ask the user to enter an infix numeric expression
  2. parse the infix expression into tokens (operators and operands)
  3. display the tokens
Use the tokenizer code found HERE .

Project #0e

Define "syntax" and "semantics" as they relate to computer programming languages.

Project #1

Create an interactive program to convert an infix numeric expressions
to a Reverse Polish Notation (RPN) numeric expressions.

  1. ask the user to enter an infix numeric expression (string)
  2. parses the infix expression into tokens (strings)
  3. using the tokens, create a Reverse Polish Notation numeric expression (string)
    (a single string with tokens separated by a space)
  4. display the results
  5. loop

Code the algorithm found HERE .

Project #2

Expand the project

  1. convert to a GUI
  2. add scientific notation (i.e. -3.1415E-3)

Links

Infix notation (Wikipedia)

Reverse Polish notation (Wikipedia)

Shunting yard algorithm (Wikipedia)

Infix, Postfix and Prefix Expressions/Notations

Operator Precedence in Python

Converting infix to RPN (shunting-yard algorithm)

Rules to Convert Infix to Postfix (Reverse Polish) Expression using a Stack (YouTube)

How to convert Infix expressions to Reverse Polish Notation expressions (Youtube)