-
Notifications
You must be signed in to change notification settings - Fork 1
/
simplificador.pas
92 lines (73 loc) · 2.13 KB
/
simplificador.pas
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
program simplificadormif;
Uses sysutils;
var
//==============| Entrada |===============//
original : Text; temp:string;
//========================================//
//==============| Controle |==============//
posI,posF,ctd,qtagrup,enable : integer;
//=======================================//
//==============| Saida |===============//
novo: Text; temp2 : string;
//=====================================//
procedure a(linha:string);
var posicao,conteudo : integer; s : integer;
begin
s:=Pos(':',linha);
posicao := strtoint(Copy(linha,1,(s-1)));
conteudo := strtoint(linha[s+1]);
if(conteudo <> ctd) then
begin
if(qtAgrup >= 1) then
begin
temp2 := concat('[',inttostr(posI),'..',inttostr(posF),']: ', inttostr(ctd),';');
writeln(temp2);
writeln(novo,temp2); qtAgrup := 0;
end else begin
if(enable=1) then begin
temp2 := concat(inttostr(posI),': ',inttostr(ctd),';');
writeln(temp2);
writeln(novo,temp2);
end;
end;
ctd:= conteudo; posI := posicao; posF := posicao;
end else
if(posicao <> posF) then begin qtagrup := qtagrup +1; posF := posicao; end;
end;
procedure geraCabecalho;
begin
writeln(novo,' -- Arquivo gerado pelo simplificador de mif de autoria de Bruno César(201439002-7) --'); writeln(novo,'');
writeln(novo,'WIDTH=1;');
writeln(novo,'DEPTH=16383;'); writeln(novo,'');
writeln(novo,'ADDRESS_RADIX=UNS;');
writeln(novo,'DATA_RADIX=UNS;'); writeln(novo,'');
end;
begin
ctd:= 0; posI:= 1; posF:= 1;enable:= 0;
assign(original,'arquivo.mif');
reset(original);
assign(novo,'saida.mif');
rewrite(novo);
writeln('========| Iniciando |=======');
geraCabecalho;
repeat
readln(original,temp);
a(temp);
if(enable = 0) then enable:= 1;
until eof(original);
if(qtAgrup >= 1) then
begin
temp2 := concat('[',inttostr(posI),'..',inttostr(posF),']: ', inttostr(ctd),';');
writeln(temp2);
writeln(novo,temp2); qtAgrup := 0;
end else begin
if(enable=1) then begin
temp2 := concat(inttostr(posI),': ',inttostr(ctd),';');
writeln(temp2);
writeln(novo,temp2);
end;
end;
writeln('============================');
close(original);
close(novo);
end.