-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_token.cpp
125 lines (113 loc) · 5.91 KB
/
test_token.cpp
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
#include <iostream>
#include <cstdlib>
#include "token.hpp"
using namespace std;
int main() {
// Proves amb les operacions de 'token':
// Crear tokens diferents i cridar a les consultores per comprovar si funcionen.
token t1(3);
cout << t1 << endl;
cout << "És un operador unari: " << t1.es_operador_unari() << endl;
cout << "És un operador binari: " << t1.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t1.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t1.es_boolea() << endl;
cout << "És un valor enter: " << t1.es_enter() << endl;
cout << "És una variable: " << t1.es_variable() << endl;
cout << "Valor enter: " << t1.to_int() << endl;
cout << "Valor string: " << t1.to_string() << endl;
cout << "Prioritat: " << t1.prioritat().first << " " << t1.prioritat().second << endl;
cout << "=============================" << endl;
token t2(true);
cout << t2 << endl;
cout << "És un operador unari: " << t2.es_operador_unari() << endl;
cout << "És un operador binari: " << t2.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t2.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t2.es_boolea() << endl;
cout << "És un valor enter: " << t2.es_enter() << endl;
cout << "És una variable: " << t2.es_variable() << endl;
cout << "Valor booleà: " << t2.to_bool() << endl;
cout << "Valor string: " << t2.to_string() << endl;
cout << "Prioritat: " << t2.prioritat().first << " " << t2.prioritat().second << endl;
cout << "=============================" << endl;
token t3(false);
cout << t3 << endl;
cout << "És un operador unari: " << t3.es_operador_unari() << endl;
cout << "És un operador binari: " << t3.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t3.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t3.es_boolea() << endl;
cout << "És un valor enter: " << t3.es_enter() << endl;
cout << "És una variable: " << t3.es_variable() << endl;
cout << "Valor booleà: " << t3.to_bool() << endl;
cout << "Valor string: " << t3.to_string() << endl;
cout << "Prioritat: " << t3.prioritat().first << " " << t3.prioritat().second << endl;
cout << "=============================" << endl;
string s4("x");
token t4(s4);
cout << t4 << endl;
cout << "És un operador unari: " << t4.es_operador_unari() << endl;
cout << "És un operador binari: " << t4.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t4.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t4.es_boolea() << endl;
cout << "És un valor enter: " << t4.es_enter() << endl;
cout << "És una variable: " << t4.es_variable() << endl;
cout << "Valor string: " << t4.to_string() << endl;
cout << "Prioritat: " << t4.prioritat().first << " " << t4.prioritat().second << endl;
cout << "=============================" << endl;
string s5("x1");
token t5(s5);
cout << t5 << endl;
cout << "És un operador unari: " << t5.es_operador_unari() << endl;
cout << "És un operador binari: " << t5.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t5.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t5.es_boolea() << endl;
cout << "És un valor enter: " << t5.es_enter() << endl;
cout << "És una variable: " << t5.es_variable() << endl;
cout << "Valor string: " << t5.to_string() << endl;
cout << "Prioritat: " << t5.prioritat().first << " " << t5.prioritat().second << endl;
cout << "=============================" << endl;
token t6(-459);
cout << t6 << endl;
cout << "És un operador unari: " << t6.es_operador_unari() << endl;
cout << "És un operador binari: " << t6.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t6.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t6.es_boolea() << endl;
cout << "És un valor enter: " << t6.es_enter() << endl;
cout << "És una variable: " << t6.es_variable() << endl;
cout << "Valor string: " << t6.to_string() << endl;
cout << "Prioritat: " << t6.prioritat().first << " " << t6.prioritat().second << endl;
cout << "=============================" << endl;
cout << t2 << " i " << t2 << " són iguals: " << (t2 == t2) << endl;
cout << t2 << " i " << t3 << " són iguals: " << (t2 == t3) << endl;
cout << t2 << " i " << t2 << " són diferents: " << (t2 != t2) << endl;
cout << t2 << " i " << t3 << " són diferents: " << (t2 != t3) << endl;
cout << "=============================" << endl;
cout << t4 << " i x són iguals: " << (t4 == token("x")) << endl;
cout << t4 << " i y són iguals: " << (t4 == token("y")) << endl;
cout << t4 << " i x són diferents: " << (t4 != token("x")) << endl;
cout << t4 << " i y són diferents: " << (t4 != token("y")) << endl;
cout << "=============================" << endl;
string s;
bool primer = true;
token tant;
while (getline(cin, s)) {
token t(s);
cout << "TOKEN: " << t << endl;
cout << "És un operador unari: " << t.es_operador_unari() << endl;
cout << "És un operador binari: " << t.es_operador_binari() << endl;
cout << "És un operador commutatiu: " << t.es_operador_commutatiu() << endl;
cout << "És un valor booleà: " << t.es_boolea() << endl;
cout << "És un valor enter: " << t.es_enter() << endl;
cout << "És una variable: " << t.es_variable() << endl;
cout << "Valor string: " << t.to_string() << endl;
cout << "Prioritat: " << t.prioritat().first << " " << t.prioritat().second << endl;
if (not primer) {
cout << t << " i " << t << " són iguals: " << (t == t) << endl;
cout << t << " i " << tant << " són iguals: " << (t == tant) << endl;
cout << t << " i " << t << " són diferents: " << (t != t) << endl;
cout << t << " i " << tant << " són diferents: " << (t != tant) << endl;
}
tant = t;
primer = false;
cout << "=============================" << endl;
}
}