diff options
author | scratko <m@scratko.xyz> | 2024-04-01 19:53:45 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-04-01 19:53:45 +0300 |
commit | 8a704989e2d4733e6e847cb272a40dd85de4c9cd (patch) | |
tree | a58c0d57316361083b7662e2e19251f5288adaf4 | |
parent | 7d07ff825dc7cff7ee80b04346e0d2c49a91e190 (diff) | |
download | arithmetic-expression-computator-8a704989e2d4733e6e847cb272a40dd85de4c9cd.tar.gz arithmetic-expression-computator-8a704989e2d4733e6e847cb272a40dd85de4c9cd.tar.bz2 arithmetic-expression-computator-8a704989e2d4733e6e847cb272a40dd85de4c9cd.zip |
update README
-rw-r--r-- | README.md | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -1,3 +1,43 @@ # Arithmetic expression computator <img src="arithmetic-expression-computator.png" /> + +## Introduction + +Remarkably, this program is written in C without using library features at all. +Assembler modules are used for program entry point and system call wrappers. + +This program is based on two algorithms: reverse polish notation (RPN) and +Dijkstra's algorithm. + +Any arithmetic expression can be calculated. To do this, the expression needs to +be represented in an RPN, in that operands are written first, then +the operation sign; operands can be any complex expressions. +For example, the expression `(x+y)*(1-z)` in RPN would be written as: x y + 1 z - +\*. All this is calculated using the stack. + +To translate an arithmetic expression from traditional infix notation to RPN we +need to use Dijkstra's algorithm. +The stack is also used here, but a new one. +According to this algorithm, the initial expression is viewed from left to +right. The elements are written out either to the RPN stack or to the operation +stack (for Dijkstra's algorithm). While viewing the expression, open brackets +and operation symbols (in some cases) are inserted into the operation stack, and +operands as well as operation symbols (again, in some cases) are inserted into +the RPN stack. The algorithm is described in more detail in the book А.В. +Столяров "Программирование: введение в профессию" (том 1, ДМК Пресс, стр. 644). + +## Building and usagea + +``` +git clone https://git.scratko.xyz/arithmetic-expression-computator +cd arithmetic-expression-computator +make +``` +Launch the program `./arith_exp` +After starting, enter an arithmetic expression. + +Notes: +- the expression must not contain any space characters +- negative values must be surrounded by brackets +- you can see an example of the expression on the screenshot above. |