@@ -71,6 +71,92 @@ namespace FPL {
71
71
mVariables [variable.VariableName ] = variable;
72
72
}
73
73
74
+
75
+
76
+ bool Parser::FichierInstruction (std::optional<FonctionDefinition>& fonction) {
77
+ auto arg = CheckerIdentifiant ();
78
+ if (arg.has_value ()) {
79
+ auto fichierName = CheckerValue ();
80
+
81
+ if (fichierName->StatementType .mType != STRING) {
82
+ std::cerr << " Le nom du fichier doit etre entre \"\" ." << std::endl;
83
+ exit (1 );
84
+ }
85
+
86
+ std::replace (fichierName->StatementName .begin (), fichierName->StatementName .end (), ' "' , ' ' );
87
+ fichierName->StatementName .erase (std::remove_if (fichierName->StatementName .begin (), fichierName->StatementName .end (), ::isspace), fichierName->StatementName .end ());
88
+
89
+ if (fichierName.has_value ()) {
90
+ if (arg->mText == " ecrire" ) {
91
+ std::ofstream file { fichierName->StatementName };
92
+ if (!file) {
93
+ std::cerr << " Donnez le nom correct du fichier : '" << fichierName->StatementName << " ' ." << std::endl;
94
+ exit (1 );
95
+ }
96
+ if (CheckerOperateur (" -" ).has_value ()) {
97
+ if (CheckerOperateur (" >" ).has_value ()) {
98
+ auto valueInFile = CheckerValue ();
99
+ if (valueInFile.has_value ()) {
100
+ if (CheckerOperateur (" ;" ).has_value ()) {
101
+ std::replace (valueInFile->StatementName .begin (), valueInFile->StatementName .end (), ' "' , ' ' );
102
+ file << valueInFile->StatementName << std::endl;
103
+ return true ;
104
+ }
105
+ std::cerr << " Vous devez mettre le symbole ';' pour mettre fin a l'instruction." << std::endl;
106
+ exit (1 );
107
+ } else {
108
+ std::cerr << " Veuillez donner une valeur qui va etre ecrite dans le fichier '" << fichierName->StatementName << " '." << std::endl;
109
+ exit (1 );
110
+ }
111
+ } else {
112
+ std::cerr << " Vous devez utiliser les symboles '->' pour donner une valeur." << std::endl;
113
+ exit (1 );
114
+ }
115
+ } else {
116
+ std::cerr << " Vous devez utiliser les symboles '->' pour donner une valeur." << std::endl;
117
+ exit (1 );
118
+ }
119
+ } else if (arg->mText == " lire" ) {
120
+ std::ifstream file { fichierName->StatementName };
121
+ if (!file) {
122
+ std::cerr << " Donnez le nom correct du fichier : '" << fichierName->StatementName << " ' ." << std::endl;
123
+ exit (1 );
124
+ }
125
+ auto varName = CheckerIdentifiant ();
126
+ if (varName.has_value ()) {
127
+ if (CheckerOperateur (" ;" ).has_value ()) {
128
+ std::string f_content ((std::istreambuf_iterator<char >(file)), (std::istreambuf_iterator<char >()));
129
+ VariableDefinition variable;
130
+ variable.VariableName = varName->mText ;
131
+ variable.VariableType = Type (" texte" , STRING);
132
+ variable.HasReturnValue = false ;
133
+ variable.IsGlobal = false ;
134
+ variable.InFonction = false ;
135
+ if (fonction.has_value ()) {
136
+ variable.InFonction = true ;
137
+ }
138
+ variable.VariableValue = f_content;
139
+ mVariables [variable.VariableName ] = variable;
140
+ return true ;
141
+ }
142
+ std::cerr << " Vous devez mettre le symbole ';' pour mettre fin a l'instruction." << std::endl;
143
+ exit (1 );
144
+ } else {
145
+ std::cerr << " Veuillez donner un nom pour la variable." << std::endl;
146
+ exit (1 );
147
+ }
148
+ } else {
149
+ std::cerr << " Vous ne pouvez que ecrire ou lire le contenu d'un fichier en F.P.L." << std::endl;
150
+ exit (1 );
151
+ }
152
+ } else {
153
+ std::cerr << " Vous devez preciser le nom du fichier auquel vous voulez executer une instruction." << std::endl;
154
+ exit (1 );
155
+ }
156
+ }
157
+ return false ;
158
+ }
159
+
74
160
bool Parser::AppelerInstruction () {
75
161
auto PossibleFonctionName = CheckerIdentifiant ();
76
162
if (PossibleFonctionName.has_value ()) {
@@ -893,6 +979,8 @@ namespace FPL {
893
979
if (AppelerInstruction ()) { return true ; } else {return false ;}
894
980
} else if (PeutEtreInstruction->mText == " saisir" ) {
895
981
if (SaisirInstruction (fonction)) { return true ; } else { return false ; }
982
+ } else if (PeutEtreInstruction->mText == " fichier" ) {
983
+ if (FichierInstruction (fonction)) {return true ;} else {return false ;}
896
984
}
897
985
else {
898
986
mCurrentToken = parseStart;
0 commit comments