IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

erreur de segmentation


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé

    Homme Profil pro
    développeur à la maison
    Inscrit en
    Septembre 2006
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : développeur à la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 393
    Billets dans le blog
    16
    Par défaut erreur de segmentation
    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";
    }
    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.
    ça me fait ça dès que l'on affecte symbole2string[1]="quelque chose"

    quelqu'un a une idée?

  2. #2
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 599
    Par défaut
    Bonjour,

    Il faut utiliser les bons indices, il y a 5 éléments dans symbole2nonterminal, normalement dans les cas flagrant le compilateur aurait dû prévenir.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
      symbole2nonterminal[sE]=E;          // <= sE = 10
      symbole2nonterminal[sEprim]=Eprim;  //  <= sEprim = 11
      symbole2nonterminal[sT]=T;          // <= sT= 12
      symbole2nonterminal[sTprim]=Tprim;  // <= sTprim = 13
      symbole2nonterminal[sF]=F;          // <= SF = 14

  3. #3
    Membre éclairé

    Homme Profil pro
    développeur à la maison
    Inscrit en
    Septembre 2006
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : développeur à la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 393
    Billets dans le blog
    16
    Par défaut
    Merci Dalfab, tu as trouvé
    comme-ça, ça marche:
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #ifndef TERMINAL_HPP 
    #define TERMINAL_HPP
     
    enum terminal {identificateur,nombre,plus,moins,etoile,slash,po,pf,dollar};
    enum symbole{sE,sEprim,sT,sTprim,sF,snombre,sidentificateur,splus,smoins,
    	     setoile,sslash,spo,spf,sdollar,sepsilon};
    enum nonterminal{E,Eprim,T,Tprim,F};
    constexpr int nbterminaux=9;
    constexpr int nbnonterminaux=5;
    constexpr int nbsymboles=15;
    #endif

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreurs de segmentation !
    Par anti-conformiste dans le forum Applications et environnements graphiques
    Réponses: 16
    Dernier message: 18/10/2005, 11h11
  2. Erreur de segmentation
    Par Trunks dans le forum C
    Réponses: 3
    Dernier message: 06/10/2005, 18h28
  3. Erreur de segmentation (Inconnue)
    Par Dark-Meteor dans le forum C
    Réponses: 5
    Dernier message: 08/09/2005, 13h42
  4. [Dev-C++] Erreur de segmentation...
    Par sas dans le forum Dev-C++
    Réponses: 11
    Dernier message: 26/03/2005, 14h25
  5. erreur de segmentation
    Par transistor49 dans le forum C++
    Réponses: 10
    Dernier message: 15/03/2005, 11h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo