-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathParser.c
More file actions
64 lines (52 loc) · 1.34 KB
/
Parser.c
File metadata and controls
64 lines (52 loc) · 1.34 KB
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
#include "AssBin.h"
#include "BinAss.h"
#include <stdio.h>
void analise(char*);
int getControlLabel(char*, int);
int main(){
char ch;
char instruction[100] = "";
char readFile[100] = "";
char writeFile[100] = "";
FILE *arq;
int op = -1;
printf("1- Converter Assembly para Binario\n");
printf("2- Converter Binario para Assembly\n");
scanf("%d", &op);
if(op == 1){
strcpy(readFile, "AssBin.txt");
strcpy(writeFile, "BinAss.txt");
}
else if(op == 2){
strcpy(readFile, "BinAss.txt");
strcpy(writeFile, "AssBin.txt");
}
system("cls");
arq = fopen(readFile, "r");
openFile(writeFile);
if(arq == NULL){
printf("Erro, nao foi possivel abrir o arquivo\n");
system("pause");
exit(0);
}
while( (ch=fgetc(arq))!= EOF )
{
int len = strlen(instruction);
instruction[len] = ch;
instruction[len+1] = '\0';
if (ch == '\n'){
if(pos(instruction, '#', 1) > 0)
substring(instruction, instruction, 0, pos(instruction, '#', 1)); //Ignorar comentários
if(op == 1)
analiseInstruction(instruction);
else if(op == 2)
analiseBinary(instruction);
strcpy(instruction, "");
}
}
if(op == 1)
analiseInstruction(instruction);
else if(op == 2)
analiseBinary(instruction);
system("pause");
}