Skip to content
/ rpn Public

Implementation of Reverse Polish Notation (RPN) or Shunting-yard algorithm + unary operator support.

Notifications You must be signed in to change notification settings

tbttin/rpn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Sep 12, 2024
41a297d · Sep 12, 2024

History

20 Commits
Sep 10, 2024
Jul 25, 2024
Jul 22, 2024
Jul 28, 2024
Sep 12, 2024
Jul 25, 2024

Repository files navigation

About

  • By using Shunting-yard algorithm rpn can evaluate a mathematics expression, that includes:

    • Multiple digits number (floating point)

    • Opearators (+, -, unary -, unary +, *, /)

    • Parentheses

    Plus:

    • Invalid parentheses check

    • Invalid operators check

Build

  • On Linux (Arch Linux), inside the rpn top level directory:
make

Run

./build/rpn

or

make run

TODO

  • Optional multi-threads.

  • Support unary minus operator.

    • Redesign unary relations?
  • Add debugging utilities.

    • Command line args support.

    • Enable/disable debug with command line option or environment variables.

    • Debug level as a flag to enable debugging a specific function.

    • Log file.

  • Implicit multiplication

    • 2(3+4)5

    • (1+2)(2+3)

    • Whenever there is no operator, it is multiplication?

  • Support function operators (sin, cos, .etc)?

  • Support portability.

  • A development branch.

What Did I Learn From Writing The rpn

  • I learned how to design and construct data type like a struct that can hold both operands (numbers) and operators (operator ids).

  • Data type (Node) and Stack are separable.

    • stack.h can be use as a library.
  • Yeah, I decided to avoid dynamic memory allocation, it require a lot of (multi-layers) memory management.

    I chose to stick with automatic memory allocation and static memory allocation, they are simple.

  • Operation orders in mathematics and in computer are not the same, there is no "standard rule".

    But there might have one: whenever it is ambiguous, just use parentheses.

  • Working with mathematics expression, it reinforces my mathematics area a little bit (it was really weak already).

About

Implementation of Reverse Polish Notation (RPN) or Shunting-yard algorithm + unary operator support.

Topics

Resources

Stars

Watchers

Forks