# Transformation of algebraic expression into the assembler language

• The programme should translate the algebraic expression into the list of teams in the assembler language.

Algebraic expression can contain Latin strings and capital letters as well as "+," "," "," "(,"") Example: "A+B-c*(a-B)

The computer has 10 registers - memory cells (R0.R9) and one. Each team on the sequenced command list begins with a new line and contains the code of the team itself (the commanders will describe below) and, through the gap, the orange (the name of the variable or the register). Teams:

``````Команда: L операнд Смысл: сумматор := операнд
Команда: A операнд Смысл: сумматор := сумматор + операнд
Команда: S операнд Смысл: сумматор := сумматор - операнд
Команда: M операнд Смысл: сумматор := сумматор * операнд
Команда: D операнд Смысл: сумматор := сумматор / операнд
Команда: ST регистр Смысл: регистр := сумматор
``````

There are two files: input.txt and output.txt

input.txt contains the algebraic expression (not more than 100 symbols), which can be calculated using not more than 10 registers.

output.txt shall contain the sequence of the assembler language commands, which result in the amount to be placed. The assembler programme should contain all operations of expression (without savings in operations).

Example: input.txt

``````A*B-C*(B+X)
``````

output.txt

``````L A    или    L B
M B           A X
ST R0         M C
L B           ST R1
A X           L A
ST R1         M B
L C           S R1
M R1
ST R1
L R0
S R1
``````

I understand the purpose of the mission, but I don't know how to start it. On the basis of an example, it is likely to be necessary to start with the search for opening brackets, to carry out lower priority operations first, but what data structures are best used and the algorithm of the solution is not clear.

• If you have a mission of misunderstanding, it's not a good idea to read about complex but effective syntaxing techniques. The elephant needs to be eaten in pieces.

Part 1. Syntax analysis of expression. As @Mike advised, read the reverse Polish record and the calculation algorithm using it. This is not complicated, intuitive and based on simple basic principles. Write the calculator, which will actually calculate.

Part 2. Translation. With the success of the previous task, this is, in fact, merely a creative rethinking of the polics. The only conditionally difficult exercise here is to figure out how the Polish donation teams are recorded in the form of assembler instructions-- it just needs to be carefully done, the work is purely editorial.

And, yes, don't forget the youth test from the beginning. And it'll be easier to manage, and the mistakes will be less, and in the future, it'll be useful to:

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2