The program must translate algebraic expression into a list of commands in assembly language.
An algebraic expression may contain lowercase and uppercase letters, as well as "+", "-", "*", "/", "(", ")". Example: "A + Bc * (aB)"
The computer has 10 registers - memory cells (R0..R9) and one adder. Each command in the sequential list of commands begins with a new line and contains the command code itself (I will describe the commands below) and, after the space, the operand (the variable name or register). Commands:
Команда: L операнд Смысл: сумматор := операнд Команда: A операнд Смысл: сумматор := сумматор + операнд Команда: S операнд Смысл: сумматор := сумматор - операнд Команда: M операнд Смысл: сумматор := сумматор * операнд Команда: D операнд Смысл: сумматор := сумматор / операнд Команда: ST регистр Смысл: регистр := сумматор
There are two files: input.txt and output.txt
input.txt contains the algebraic expression itself (no more than 100 characters), which can be calculated using no more than 10 registers.
output.txt must contain a sequence of assembler language commands, as a result of which the resulting value is placed in the adder. The assembler program must contain all the operations of the expression (without saving operations).
Example: input.txt
A*BC*(B+X)
output.txt
LA или LB MBAX ST R0 MC LB ST R1 AXLA ST R1 MB LCS R1 M R1 ST R1 L R0 S R1
I understood the very meaning of the task, but I don’t even know how to start it. Based on the example, most likely, you need to start with a search for opening parentheses, perform lower priority operations first, but which data structures are better to use and the solution algorithm itself is not yet clear.
(
and decreasing when)
And then went through in the order of decreasing priorities, capturing the operands to the left and right of the operation and building the execution tree - Mike