Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 596 Bytes

README.md

File metadata and controls

30 lines (21 loc) · 596 Bytes

Ruby arithmetic calculator

A basic arithmetic calculator implemented in Ruby

Consists of:

  • Lexer (converts input string to array of tokens)
  • Parser (converts array of tokens to RPN)
  • Evaluator (evaluates RPN expression)

Supports following arithmetic operations:

  • + (addition)
  • - (subtraction)
  • / (division)
  • * (multiplication)
  • ^ (exponentiation)
  • log (taking the logarithm)

Usage:

ruby app.rb [expression]

Example:

ruby app.rb "log 100 10 * ((4 - 7) ^ (3 + 1) / 4)"