-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEntradaESaida.h
98 lines (69 loc) · 2.58 KB
/
EntradaESaida.h
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
#include<iostream>
#include <string>
#include <sstream>
#include <map>
#include <utility>
using namespace Atributos;
using namespace ControleDeVariaveis;
using namespace MapaTipos;
namespace EntradaESaida
{
string constroiPrint(string);
string constroiScan(string);
ATRIBUTOS validarEntradaBooleanEmTempoExecucao(ATRIBUTOS);
string constroiTraducaoOperacao(string, string , string , string);
string constroiTraducaoAtribuicao(string , string );
string constroiTraducaoIF(string , string );
string constroiPrint(string label)
{
string print = "\tstd::cout << " + label + " << "+ " \'\\n\'" +";\n\n";
return print;
}
string constroiScan(string label,string tipo)
{
string scan;// = "\tstd::cin >> " + label + ";\n";
if(tipo == constante_tipo_string)
scan = "\tscanf(\"%s\","+ label + ");\n";
else
scan = "\tstd::cin >> " + label + ";\n";
return scan;
}
//Verificação se o valor digitado é 0 ou 1. Caso seja diferente, termina o programa.
ATRIBUTOS validarEntradaBooleanEmTempoExecucao(ATRIBUTOS atrib)
{
ATRIBUTOS atributos;
//string tempa, tempb,tempc,tempd;
int numVariaveis = 4;
string temps[numVariaveis];
string label = atrib.label;
atributos = atrib;
for(int i = 0 ; i < numVariaveis; i++)
{
temps[i] = gerarNovaVariavel();
atributos.traducaoDeclaracaoDeVariaveis += "\tint " + temps[i] + ";\n";
}
/*atributos.traducao += "\t" + temps[0] + " = TRUE == " + label + ";\n";
atributos.traducao += "\t" + temps[1] + " = FALSE == " + label + ";\n";
atributos.traducao += "\t" + temps[2] +" = " + temps[0] + " || " + temps[1] + ";\n";
atributos.traducao += "\t" + temps[3] +" = !" + temps[2] + ";\n";
atributos.traducao += "\tif(" + temps[3] + ") goto fimCodInter;\n";*/
atributos.traducao += constroiTraducaoOperacao(temps[0], "TRUE", label, "==");
atributos.traducao += constroiTraducaoOperacao(temps[1], "FALSE",label , "==");
atributos.traducao += constroiTraducaoOperacao(temps[2], temps[0], temps[1], "||");
atributos.traducao += constroiTraducaoAtribuicao(temps[3], "!" + temps[2]);
atributos.traducao += constroiTraducaoIF(temps[3], "FIMCODINTER");
return atributos;
}
string constroiTraducaoOperacao(string labelReceptora, string operando1, string operando2, string operador)
{
return "\t" + labelReceptora + " = " + operando1 + " " + operador + " " + operando2 + ";\n";
}
string constroiTraducaoAtribuicao(string labelReceptora, string valor)
{
return "\t" + labelReceptora + " = " + valor + ";\n";
}
string constroiTraducaoIF(string label, string addr)
{
return "\tif(" + label + ") goto " + addr + ";\n";
}
}