Bonjour,
je ne comprends pas ce segmentation fault
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 //terminal.hpp #ifndef TERMINAL_HPP #define TERMINAL_HPP enum terminal {identificateur=0,nombre,plus,moins,etoile,slash,po,pf,dollar}; enum symbole{snombre=0,sidentificateur,splus,smoins,setoile,sslash,spo,spf, sdollar,sepsilon,sE,sEprim,sT,sTprim,sF}; enum nonterminal{E=0,Eprim,T,Tprim,F}; constexpr int nbterminaux=9; constexpr int nbnonterminaux=5; constexpr int nbsymboles=15; #endif
Code cpp : 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 //main.cpp #include <iostream> #include <string> #include <vector> #include "syntaxique.hpp" int main(int argc,char *argv[]){ std::vector<std::string>args; for(unsigned i=0;i<static_cast<unsigned>(argc);++i) args.push_back(argv[i]); if(argc!=2) std::cerr<<"manque le fichier"<<std::endl; else{ syntaxique S; } }
Code cpp : 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 //syntaxique.hpp #ifndef SYNTAXIQUE_HPP #define SYNTAXIQUE_HPP #include <vector> #include <string> #include "terminal.hpp" class syntaxique{ public: syntaxique(); private: terminal ulex; std::string lexeme; unsigned long int ligne; nonterminal symbole2nonterminal[nbnonterminaux]; std::string symbole2string[nbsymboles]; std::vector<symbole>pile; std::vector<symbole>M[nbnonterminaux][nbterminaux]; }; #endif
Code cpp : 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 //syntaxique.cpp #include <iostream> #include <string> #include <vector> #include "terminal.hpp" #include "syntaxique.hpp" syntaxique::syntaxique(){ symbole2nonterminal[sE]=E; symbole2nonterminal[sEprim]=Eprim; symbole2nonterminal[sT]=T; symbole2nonterminal[sTprim]=Tprim; symbole2nonterminal[sF]=F; symbole2string[snombre]="nombre"; symbole2string[splus]="plus"; symbole2string[smoins]="moins"; symbole2string[setoile]="etoile"; symbole2string[sslash]="slash"; symbole2string[spo]="parenthèse ouvrante"; symbole2string[spf]="parenthèse fermante"; symbole2string[sdollar]="fin"; symbole2string[sE]="expression"; symbole2string[sEprim]="expressionprim"; symbole2string[sT]="terme"; symbole2string[sTprim]="termeprim"; symbole2string[sF]="facteur"; symbole2string[sidentificateur]="identificateur"; }ça me fait ça dès que l'on affecte symbole2string[1]="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
57
58
59
60
61
62
63
64
65
66
67
68
69
70 $ gdb --args ./a.out test GNU gdb (Debian 13.1-3) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./a.out... (gdb) b syntaxique Breakpoint 1 at 0x35c3: file syntaxique.cpp, line 8. (gdb) r Starting program: /media/mathieu/disknoel2023/espace de travail/developpez.net/anasynt/programme/expériences/discussion/a.out test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Breakpoint 1, syntaxique::syntaxique (this=0x7fffffffd6f0) at syntaxique.cpp:8 8 syntaxique::syntaxique(){ (gdb) n 9 symbole2nonterminal[sE]=E; (gdb) 10 symbole2nonterminal[sEprim]=Eprim; (gdb) 11 symbole2nonterminal[sT]=T; (gdb) 12 symbole2nonterminal[sTprim]=Tprim; (gdb) 13 symbole2nonterminal[sF]=F; (gdb) 14 symbole2string[snombre]="nombre"; (gdb) 15 symbole2string[splus]="plus"; (gdb) 16 symbole2string[smoins]="moins"; (gdb) 17 symbole2string[setoile]="etoile"; (gdb) 18 symbole2string[sslash]="slash"; (gdb) 19 symbole2string[spo]="parenthèse ouvrante"; (gdb) 20 symbole2string[spf]="parenthèse fermante"; (gdb) 21 symbole2string[sdollar]="fin"; (gdb) 22 symbole2string[sE]="expression"; (gdb) 23 symbole2string[sEprim]="expressionprim"; (gdb) 24 symbole2string[sT]="terme"; (gdb) 25 symbole2string[sTprim]="termeprim"; (gdb) 26 symbole2string[sF]="facteur"; (gdb) 27 symbole2string[sidentificateur]="identificateur"; (gdb) Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7ab7e3a in __GI___libc_free (mem=0x7fff00000004) at ./malloc/malloc.c:3362 3362 ./malloc/malloc.c: Aucun fichier ou dossier de ce type.
quelqu'un a une idée?
Partager