1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
| var
t: text;
s, s1: string;
k, o, y: integer;
c: char;
b, b1: boolean;
imya, znach, typ: array of string;
obr, obr1: array of integer;
words: array of string := ('begin', 'type', 'VAR');
function forma(st: string): string;
begin
for var i := 1 to st.Length do
if ord(st[i]) > 32 then
Result := Result + st[i];
end;
begin
assign(t, 'C:\PABCWork.NET\пример.PAS');
reset(t);
while not eof(t) do
begin
read(t, c);
s := s + c;
end;
close(t);
k := pos('const', s) + 5;
SetLength(imya, 0);
SetLength(znach, 0);
while b = false do
begin
foreach var x in words do
if x = forma(s1) then
b := true;
if b = false then
if s[k] = '=' then
begin
SetLength(imya, imya.Length + 1);
SetLength(znach, znach.Length + 1);
imya[imya.Length - 1] := forma(s1);
s1 := '';
end
else if (s[k] = ';') then
begin
s1 := forma(s1);
znach[znach.Length - 1] := forma(s1);
s1 := '';
end
else
s1 := s1 + s[k];
k := k + 1;
end;
//writeln(imya);
//writeln(znach);
SetLength(obr, znach.Length);
SetLength(obr1, 0);
for var x := 0 to imya.Length - 1 do
begin
k := 0;
b1 := false;
while (pos(imya[x], s, k + 1) <> 0) do
begin
if b1 = true then
begin
obr[x] := obr[x] + 1;
SetLength(obr1, obr1.Length + 1);
k := pos(imya[x], s, k + 1);
obr1[obr1.Length - 1] := k;
end
else
begin
b1 := true;
k := pos(imya[x], s, k + 1);
end;
end;
end;
//writeln(obr);
y := 0;
for var x := 0 to obr.Length - 1 do
begin
for var j := 0 + y to obr[x] - 1 + y do
begin
o := 0;
for var m := 1 to obr1[j] do
if ord(s[m]) = 13 then
o := o + 1;
o := o + 1;
obr1[j] := o;
end;
y := y + obr[x];
end;
//writeln(obr1);
setlength(typ, imya.Length);
var T1: byte;
var T2: shortint;
var T3: word;
var T4: smallint;
var T5: integer;
var T6: longword;
var T7: int64;
var T8: uint64;
var T9: boolean;
for var x := 0 to znach.Length - 1 do
if (znach[x].Length = 3) and (znach[x][1] = '''') and (znach[x][3] = '''') then
typ[x] := 'Char'
else if znach[x][1] = '''' then
typ[x] := 'String'
else if byte.TryParse(znach[x], T1) = true then
typ[x] := 'Byte'
else if shortint.TryParse(znach[x], T2) = true then
typ[x] := 'Shortint'
else if word.TryParse(znach[x], T3) = true then
typ[x] := 'Word'
else if smallint.TryParse(znach[x], T4) = true then
typ[x] := 'Smallint'
else if integer.TryParse(znach[x], T5) = true then
typ[x] := 'Integer'
else if longword.TryParse(znach[x], T6) = true then
typ[x] := 'Longword'
else if int64.TryParse(znach[x], T7) = true then
typ[x] := 'Int64'
else if uint64.TryParse(znach[x], T8) = true then
typ[x] := 'Uint64'
else if boolean.TryParse(znach[x], T9) = true then
typ[x] := 'Boolean'
else if znach[x][1] = '[' then
typ[x] := 'Array'
else
typ[x] := 'Biginteger';
s1 := '';
b := false;
for var x := 0 to typ.Length - 1 do
if typ[x] = 'Array' then
begin
for var j := 2 to znach[x].Length do
if b = false then
if (znach[x][j] = ',') or (znach[x][j] = ']') then
b := true
else
s1 := s1 + znach[x][j];
if (s1.Length = 3) and (s1[1] = '''') and (s1[3] = '''') then
typ[x] := typ[x] + ' of char'
else if s1[1] = '''' then
typ[x] := typ[x] + ' of string'
else if byte.TryParse(s1, T1) = true then
typ[x] := typ[x] + ' of byte'
else if shortint.TryParse(s1, T2) = true then
typ[x] := typ[x] + ' of shortint'
else if word.TryParse(s1, T3) = true then
typ[x] := typ[x] + ' of word'
else if smallint.TryParse(s1, T4) = true then
typ[x] := typ[x] + ' of smallint'
else if integer.TryParse(s1, T5) = true then
typ[x] := typ[x] + ' of integer'
else if longword.TryParse(s1, T6) = true then
typ[x] := typ[x] + ' of longword'
else if int64.TryParse(s1, T7) = true then
typ[x] := typ[x] + ' of int64'
else if uint64.TryParse(s1, T8) = true then
typ[x] := typ[x] + ' of uint64'
else if boolean.TryParse(s1, T9) = true then
typ[x] := typ[x] + ' of boolean'
else
typ[x] := typ[x] + ' of biginteger'
end;
//writeln(typ);
assign(t, 'info.txt');
rewrite(t);
y := 0;
for var x := 0 to imya.Length - 1 do
begin
writeln(t, x + 1, ') Имя константы: ' + imya[x]);
writeln(t, 'Тип: ' + typ[x]);
writeln(t, 'Обращений: ' + obr[x]);
if obr[x] > 0 then
begin
write(t, 'Номера строк: ');
for var j := y to y + obr[x] - 1 do
begin
if j = y + obr[x] - 1 then
write(t, obr1[j])
else
print(t, obr1[j] + ',');
end;
y := y + obr[x];
writeln(t);
end;
end;
close(t);
end. |