Bonjour à tous,
les fichiers cpp se compilent parfaitement individuellement (g++ -c fichier.cpp). mais quand je compile le tout, l'édition de liens me fait cette erreur:
voici mes fichiers sources:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 /tmp/ccOlqxEn.o: In function `ULEX_lex::ULEX_lex(T_ULEX)': objets_lex.cpp:(.text+0x8): undefined reference to `vtable for ULEX_lex' /tmp/ccOlqxEn.o: In function `ULEX_lex::ULEX_lex(T_ULEX)': objets_lex.cpp:(.text+0x20): undefined reference to `vtable for ULEX_lex' /tmp/ccOlqxEn.o:(.rodata._ZTV7FIN_lex[vtable for FIN_lex]+0x8): undefined reference to `ULEX_lex::setUlex(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' /tmp/ccOlqxEn.o:(.rodata._ZTV7FIN_lex[vtable for FIN_lex]+0xc): undefined reference to `ULEX_lex::getUlex()' /tmp/ccOlqxEn.o:(.rodata._ZTI7FIN_lex[typeinfo for FIN_lex]+0x8): undefined reference to `typeinfo for ULEX_lex' /tmp/ccOlqxEn.o:(.rodata._ZTI10ENTIER_lex[typeinfo for ENTIER_lex]+0x8): undefined reference to `typeinfo for ULEX_lex' /tmp/ccOlqxEn.o:(.rodata._ZTI10NBREEL_lex[typeinfo for NBREEL_lex]+0x8): undefined reference to `typeinfo for ULEX_lex' /tmp/ccOlqxEn.o:(.rodata._ZTI6ID_lex[typeinfo for ID_lex]+0x8): undefined reference to `typeinfo for ULEX_lex' collect2: ld returned 1 exit status
principal.cpp:
lexical.cpp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <iostream> #include <fstream> #include "objets_lex.hpp" using namespace std; ifstream source; ofstream objet; ULEX_lex *symbole; ULEX_lex *analex(); void programme_complet(); main(int argc,char *argv[]){ if(argc!=2){ cerr<<"usage:\norsay fichier_source fichier_objet"<<endl; return 1; } else{ source.open(argv[1]/*,ios::in*/); if(source){ objet.open(argv[2]/*,ios::out*/); if(objet){ symbole=analex(); programme_complet(); } else cerr<<"erreur à l'ouverture du fichier "<<argv[2]<<endl; } else cerr<<"erreur à l'ouverture du fichier "<<argv[1]<<endl; } }
syntaxique.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433 #include <string> #include <iostream> #include <fstream> using namespace std; #include "objets_lex.hpp" #define TAILLE_TAMPON 4096 #define TAILLE_DEMI_TAMPON 2047 #define SENTINELLE 2047 extern ifstream source; extern ULEX_lex *symbole; int enAvant,debutLex; int numLigne(1); char tampon[TAILLE_TAMPON]; ULEX_lex *analex(); void echec(ULEX_lex * &ulexTrouve); char carsuiv(); void supprimeSep(); void supprimeCommentaire(); ULEX_lex *obtenirId(); ULEX_lex *obtenirNb(); ULEX_lex *obtenirFin(); void reculer(); void charger1(); void charger2(); ULEX_lex *analex(){ char c; while(1){ supprimeSep(); supprimeCommentaire(); if((symbole=obtenirId())!=0) return symbole; else if((symbole=obtenirNb())!=0) return symbole; /* symbole=obtenirPtVirgule(); if(symbole!=0) return symbole;*/ else if((symbole=obtenirFin())!=0) return symbole; else cerr<<"lexeme inconu à la ligne "<<numLigne<<endl; } } void supprimeSep(){ char c; int etat(0); while(1){ switch(etat){ case 0: c=carsuiv(); if(c=='\n'){ numLigne++; etat=1; } else if(c==' '||c=='\t') etat=1; else{ enAvant=debutLex; return; } break; case 1: c=carsuiv(); if(c=='\n'){ numLigne++; etat=1; } else if(c==' '||c=='\t') etat=1; else etat=2; break; case 2: reculer(); debutLex=enAvant; return; } } } void supprimeCommentaire(){ char c; int etat(0); while(1){ switch(etat){ case 0: c=carsuiv(); if(c=='c') etat=1; else{ enAvant=debutLex; return; } break; case 1: c=carsuiv(); if(c=='o') etat=2; else{ enAvant=debutLex; return; } case 2: c=carsuiv(); if(c=='\n'){ numLigne++; etat=3; } else if(c==' '||c=='\t') etat=3; else{ enAvant=debutLex; return; } case 3: c=carsuiv(); if(c=='f') etat=5; else if(c=='\n'){ numLigne++; etat=3; } else if(c==' '||c=='\t') etat=3; else etat=4; break; case 4: c=carsuiv(); if(c=='\n'){ numLigne++; etat=3; } else if(c==' '||c=='\t') etat=3; else{ enAvant=debutLex; return; } case 5: c=carsuiv(); if(c=='c') etat=6; else if(c=='\n'){ numLigne++; etat=3; } else if(c==' '||c=='\t') etat=3; else etat=4; case 6: c=carsuiv(); if(c=='o') etat=7; else if(c=='\n'){ numLigne++; etat=3; } else if(c==' '||c=='\t') etat=3; else etat=4; case 7: c=carsuiv(); if(c=='\n'){ numLigne++; etat=8; } else if(c==' '||c=='\t'||c==';') etat=8; else etat=4; case 8: reculer(); debutLex=enAvant; return; } } } ULEX_lex *obtenirId(){ char c; int etat(0); ULEX_lex *ulexTrouve; string lexeme(""); while(1){ switch(etat){ case 0: c=carsuiv(); if(c=='_'){ lexeme.push_back(c); etat=0; } else if(c>='a'&&c<='z'||c>='A'&&c<='Z'){ lexeme.push_back(c); etat=1; } else{ enAvant=debutLex; //echec return 0; } break; case 1: c=carsuiv(); if(c=='_'||c>='a'&&c<='z'||c>='A'&&c<='Z'||c>='0'&&c<='9'){ lexeme.push_back(c); etat=1; } else etat=2; break; case 2: reculer(); debutLex=enAvant; ulexTrouve=new ID_lex; ulexTrouve->setUlex(lexeme); return ulexTrouve; } } } ULEX_lex *obtenirNb(){ char c; int etat(0); ULEX_lex *ulexTrouve; string lexeme(""); while(1){ switch(etat){ case 0: c=carsuiv(); if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=1; } else{ enAvant=debutLex; //echec return 0; } break; case 1: c=carsuiv(); if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=1; } else if(c==','){ lexeme.push_back(c); etat=2; } else if(c=='e'||c=='E'){ lexeme.push_back(c); etat=4; } else etat=8; break; case 2: c=carsuiv(); if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=3; } else{ lexeme=lexeme.substr(0,lexeme.size()-1); etat=9; } break; case 3: c=carsuiv(); if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=3; } else if(c=='e'||c=='E'){ lexeme.push_back(c); etat=4; } else if(c=='\n'){ numLigne++; etat=10; } else if(c==' '||c=='\t') etat=10; else etat=7; break; case 4: c=carsuiv(); if(c=='+'||c=='-'){ lexeme.push_back(c); etat=5; } else if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=6; } else enAvant=debutLex; return 0; break; case 5: c=carsuiv(); if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=6; } else enAvant=debutLex; return 0; break; case 6: c=carsuiv(); if(c>='0'&&c<='9'){ lexeme.push_back(c); etat=6; } else etat=7; break; case 7: reculer(); debutLex=enAvant; ulexTrouve=new NBREEL_lex; ulexTrouve->setUlex(lexeme); return ulexTrouve; case 8: reculer(); debutLex=enAvant; ulexTrouve=new ENTIER_lex; ulexTrouve->setUlex(lexeme); return ulexTrouve; case 9: reculer(); reculer(); debutLex=enAvant; ulexTrouve=new ENTIER_lex; ulexTrouve->setUlex(lexeme); return ulexTrouve; case 10: debutLex=enAvant; ulexTrouve=new NBREEL_lex; ulexTrouve->setUlex(lexeme); return ulexTrouve; } } } ULEX_lex *obtenirFin(){ char c; int etat(0); // ULEX_lex *ulexTrouve; string lexeme(""); while(1){ switch(etat){ case 0: c=carsuiv(); if(c==EOF) etat=1; else enAvant=debutLex; return 0; //echec break; case 1: debutLex=enAvant; return new FIN_lex; } } } char carsuiv(){ char c; c=tampon[enAvant++]; if(c==EOF) if(enAvant==SENTINELLE+1){ charger2(); // enavant=SENTINELLE+1; c=tampon[enAvant++]; } else if(enAvant==TAILLE_TAMPON){ charger1(); c=tampon[0]; enAvant=1; } else return EOF; return c; } void charger1(){ int i; for(i=0;i<SENTINELLE;i++) tampon[i]='\0'; source.read(tampon,TAILLE_DEMI_TAMPON); if(source.tellg()==-1){ for(i=SENTINELLE;i>0 && tampon[i-1]=='\0';i--) ; tampon[i]=EOF; } } void charger2(){ int i; for(i=SENTINELLE+1;i<TAILLE_TAMPON-1;i++) tampon[i]='\0'; source.read(tampon+SENTINELLE+1,TAILLE_DEMI_TAMPON); if(source.tellg()==-1){ for(i=TAILLE_TAMPON-1;i>SENTINELLE+1 && tampon[i-1]=='\0';i--) ; tampon[i]=EOF; } } void reculer(){ char c; if(enAvant==0){ source.seekg(-TAILLE_DEMI_TAMPON,ios::cur); charger2(); enAvant=TAILLE_TAMPON-2; } else if(enAvant==SENTINELLE+1){ source.seekg(-TAILLE_DEMI_TAMPON,ios::cur); charger1(); enAvant=SENTINELLE-1; } else enAvant--; }
objets_lex.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <iostream> #include <fstream> #include <string> #include "objets_lex.hpp" using namespace std; extern ULEX_lex *symbole; extern ofstream objet; extern int numLigne; void programme_complet(){ while(symbole->getTypeUlex()!=U_FIN){ switch(symbole->getTypeUlex()){ case U_ID: objet<<"ligne "<<numLigne<<": identificateur "<< symbole->getUlex()<<endl; break; case U_REEL: objet<<"ligne "<<numLigne<<": réel "<< symbole->getUlex()<<endl; break; case U_ENTIER: objet<<"ligne "<<numLigne<<": entier "<< symbole->getUlex()<<endl; break; } } }
types.hpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <string> using namespace std; #include "objets_lex.hpp" #include "types.hpp" ULEX_lex::ULEX_lex(T_ULEX x):typeUlex(x){} T_ULEX ULEX_lex::getTypeUlex() const{ return typeUlex; } ID_lex::ID_lex():ULEX_lex(U_ID){} void ID_lex::setUlex(string x){ uniLex=x; } string ID_lex::getUlex(){ return uniLex; } //OPREL_lex::OPREL_lex():ULEX_lex(U_OPREL){} /*void OPREL_lex::setUlex(string x){ uniLex=x; }*/ NBREEL_lex::NBREEL_lex():ULEX_lex(U_NBREEL){} void NBREEL_lex::setUlex(string x){ valeur=x; } string NBREEL_lex::getUlex(){ return valeur; } ENTIER_lex::ENTIER_lex():ULEX_lex(U_ENTIER){} void ENTIER_lex::setUlex(string x){ valeur=x; } string ENTIER_lex::getUlex(){ return valeur; } FIN_lex::FIN_lex():ULEX_lex(U_FIN){}
objets_lex.hpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 #ifndef types_hpp #define types_hpp typedef enum {U_PTVIRG,U_DEUXPTEGAL,U_DEUXPT,U_EGAL,U_FDF,U_ID,U_NBREEL,U_ENTIER,U_CROCHET_OUVRANT,U_CROCHET_FERMANT,U_PARENTHESE_OUVRANTE, U_PARENTHESE_FERMANTE,U_CARACTERE,U_CHAINE,U_POINT,U_OPREL,U_DREF,U_CHAPEAU,U_ADRESSE,U_DEBUT,U_FIN,U_PROC,U_FONCT,U_FIX,U_PROG,U_TYPE,U_STRUCT, U_ENT,U_REEL,U_BOOL,U_CAR,U_CONST,U_VAR,U_EST,U_SI,U_ALORS,U_FSI,U_FAIRE,U_TANTQUE,U_REFAIRE,U_POUR,U_DEPUIS,U_JUSQUE,U_PAS,U_FAIT,U_SINONSI,U_SINON, U_MOD,U_OU8,U_ET8,U_NON8,U_OU,U_ET,U_NON,U_VALBOOL,U_PLUS,U_MOINS,U_ETOILE,U_SLASH} T_ULEX; #endif
cela vous dit-il quelque chose?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #ifndef objets_hpp #define objets_hpp #include <string> #include "types.hpp" class ULEX_lex{ private: T_ULEX typeUlex; public: ULEX_lex(T_ULEX x); T_ULEX getTypeUlex() const; virtual void setUlex(std::string x); virtual std::string getUlex(); }; class ID_lex:public ULEX_lex{ private: std::string uniLex; public: ID_lex(); void setUlex(std::string x); std::string getUlex(); }; class OPREL:public ULEX_lex{ private: std::string uniLex; public: OPREL(); void setUlex(std::string x); std::string getUlex(); }; class NBREEL_lex:public ULEX_lex{ private: std::string valeur; public: NBREEL_lex(); void setUlex(std::string x); std::string getUlex(); }; class ENTIER_lex:public ULEX_lex{ private: std::string valeur; public: ENTIER_lex(); void setUlex(std::string x); std::string getUlex(); }; class FIN_lex:public ULEX_lex{ public: FIN_lex(); }; #endif
ps:
c'est exprès que la fonction ULEX::getUlex ne soit pas virtuelle
Partager