1+ #include " Prints.h"
2+
3+ namespace FPL ::Instruction::Prints {
4+ void managementPrint_VARIABLE (FPL::Data::Data &data, FPL::VariableDef &var) {
5+ auto conditionOperator = ExpectConditionOperator (data);
6+ if (conditionOperator.has_value ()) {
7+ auto conditionValue = ExpectValue (data);
8+ if (!conditionValue.has_value ()) {needValueNextOperatorCondition (data);}
9+
10+ if (conditionOperator == " =" ) {
11+ if (var.VariableType .Type == Types::INT) {
12+ int varV = stringToInt (var.VariableValue , " " );
13+ int condV = stringToInt (conditionValue->StatementName , " " );
14+ printWithOperatorCondition_INT (" =" , varV, condV);
15+ } else if (var.VariableType .Type == Types::DOUBLE) {
16+ double varV = stringToDouble (var.VariableValue , " " );
17+ double condV = stringToDouble (conditionValue->StatementName , " " );
18+ printWithOperatorCondition_DOUBLE (" =" , varV, condV);
19+ } else {
20+ wrongType (data);
21+ }
22+ } else if (conditionOperator == " >" ) {
23+ if (var.VariableType .Type == Types::INT) {
24+ int varV = stringToInt (var.VariableValue , " " );
25+ int condV = stringToInt (conditionValue->StatementName , " " );
26+ printWithOperatorCondition_INT (" >" , varV, condV);
27+ } else if (var.VariableType .Type == Types::DOUBLE) {
28+ double varV = stringToDouble (var.VariableValue , " " );
29+ double condV = stringToDouble (conditionValue->StatementName , " " );
30+ printWithOperatorCondition_DOUBLE (" >" , varV, condV);
31+ } else {
32+ wrongType (data);
33+ }
34+ } else if (conditionOperator == " <" ) {
35+ if (var.VariableType .Type == Types::INT) {
36+ int varV = stringToInt (var.VariableValue , " " );
37+ int condV = stringToInt (conditionValue->StatementName , " " );
38+ printWithOperatorCondition_INT (" <" , varV, condV);
39+ } else if (var.VariableType .Type == Types::DOUBLE) {
40+ double varV = stringToDouble (var.VariableValue , " " );
41+ double condV = stringToDouble (conditionValue->StatementName , " " );
42+ printWithOperatorCondition_DOUBLE (" <" , varV, condV);
43+ } else {
44+ wrongType (data);
45+ }
46+ } else if (conditionOperator == " >=" ) {
47+ if (var.VariableType .Type == Types::INT) {
48+ int varV = stringToInt (var.VariableValue , " " );
49+ int condV = stringToInt (conditionValue->StatementName , " " );
50+ printWithOperatorCondition_INT (" >=" , varV, condV);
51+ } else if (var.VariableType .Type == Types::DOUBLE) {
52+ double varV = stringToDouble (var.VariableValue , " " );
53+ double condV = stringToDouble (conditionValue->StatementName , " " );
54+ printWithOperatorCondition_DOUBLE (" >=" , varV, condV);
55+ } else {
56+ wrongType (data);
57+ }
58+ } else if (conditionOperator == " <=" ) {
59+ if (var.VariableType .Type == Types::INT) {
60+ int varV = stringToInt (var.VariableValue , " " );
61+ int condV = stringToInt (conditionValue->StatementName , " " );
62+ printWithOperatorCondition_INT (" <=" , varV, condV);
63+ } else if (var.VariableType .Type == Types::DOUBLE) {
64+ double varV = stringToDouble (var.VariableValue , " " );
65+ double condV = stringToDouble (conditionValue->StatementName , " " );
66+ printWithOperatorCondition_DOUBLE (" <=" , varV, condV);
67+ } else {
68+ wrongType (data);
69+ }
70+ }
71+ } else {
72+ std::cout << var.VariableValue ;
73+ }
74+ }
75+
76+ void managementPrint_ARGUMENT (FPL::Data::Data &data, std::optional<FPL::FonctionArgumentDef> &arg) {
77+ auto conditionOperator = ExpectConditionOperator (data);
78+ if (conditionOperator.has_value ()) {
79+ auto conditionValue = ExpectValue (data);
80+ if (!conditionValue.has_value ()) {needValueNextOperatorCondition (data);}
81+
82+ if (conditionOperator == " =" ) {
83+ if (arg->ArgumentType .Type == Types::INT) {
84+ int varV = stringToInt (arg->ArgumentValue , " " );
85+ int condV = stringToInt (conditionValue->StatementName , " " );
86+ printWithOperatorCondition_INT (" =" , varV, condV);
87+ } else if (arg->ArgumentType .Type == Types::DOUBLE) {
88+ double varV = stringToDouble (arg->ArgumentValue , " " );
89+ double condV = stringToDouble (conditionValue->StatementName , " " );
90+ printWithOperatorCondition_DOUBLE (" =" , varV, condV);
91+ } else {
92+ wrongType (data);
93+ }
94+ } else if (conditionOperator == " >" ) {
95+ if (arg->ArgumentType .Type == Types::INT) {
96+ int varV = stringToInt (arg->ArgumentValue , " " );
97+ int condV = stringToInt (conditionValue->StatementName , " " );
98+ printWithOperatorCondition_INT (" >" , varV, condV);
99+ } else if (arg->ArgumentType .Type == Types::DOUBLE) {
100+ double varV = stringToDouble (arg->ArgumentValue , " " );
101+ double condV = stringToDouble (conditionValue->StatementName , " " );
102+ printWithOperatorCondition_DOUBLE (" >" , varV, condV);
103+ } else {
104+ wrongType (data);
105+ }
106+ } else if (conditionOperator == " <" ) {
107+ if (arg->ArgumentType .Type == Types::INT) {
108+ int varV = stringToInt (arg->ArgumentValue , " " );
109+ int condV = stringToInt (conditionValue->StatementName , " " );
110+ printWithOperatorCondition_INT (" <" , varV, condV);
111+ } else if (arg->ArgumentType .Type == Types::DOUBLE) {
112+ double varV = stringToDouble (arg->ArgumentValue , " " );
113+ double condV = stringToDouble (conditionValue->StatementName , " " );
114+ printWithOperatorCondition_DOUBLE (" <" , varV, condV);
115+ } else {
116+ wrongType (data);
117+ }
118+ } else if (conditionOperator == " >=" ) {
119+ if (arg->ArgumentType .Type == Types::INT) {
120+ int varV = stringToInt (arg->ArgumentValue , " " );
121+ int condV = stringToInt (conditionValue->StatementName , " " );
122+ printWithOperatorCondition_INT (" >=" , varV, condV);
123+ } else if (arg->ArgumentType .Type == Types::DOUBLE) {
124+ double varV = stringToDouble (arg->ArgumentValue , " " );
125+ double condV = stringToDouble (conditionValue->StatementName , " " );
126+ printWithOperatorCondition_DOUBLE (" >=" , varV, condV);
127+ } else {
128+ wrongType (data);
129+ }
130+ } else if (conditionOperator == " <=" ) {
131+ if (arg->ArgumentType .Type == Types::INT) {
132+ int varV = stringToInt (arg->ArgumentValue , " " );
133+ int condV = stringToInt (conditionValue->StatementName , " " );
134+ printWithOperatorCondition_INT (" <=" , varV, condV);
135+ } else if (arg->ArgumentType .Type == Types::DOUBLE) {
136+ double varV = stringToDouble (arg->ArgumentValue , " " );
137+ double condV = stringToDouble (conditionValue->StatementName , " " );
138+ printWithOperatorCondition_DOUBLE (" <=" , varV, condV);
139+ } else {
140+ wrongType (data);
141+ }
142+ }
143+ } else {
144+ std::cout << arg->ArgumentValue ;
145+ }
146+ }
147+
148+ void printWithOperatorCondition_INT (std::string_view currOP, int a, int b) {
149+ if (currOP == " =" ) {
150+ if (a == b) {
151+ std::cout << " vrai" ;
152+ } else {
153+ std::cout << " faux" ;
154+ }
155+ } else if (currOP == " <" ) {
156+ if (a < b) {
157+ std::cout << " vrai" ;
158+ } else {
159+ std::cout << " faux" ;
160+ }
161+ } else if (currOP == " >" ) {
162+ if (a > b) {
163+ std::cout << " vrai" ;
164+ } else {
165+ std::cout << " faux" ;
166+ }
167+ } else if (currOP == " >=" ) {
168+ if (a >= b) {
169+ std::cout << " vrai" ;
170+ } else {
171+ std::cout << " faux" ;
172+ }
173+ } else if (currOP == " <=" ) {
174+ if (a <= b) {
175+ std::cout << " vrai" ;
176+ } else {
177+ std::cout << " faux" ;
178+ }
179+ }
180+ }
181+
182+ void printWithOperatorCondition_DOUBLE (std::string_view currOP, double a, double b) {
183+ if (currOP == " =" ) {
184+ if (a == b) {
185+ std::cout << " vrai" ;
186+ } else {
187+ std::cout << " faux" ;
188+ }
189+ } else if (currOP == " <" ) {
190+ if (a < b) {
191+ std::cout << " vrai" ;
192+ } else {
193+ std::cout << " faux" ;
194+ }
195+ } else if (currOP == " >" ) {
196+ if (a > b) {
197+ std::cout << " vrai" ;
198+ } else {
199+ std::cout << " faux" ;
200+ }
201+ } else if (currOP == " >=" ) {
202+ if (a >= b) {
203+ std::cout << " vrai" ;
204+ } else {
205+ std::cout << " faux" ;
206+ }
207+ } else if (currOP == " <=" ) {
208+ if (a <= b) {
209+ std::cout << " vrai" ;
210+ } else {
211+ std::cout << " faux" ;
212+ }
213+ }
214+ }
215+ }
0 commit comments