COMMAND LINE CALCULATOR

WORK BY SAHANA HP AND ROHIT K

sahana hp
3 min readMay 31, 2021

Guided By, Dr. Anbunathan Ramaiah

“A compiler design project done in most efficient way to the most useful applications”

ABSTRACT

A command line calculator which supports mathematical expressions with scientific functions is very useful for most developers. The calculator available with Windows does not support most scientific functions. Most of the time, I do not feel comfortable with the calculator available with Windows. I needed a calculator which will not restrict writing expressions. I use variables to store results. Every time I need a simple calculation, I have to face problems with the Windows calculator. To make such a calculator, I designed a complete Mathematics library with MFC. The most difficult part I found when designing such a calculator was the parsing logic. Later while working with .NET, the runtime source code compilation made the parsing logic easy and interesting. I read some articles on .NET CodeDOM compilation. And I decided to write a new command line calculator using CodeDOM. It uses runtime compilation and saves the variables by serializing in a file. Thus you can get the values of all the variables used in the previous calculation.

PROBLEM STATEMENT

In this command line calculator, the result is saved in a pre-defined variable called ans. The user can declare his/her own variables to store results and can use it later in different expressions. The validation of the variable name is the same as in C#. Similarly, expression support is the same as supported in C# .NET.

The calculate function calculates an expression. It uses the saved variables. I have generated code which has a declaration of the variables.

To Evaluate the given expressions.

To perform basic calculations

S/W & H/W REQUIREMENTS

Software Requirements:

  • C compiler (gcc, cc, egcs,..)

Hardware Requirements:

  • CPU : Intel Core i5
  • Memory : 8GB for RAM

ALGORITHM

Step 1 — START

Step 2 — input

Step 3 — parse_expr()

step 3.1 parse_term()

step 3.1.1 parse_factor()

step 3.2 parse_num_op()

step 3.2.1 parse_rest_term()

step 3.3 parse_factor()

step 3.3.1 parse_num_op()

step 3.4 parse_rest_term()

step 3.4.1 parse_rest_expr()

Step 4 — STOP

OUTPUT SCREEN SHOTS

CONCLUSION AND FUTURE ENHANCEMENTS

This is a powerful and versatile command-line calculator that really lives up to your expectation. Preloaded on all modern Linux distributions, this can make your number crunching tasks much easier to handle without leaving your terminals. Besides, if your shell script requires floating point calculation, can easily be invoked by the script to get the job done. All in all, CLC should definitely be in your productivity tool set.

References

[1] — https://www.codeproject.com/Articles/12395/A-Command-Line-Calculator

[2] — https://fedoramagazine.org/bc-command-line-calculato

--

--