Receiving a core dumped while using flex-bison and cpp

45 Views Asked by At

I am using flex-bison to make a basic compiler of an invented language for an appointment. The problem is that I always receive a core dumped error when I test the 'continue' sentence. I know this might be more a cpp problem than flex-bison problem.

| RCONTINUE TSEMIC
    {
    $$ = new sentenciastruct;
vector<int> tmp;
tmp.push_back(codigo.obtenRef());
$$->conti = tmp;
    codigo.anadirInstruccion("goto"); 
    }

This is the 'problematic' part, if i comment the push back line, the error does not appear but the compiler does not do what it is supposed to. (all the functions of codigo are supposed to be okay because they are given by the teachers).

It looks like, in other rules of the grammar, the $$->conti vector just disapperars giving the error.

The conti value is mainly used in here, it is a vector of references to uncomplete goto instructions in the generated code:

| RWHILE M expresion TDOSPT M bloque M 
    {
    codigo.anadirInstruccion("goto");
    vector<int> *tmp1 = new vector<int>; 
tmp1->push_back($7) ;
    codigo.completarInstrucciones(*tmp1, $2) ;
    }
    RELSE TDOSPT bloque M
    {
    $$ = new sentenciastruct;
    codigo.completarInstrucciones($3->trues,$5);
    codigo.completarInstrucciones($3->falses,$7 + 1);
    codigo.completarInstrucciones($6->exit,$7 + 1);
    codigo.completarInstrucciones($6->conti,$2);
    codigo.completarInstrucciones($11->exit,$12);
    codigo.completarInstrucciones($11->conti,$2);
    delete $3;
    }

The struct that contains the conti vector is the following:

struct sentenciastruct {
vector<int> exit;
vector<int> conti;
};

I have tried many ways to initialize the conti vector on the rule I mentioned before but none of them worked.

0

There are 0 best solutions below