Git Product home page Git Product logo

rpn-calculator's Introduction

rpn-calculator

dc command-like to compute rpn - Reverse Polish notation expression.

Download and run

To download the repo, you can either download the .zip file for this project, or use git commands as bellow :

$ git clone https://github.com/GouruRK/rpn-calculator.git

This repo uses the readline library. Donwload it with

$ sudo apt-get install libreadline-dev.

To compile it, go in the rpn-calculator folder and run the make command to compile it. It creates an executable rpn.

$ cd rpn-calculator
$ make
$ ./rpn

Examples

$ ./rpn
1 3 p + 4 * p q
3
16
$ ./rpn
p c a 1 a c a c 0 r 1 r / % ^ a 3 ^ a 3 r ^ a 42 1984 a - - - - a 1947 - a ! 5 + ! a q
rpn: stack empty
[] <- HEAD
[1] <- HEAD
[] <- HEAD
rpn: stack empty
rpn: divide by 0
rpn: divide by 0
[1] <- HEAD
[1] <- HEAD
[3] <- HEAD
[3, 42, 1984] <- HEAD
rpn: stack empty
rpn: stack empty
[1945] <- HEAD
[-2] <- HEAD
rpn: factorial of negative number
[6] <- HEAD

How to use

  • Tokens must be separated by spaces or new lines
  • Relatives numbers must be written as -a
  • This implementation does not support floating numbers
  • If computing a sequence triggers an error, the stack stays untouched

Supported operation

Operation Input Calculated
+ a b + a + b
- a b - a - b
* a b * a * b
/ a b / a / b
% a b % a % b
^ a b ^ a ^ b
! a ! a!

Supported commands

  • a : Print the stack
  • p : Print the first element of the stack
  • r : Reverse the top two elements of the stack
  • c : Clear the stack
  • q : Quit

rpn-calculator's People

Contributors

goururk avatar

Stargazers

Cyanne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.