Skip to content

shravanasati/crusade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crusade

A simple math interpreter written in C++ using the Shunting-yard algorithm.

Watch the demo video.

Working mechanism

crusade first tokenizes the given input and classifies them into numbers, operators, parentheses and so on. During this operation, it also validates the input and checks for invalid expressions like missing operators/operands/parentheses and so on.

The next step is to use the shunting yard algorithm to convert the infix expression to the reverse polish notation (aka postfix expression, eg. 1 + 2 - 3 => 1 2 + 3 -). I've also added a slight modification by providing unary operators with the highest precedence and right associativity. The evaluation of the postfix expression is pretty easy.

Build from source

make

Usage

Just launch the executable file and you'd see a prompt. Enter your expressions here and press enter.

You can type /q, exit or quit to exit the application.

You can also toggle the debug mode using the /debug command. It will show your given expression in a parenthesized manner.

You can autocomplete these commands by pressing tab.

Further Goals

  • Support for unary operators
  • Pretty output
  • Input history
  • Tab Completions
  • Functions

Acknowledgements

  1. The awesome linenoise library.