A calculator for expressions with predefined grammar, including basic calcualtions, let statements, if statements, and function calls. The expressions can be typed in or imported from existing files.
- Add:
<expression1> + <expression2>
- Multiply:
<expression1> * <expression1>
- Variable (only accept alphabetic words): ,
x
,var
, ... - Let:
_let x = 3 _in x + 1
, ... - Bool:
_true
&_false
, ... - Comparison:
<expression1> == <expression2>
- If:
_if _true _then 0 _else 1
,_if x == 5 _then x + 1 _else x
, - Function:
_fun(x) x + 1
, ... - Function call:
(_fun(x) x + 1)(1)
,_let f = _fun(x) x + 1 _in f(1)
, ...
- clone the repo:
git clone https://github.com/Sonia-96/Expression_Calculator_in_CPP
- open
Calculator/Calculator.pro
file
Calculate the result of an expression. For example, the result of Fibonacci(10) is 55.
Print an expression in a nicer format. In the following example, the statements will be aligned and the redundant brackets will be removed through Pretty Print
mode.