Finite state machine calculator
The spelling accepted by the parser:
1. Multiplication:
α*x; x*α; αx; xα
2. Addition:
x₁+x₂; x₁-x₂
3. Letters of the Latin alphabet:
a, b, c, d, ...
4. Arabic numerals:
0, 1, 2, ...
Examples of function input (the maximum number of variables is 32):
2*n+3*m-5
2*n+3*m-5
n*3+m3-5
Basis:
1. A term without a variable will change for each state of a finite automaton
2. The initial state is a summand without a variable
3. The name of the state is indicated as a sign before the numeric value and the numeric value of the term itself without a variable. Example: "+1", "-3"
4. The state in which there is no summand without a variable is denoted as the state "+0".
Solution algorithm:
1. Replace some set of bits with the places of variables
2. Calculate the expression and store the resulting value in decimal notation
1. If the calculated value is greater than or equal to 0, proceed to step 5 (operation sign - "+")
4. If the calculated value is less than 0 (operation sign - "-"). The resulting numeric value is a multiple of 2?
a) yes. Go to step 5
b) no. Add 2 to the numeric value and then operate with this sum. Example: if we got "-5", then we add 2 to 5 and get 7
5. Translate the numeric value into binary notation
6. Disable the last bit, its value will be the output value when switching from one state to another according to the current set of variable bits
7. We translate the remaining sequence of bits into decimal notation
8. The state to which we move from the current one with the help of this set of variable bits has the name of the operation sign and the numeric value obtained at step number seven
9. Repeat steps 1-8 for all possible bitsets for variables
10. Repeat steps 1-9 until new states stop appearing