A small calculator like Eval()

by lighfu

Version 1 (December 9, 2021)

Download (19 downloads)

Demonstration of four arithmetic operations

The entire flowchart consists of 29 blocks.

🌠 Free!

In this flowchart, the four arithmetic operations are compressed as much as possible.
Therefore, you cannot use the following format.

(1) Omission of multiplication
ex, 10 (2 + 2)

* It is possible in the following cases.
ex, 10 * (2 + 2)

(2) Elements other than the four arithmetic operations
ex, 2 ^ 3 + abs (-10)

- Pow calculation is not supported.
- Functions cannot be used.

(3) divided by zero
There is no error handling when divided by zero. So it's a bug.

How to)

Use the ternary operator.
With this, you feel as if you were writing an IF statement or a Switch statement.

In this flow chart, the ternary operator in the four "Variable set" blocks greatly reduces the number of blocks.

① Detection of the appropriate position of the four arithmetic operators.
② Acquire while calculating the left and right sides a little.
③ Calculated according to the priority of the operator.
④ Delete blanks other than string literals.

These three are processed using the ternary operator and Dictionary.

It looks pretty bad.




🌠 Freeでも実行できます!


① 乗算省略
ex, 10(2+2)

ex, 10 * (2+2)

② 四則演算以外の要素
ex, 2^3 + abs(-10)


③ ゼロで割る


三項演算子 を使用します。

このフローチャートでは、4つの「Variable set」ブロック内の三項演算子が、大きくブロック数を減少させています。

① 四則演算子の適切な位置の検出
② 左辺、右辺を少し計算しながら取得する
③ 演算子の優先順位 に応じて計算
④ 文字列リテラル以外の空白削除

この3つを 三項演算子とDictionary を活用して処理しています。



2021/12/10: v1 upload