[C] FLEX/BISON Erreur segmentation
Bonjour,
je dois faire une systeme de réecriture:
x+0 -> x
(a+b)^2 -> a^2+ b^2+2ab
Mon probleme est que je souhaite donc travailler sur des char*, j'ai donc changé le type de YYPTYPE en char* mais lorsque le lance le programme j'ai une erreur de segmentation: "Erreur de segmentation (core dumped)"
fichier flex:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
%{
#include "tok.h"
#include "heading.h"
int yyerror(char *s);
%}
digit [0-9]
variable [a-zA-Z]
%%
" "|\t|\n ;
{variable} {return VAR;}
"+" {return PLUS;}
"-" {return MOINS;}
"*" {return TIMES;}
"sqrt" {return SQRT;}
"(" {return LPAREN;}
")" {return RPAREN;}
"->" {return DONNE;}
";" {return PV;}
. {std::cerr<<"SCANNER "; yyerror(""); exit(1);} |
fichier bison:
Code:
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
|
%{
#include "heading.h"
int yyerror(char *s);
int yylex(void);
#define YYSTYPE char *
%}
%token PV
%token VAR
%token SQRT
%token LPAREN
%token RPAREN
%token PLUS
%token TIMES
%token MOINS
%token DONNE
%start input
%%
input:
| expr PV {printf("%s\n",$1);}
;
expr: VAR {$$=$1;}
| SQRT LPAREN expr PLUS expr RPAREN {$$=$1;}
;
%%
int yyerror(char *s){
printf("%s\n",s);
return 0;
} |
merci....