Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Zapiska_-_31_1 (1).docx
Скачиваний:
0
Добавлен:
01.04.2025
Размер:
536.65 Кб
Скачать

Додаток б. Приклад програми із лексичними та синтаксичними помилками та текст файлу з повідомленням про помилки.

Файл prog.i31:

STARTPROGRAM

VARIABLE _Sa,_K,_Wa,_A,_As,_C,_B integer16_t;

STARTBLOK

scandata(_A);

scandata(_B);

printdata(2 or 0);

printdata(not (2 and 0 ));

printdata(_A + 2)

printdata(8 - 30);

printdata(_A * 3);

printdata(_A div 2);

printdata(_A + 3 * 2);

printdata(_B + ((_A - 1)*4 + 7));

printdata(7 % 6);

if (_A <> _B) then

STARTBLOK

if (_A >> _B) then

if (_A == 5) then

STARTBLOK

_K:=1;

printdata(_K + 3);

ENDBLOK ;

else

STARTBLOK

_K:=2;

printdata (_K);

ENDBLOK ;

ENDBLOK ;

ENDBLOK ;

if (3 >> 2)

then

STARTBLOK

printdata(1);

ENDBLOK ;

else

STARTBLOK

if (2 << 2)

then

STARTBLOK

printdata(2);

ENDBLOK ;

ENDBLOK ;

ENDBLOK

ФайлErrors.txt:

Error output file. Next errors found:

line 45: Too much 'ENDBLOK'!

line 8: After ')' must be ')', operation or ';'!

line 19: 'STARTBLOK' expected!

Додаток в. Приклад коректної програми та результат її виконання.

STARTPROGRAM

VARIABLE _Sa,_K,_Wa,_A,_AS,_C,_B integer16_t;

STARTBLOK

scandata(_A);

scandata(_B);

printdata(2 or 0);

printdata(not (2 and 0 ));

printdata(_A + 2) ;

printdata(8 - 30);

printdata(_A * 3);

printdata(_A div 2);

printdata(_A + 3 * 2);

printdata(_B + ((_A - 1)*4 + 7));

printdata(7 % 6);

if (_A <> _B) then

STARTBLOK

if (_A >> _B) then

STARTBLOK

if (_A == 5) then

STARTBLOK

_K:=1;

printdata(_K + 3);

ENDBLOK ;

else

STARTBLOK

_K:=2;

printdata (_K);

ENDBLOK ;

ENDBLOK ;

ENDBLOK ;

if (3 >> 2)

then

STARTBLOK

printdata(1);

ENDBLOK ;

else

STARTBLOK

if (2 << 2)

then

STARTBLOK

printdata(2);

ENDBLOK ;

ENDBLOK ;

ENDBLOK

Результат синтаксичного аналіза:

Error output file. Next errors found:

No errors found.

Результат лексичного аналіза:

Output lexem file. Results of the lexical analyze: next lexems found:

Name Type Value Line

1 STARTPROGRAM STARTPROGRAM 0 1

2 VARIABLE VARIABLE 0 2

3 _Sa identifier 1 2

4 , komma 0 2

5 _K identifier 1 2

6 , komma 0 2

7 _Wa identifier 1 2

8 , komma 0 2

9 _A identifier 1 2

10 , komma 0 2

11 _AS identifier 1 2

12 , komma 0 2

13 _C identifier 1 2

14 , komma 0 2

15 _B identifier 1 2

16 integer16_t integer16_t 0 2

17 ; EndGroup 0 2

18 STARTBLOK STARTBLOK 0 3

19 scandata scandata 0 4

20 ( Left_Braket 0 4

21 _A identifier 1 4

22 ) Right_Braket 0 4

23 ; EndGroup 0 4

24 scandata scandata 0 5

25 ( Left_Braket 0 5

26 _B identifier 1 5

27 ) Right_Braket 0 5

28 ; EndGroup 0 5

29 printdata printdata 0 6

30 ( Left_Braket 0 6

31 2 number 2 6

32 or or 0 6

33 0 number 0 6

34 ) Right_Braket 0 6

35 ; EndGroup 0 6

36 printdata printdata 0 7

37 ( Left_Braket 0 7

38 not not 0 7

39 ( Left_Braket 0 7

40 2 number 2 7

41 and and 0 7

42 0 number 0 7

43 ) Right_Braket 0 7

44 ) Right_Braket 0 7

45 ; EndGroup 0 7

46 printdata printdata 0 8

47 ( Left_Braket 0 8

48 _A identifier 1 8

49 + add 0 8

50 2 number 2 8

51 ) Right_Braket 0 8

52 ; EndGroup 0 8

53 printdata printdata 0 9

54 ( Left_Braket 0 9

55 8 number 8 9

56 - sub 0 9

57 30 number 30 9

58 ) Right_Braket 0 9

59 ; EndGroup 0 9

60 printdata printdata 0 10

61 ( Left_Braket 0 10

62 _A identifier 1 10

63 * mul 0 10

64 3 number 3 10

65 ) Right_Braket 0 10

66 ; EndGroup 0 10

67 printdata printdata 0 11

68 ( Left_Braket 0 11

69 _A identifier 1 11

70 div div 0 11

71 2 number 2 11

72 ) Right_Braket 0 11

73 ; EndGroup 0 11

74 printdata printdata 0 12

75 ( Left_Braket 0 12

76 _A identifier 1 12

77 + add 0 12

78 3 number 3 12

79 * mul 0 12

80 2 number 2 12

81 ) Right_Braket 0 12

82 ; EndGroup 0 12

83 printdata printdata 0 13

84 ( Left_Braket 0 13

85 _B identifier 1 13

86 + add 0 13

87 ( Left_Braket 0 13

88 ( Left_Braket 0 13

89 _A identifier 1 13

90 - sub 0 13

91 1 number 1 13

92 ) Right_Braket 0 13

93 * mul 0 13

94 4 number 4 13

95 + add 0 13

96 7 number 7 13

97 ) Right_Braket 0 13

98 ) Right_Braket 0 13

99 ; EndGroup 0 13

100 printdata printdata 0 14

101 ( Left_Braket 0 14

102 7 number 7 14

103 % mod 0 14

104 6 number 6 14

105 ) Right_Braket 0 14

106 ; EndGroup 0 14

107 if if 0 15

108 ( Left_Braket 0 15

109 _A identifier 1 15

110 <> not_equal 0 15

111 _B identifier 1 15

112 ) Right_Braket 0 15

113 then then 0 15

114 STARTBLOK STARTBLOK 0 16

115 if if 0 17

116 ( Left_Braket 0 17

117 _A identifier 1 17

118 >> greater_or_equal 0 17

119 _B identifier 1 17

120 ) Right_Braket 0 17

121 then then 0 17

122 STARTBLOK STARTBLOK 0 18

123 if if 0 19

124 ( Left_Braket 0 19

125 _A identifier 1 19

126 == equal 0 19

127 5 number 5 19

128 ) Right_Braket 0 19

129 then then 0 19

130 STARTBLOK STARTBLOK 0 20

131 _K identifier 1 21

132 := new_value 0 21

133 1 number 1 21

134 ; EndGroup 0 21

135 printdata printdata 0 22

136 ( Left_Braket 0 22

137 _K identifier 1 22

138 + add 0 22

139 3 number 3 22

140 ) Right_Braket 0 22

141 ; EndGroup 0 22

142 ENDBLOK ENDBLOK 0 23

143 ; EndGroup 0 23

144 else else 0 24

145 STARTBLOK STARTBLOK 0 25

146 _K identifier 1 26

147 := new_value 0 26

148 2 number 2 26

149 ; EndGroup 0 26

150 printdata printdata 0 27

151 ( Left_Braket 0 27

152 _K identifier 1 27

153 ) Right_Braket 0 27

154 ; EndGroup 0 27

155 ENDBLOK ENDBLOK 0 28

156 ; EndGroup 0 28

157 ENDBLOK ENDBLOK 0 29

158 ; EndGroup 0 29

159 ENDBLOK ENDBLOK 0 30

160 ; EndGroup 0 30

161 if if 0 31

162 ( Left_Braket 0 31

163 3 number 3 31

164 >> greater_or_equal 0 31

165 2 number 2 31

166 ) Right_Braket 0 31

167 then then 0 32

168 STARTBLOK STARTBLOK 0 33

169 printdata printdata 0 34

170 ( Left_Braket 0 34

171 1 number 1 34

172 ) Right_Braket 0 34

173 ; EndGroup 0 34

174 ENDBLOK ENDBLOK 0 35

175 ; EndGroup 0 35

176 else else 0 36

177 STARTBLOK STARTBLOK 0 37

178 if if 0 38

179 ( Left_Braket 0 38

180 2 number 2 38

181 << less_or_equal 0 38

182 2 number 2 38

183 ) Right_Braket 0 38

184 then then 0 39

185 STARTBLOK STARTBLOK 0 40

186 printdata printdata 0 41

187 ( Left_Braket 0 41

188 2 number 2 41

189 ) Right_Braket 0 41

190 ; EndGroup 0 41

191 ENDBLOK ENDBLOK 0 42

192 ; EndGroup 0 42

193 ENDBLOK ENDBLOK 0 43

194 ; EndGroup 0 43

195 ENDBLOK ENDBLOK 0 44

196 EOF end_of_file 0 45

Лістинг згенерованого коду:

DOSSEG

.MODEL SMALL

.STACK 100h

.DATA

MY_MUL MACRO X,Y,Z

mov z,0

mov z+2,0

mov ax,x

mul y

mov z,ax

mov z+2,dx

mov ax,x+2

mul y

add z+2,ax

mov ax,z

mov dx,z+2

ENDM

_Sa dw 00h

_K dw 00h

_Wa dw 00h

_A dw 00h

_AS dw 00h

_C dw 00h

_B dw 00h

lb1 dw 0h

lb2 dw 0h

buf_if dw 0h

buf dd 0

rc dw 0

;======Data for input() functions======

erFlag db 0

TStr db 10 dup (0)

TBin dw 0,0

MaxLen dw 0

FlagS db 0

Mul10 dw 1,0

my_z dw 0,0

In_Str db 13,10,'<< $'

erStr1 db13,10,'Data not input_variable',13,10,'$'

erStr2 db 13,10,'Incorrectly data ',13,10,'$'

erStr3 db 13,10,'Data is too long ',13,10,'$'

;======================================

;=======Data for output===================

MSign db '+','$'

X_Str db 12 dup (0)

ten dw 10

X1 dw 0h

MX1 db 13,10,'>> $'

;======================================

.CODE

mov ax,@data

mov ds,ax

finit

fstcw rc

or rc,0c00h

fldcw rc

call input

fild buf

fistp _A

call input

fild buf

fistp _B

mov word ptr buf,00002h

fild buf

mov word ptr buf,00000h

fild buf

call or_

fistp buf

call output

call not_

mov word ptr buf,00002h

fild buf

mov word ptr buf,00000h

fild buf

call and_

fistp buf

call output

fild _A

mov word ptr buf,00002h

fild buf

fadd

fistp buf

call output

mov word ptr buf,00008h

fild buf

mov word ptr buf,0001eh

fild buf

fsub

fistp buf

call output

fild _A

mov word ptr buf,00003h

fild buf

fmul

fistp buf

call output

fild _A

mov word ptr buf,00002h

fild buf

fdiv

fistp buf

call output

fild _A

mov word ptr buf,00003h

fild buf

mov word ptr buf,00002h

fild buf

fmul

fadd

fistp buf

call output

fild _B

fild _A

mov word ptr buf,00001h

fild buf

fsub

mov word ptr buf,00004h

fild buf

fmul

mov word ptr buf,00007h

fild buf

fadd

fadd

fistp buf

call output

mov word ptr buf,00007h

fild buf

mov word ptr buf,00006h

fild buf

call mod_

fistp buf

call output

fild _A

fild _B

call eq_

call not_

fistp buf_if

cmp buf_if,0

jne label_1ne

jmp label_1

label_1ne:

fild _A

fild _B

call ge_

fistp buf_if

cmp buf_if,0

jne label_2ne

jmp label_2

label_2ne:

fild _A

mov word ptr buf,00005h

fild buf

call eq_

fistp buf_if

cmp buf_if,0

jne label_3ne

jmp label_3

label_3ne:

mov word ptr buf,00001h

fild buf

fistp _K

fild _K

mov word ptr buf,00003h

fild buf

fadd

fistp buf

call output

jmp label_3_

label_3:

mov word ptr buf,00002h

fild buf

fistp _K

fild _K

fistp buf

call output

label_3_:

label_2:

label_1:

mov word ptr buf,00003h

fild buf

mov word ptr buf,00002h

fild buf

call ge_

fistp buf_if

cmp buf_if,0

jne label_4ne

jmp label_4

label_4ne:

mov word ptr buf,00001h

fild buf

fistp buf

call output

jmp label_4_

label_4:

mov word ptr buf,00002h

fild buf

mov word ptr buf,00002h

fild buf

call le_

fistp buf_if

cmp buf_if,0

jne label_5ne

jmp label_5

label_5ne:

mov word ptr buf,00002h

fild buf

fistp buf

call output

label_5:

label_4_:

;======================================

MOV AH,4Ch

INT 21h

;====Input procedure Input()=============

input PROC

push ax

push bx

push cx

push dx

push di

push si

lea dx,In_Str

mov ah,09

int 21h

mov di,offset buf

mov MaxLen,5

mov cx,MaxLen

mov si,0

In_00:

mov ah,01

int 21h

cmp al,0Dh

je In_1

cmp al,'-'

jne In_0

mov FlagS,1

jmp In_00

In_0:

mov dl,al

call CHECK_BYTE

mov TStr[si],dl

inc si

loop In_00

In_1:

push si

dec si

cmp cx,MaxLen

jne In_2

lea dx,erStr1

mov ah,09

int 21h

mov erFlag,1

jmp In_5

In_2:

mov bh,0

mov bl,TStr[si]

MY_MUL Mul10,bx,my_z

add TBin,ax

adc TBin+2,dx

mov bh,0

mov bl,10

MY_MUL Mul10,bx,my_z

mov Mul10,ax

mov Mul10+2,dx

dec si

cmp si,0

jge In_2

mov ax,TBin

mov dx,TBin+2

pop si

cmp si,MaxLen

jl In_3

cmp MaxLen,5

jl In_2_1

js In_Err

cmp dx,7FFFh

ja In_Err

jmp In_3

In_2_1:

cmp MaxLen,5

jl In_2_2

cmp dx,00

ja In_Err

cmp ah,7fh

ja In_Err

jmp In_3

In_2_2:

cmp ax,007Fh

jbe In_3

In_Err:

lea dx,erStr3

mov ah,09

int 21h

mov erFlag,1

jmp In_5

In_3:

cmp FlagS,1

jne In_4

mov bx,0

sub bx,ax

mov ax,bx

mov bx,0

sbb bx,dx

mov dx,bx

In_4:

mov [di],ax

mov [di+2],dx

mov TBin,0

mov TBin+2,0

mov Mul10,1

mov Mul10+2,0

mov FlagS,0

In_5:

pop si

pop di

pop dx

pop cx

pop bx

pop ax

ret

input ENDP

CHECK_BYTE PROC

sub dl,30h

cmp dl,00

jl ErS

cmp dl,0Ah

jl GO

ErS:

lea dx,erStr2

mov ah,09

int 21h

GO:

ret

CHECK_BYTE ENDP

;======================================

;===Output procedure output()=============

output PROC

push ax

push bx

push cx

push dx

push di

push si

mov cl,byte ptr buf+3

and cl,80h

je m6

fild buf

fchs

fistp buf

mov MSign,'-'

M6:

mov cx,5

mov di,0

O_1:

ffree st(0)

ffree st(1)

fild ten

fild buf

fprem

fistp X1

mov dl,byte ptr X1

add dl,30h

mov X_Str[di],dl

inc di

fild buf

fxch st(1)

fdiv

frndint

fistp buf

loop O_1

mov dx,offset MX1

mov ah,09

int 21h

mov dl,MSign

mov ah,02

int 21h

inc di

mov cx,7

O_2:

mov dl,X_Str[di]

mov ah,02h

int 21h

dec di

loop O_2

mov MSign,'+'

pop si

pop di

pop dx

pop cx

pop bx

pop ax

ret

output ENDP

;======================================

;===Procedure mod_====================

mod_ PROC

fistp lb1

fistp lb2

fild lb1

fild lb2

fprem

ret

mod_ ENDP

;======================================

;===Procedure and_====================

and_ PROC

push ax

push dx

pushf

fistp lb1

fist lb2

mov ax,lb1

cmp ax,0

jnz true_and1

jz false_and

true_and1:

mov ax,lb2

cmp ax,0

jnz true_and

false_and:

fldz

jmp l_and

true_and:

fld1

l_and:

popf

pop dx

pop ax

ret

and_ ENDP

;======================================

;===Procedure or_======================

or_ PROC

push ax

push dx

pushf

fistp lb1

fist lb2

mov ax,lb1

cmp ax,0

jnz true_or

mov ax,lb2

cmp ax,0

jnz true_or

fldz

jmp l_or

true_or:

fld1

l_or:

popf

pop dx

pop ax

ret

or_ ENDP

;======================================

;===Procedure not_====================

not_ PROC

push ax

pushf

fistp lb1

mov ax,lb1

cmp ax,0

jne is_true

fld1

jmp l_not

is_true:

fldz

l_not:

popf

pop ax

ret

not_ ENDP

;======================================

;===Procedure eq_======================

eq_ PROC

push ax

push dx

pushf

fistp lb1

fistp lb2

mov ax,lb1

mov dx,lb2

cmp ax,dx

jne not_eq

fld1

jmp l_eq

not_eq:

fldz

l_eq:

popf

pop dx

pop ax

ret

eq_ ENDP

;======================================

;===Procedure ge_======================

ge_ PROC

push ax

push dx

pushf

fistp lb1

fistp lb2

mov ax,lb1

mov dx,lb2

cmp dx,ax

jl lov

fld1

jmp l_ge

lov:

fldz

l_ge:

popf

pop dx

pop ax

ret

ge_ ENDP

;======================================

;===Procedure le_======================

le_ PROC

push ax

push dx

pushf

fistp lb1

fistp lb2

mov ax, lb1

mov dx, lb2

cmp dx,ax

jg gr

lo:

fld1

jmp l_le

gr:

fldz

l_le:

popf

pop dx

pop ax

ret

le_ ENDP

;======================================

;======================================

END

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]