· Результат в текстовом виде:
Prog
Varop
Tvar - string: "int "
ID
Tid - string: "ab2"
Tzap - string: ","
ID
Tid - string: "d3"
Ttochz - string: ";"
Varop
Tvar - string: "float"
ID
Tid - string: "c1"
Ttochz - string: ";"
Varop
Tvar - string: "bool"
ID
Tid - string: "xy4"
Ttochz - string: ";"
Telo
Condop
Tby - string: "by"
Tmotron - string: "("
Operand
Tid - string: "xy4"
Tcrav - string: "=="
Operand
Tconst - string: "yes"
Tdongtron - string: ")"
Tdo - string: "do"
Block
Tid - string: "ab2"
Tpris - string: "="
Vr
Omult
Som
Operand
Tconst - string: "4"
Ttochz - string: ";"
Totherwise - string: "otherwise"
Block
Tid - string: "c1"
Tpris - string: "="
Vr
Omult
Som
Operand
Tconst - string: "3"
Ttochz - string: ";"
Telo
Switchop
Tswitch - string: "switch"
Tmotron - string: "("
Vr
Omult
Som
Operand
Tid - string: "ab2"
Tdongtron - string: ")"
Tmonhon - string: "{"
Byop
Tby - string: "by"
Tconst - string: "1"
Tdvetoch - string: ":"
Block
Tid - string: "d3"
Tpris - string: "="
Vr
Omult
Omult
Som
Operand
Tconst - string: "4"
Tmult - string: "*"
Som
Tmotron - string: "("
Vr
Vr
Omult
Som
Operand
Tid - string: "c1"
Tadd - string: "+"
Omult
Som
Operand
Tconst - string: "3"
Tdongtron - string: ")"
Ttochz - string: ";"
Byop
Tby - string: "by"
Tconst - string: "2"
Tdvetoch - string: ":"
Block
Tid - string: "c1"
Tpris - string: "="
Vr
Omult
Omult
Som
Tmotron - string: "("
Vr
Vr
Omult
Som
Operand
Tid - string: "ab2"
Tadd - string: "+"
Omult
Som
Operand
Tconst - string: "3"
Tdongtron - string: ")"
Tmult - string: "*"
Som
Operand
Tconst - string: "3"
Ttochz - string: ";"
Tdongnhon - string: "}"
Telo
Forop
Tfor - string: "for"
Tid - string: "d3"
Tfrom - string: "from"
Operand
Tconst - string: "0"
Tto - string: "to"
Operand
Tconst - string: "3"
Block
Tid - string: "ab2"
Tpris - string: "="
Vr
Omult
Omult
Som
Operand
Tid - string: "d3"
Tmult - string: "*"
Som
Operand
Tconst - string: "1"
Ttochz - string: ";"
Telo
· Результат в виде дерева:
Результат реализации генератора кода с переводом в язык абстрактной стековой машины
· Входная цепочка
int ab2, d3; float c1;
bool xy4;
by(xy4==yes) do ab2 = 4;
otherwise c1=3;
switch (ab2) { by 1: d3=4 * (c1 + 3); by 2: c1 =(ab2 + 3) *3; }
for d3 from 0 to 3 ab2 = d3 * 1;
· Результат
Prog
-string:
xy4 DW
ab2 DW
c1 DW
ab2 DW
d3 DW
xy4 DW
ab2 DW
c1 DW
ab2 DW
d3 DW
//***COND_OP****//
RVALUE xy4
PUSH yes
==
GOTRUE M1
GOTO M2
LABEL M2
LVALUE c1
PUSH 3
:=
GOTO M3
LABEL M1
LVALUE ab2
PUSH 4
:=
GOTO M3
LABEL M3
//***SWITCH OP****//
RVALUE ab2
PUSH 1
=
GOTRUE CASE2
RVALUE ab2
PUSH
=
GOTRUE CASE 1
GOTO OUT_SWITCH
LABEL CASE2
LVALUE d3
PUSH 4
RVALUE c1
PUSH 3
ADD
MULT
:=
GOTO OUT_SWITCH
LABEL CASE 1
LVALUE c1
RVALUE ab2
PUSH 3
ADD
PUSH 3
MULT
:=
GOTO OUT_SWITCH
LABEL OUT_SWITCH
//***FOR****//
LVALUE d3
PUSH 0
:=
LABEL LAP
RVALUE d3
PUSH 3
<=
GOFALSE OUTFOR
LVALUE ab2
RVALUE d3
PUSH 1
MULT
:=
LVALUE
d3
RVALUE
d3
PUSH 1
ADD
:=
GOTO LAP
LABEL OUTFOR
HALT
Список литературы
1. Методическое пособие по СПО С.С. Сосинская, П.В. Юрин Издательство- Иркутского государственного технического университета 2006г.-95с.
2. Сосинская С. С. “Системное программное обеспечение ”: Лабораторная работа №3-25с. в электронном каталоге кафедры вычислительной техники.
3. Молчанов А.Ю. Системное программное обеспечение: Учебник для вузов. Питер 2003- 736 с.
4. Сайт: https://decoding.narod.ru/practic/polishrecord/polishrecord.html
https://codingrus.ru/readarticle.php?article_id=2158