A small calculator like Eval()

by lighfu

Version 1 (December 9, 2021)

Download (42 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.


ーー


四則演算のデモ

フローチャート全体は29ブロックで構成されています。

🌠 Freeでも実行できます!


このフローチャートでは、四則演算を可能な限り圧縮して処理しています。
そのため以下のような書式を使用することはできません。

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

*以下の場合は可能です。
ex, 10 * (2+2)

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

・べき計算は対応していません。
・関数を使用することはできません。

③ ゼロで割る
ゼロで割った場合のエラー処理はありません。なのでバグります。


仕組み)

三項演算子 を使用します。
これを使用すると、まるで、IF文や、Switch文を書いているような気分になります。

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

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

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

かなり見た目が悪いですが。


_____________

2021/12/10: v1 upload

5.0 average rating from 2 reviews

5 stars
2
4 stars
0
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.