Précédent   Forum du club des développeurs et IT Pro > C et C++ > Outils pour C & C++ > GCC
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 05/06/2010, 00h40   #1
m3asmi
Invité de passage
 
rachid el ghazi
Inscription : mars 2010
Messages : 10
Détails du profil
Informations personnelles :
Nom : rachid el ghazi
Localisation : Maroc

Informations forums :
Inscription : mars 2010
Messages : 10
Points : 4
Points : 4
Par défaut compilation gcc tmp

salut !

j'ai un projet qui est cree en flex et bison sur calculatrice Logique

voila le code de log.l
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
%{
#include <stdio.h>
#include "logY.h"
extern void yyerror(char *);
extern int yyval;
 
%}
 
t  T|t
f  F|f
 
%%
 
(t|f) { yyval = atoi(yytext); return term;}
[ \t]     /* ignore whitespace */
 
<<EOF>>   yyterminate();  /* signal end of dialogue */
 
\n        return yytext[0];
.         return yytext[0];
 
%%
et le fichier bison log.y
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
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
/*  file name : log.y  */
 
/*  Calculator grammar for arithmetic expressions.      */
/*  Associativity and precedence declarations used to   */
/*  disambiguate the grammar.                           */
 
%{
   #include <stdio.h>
   #include <stdlib.h>
 
   #include <ctype.h>
 
   extern FILE* yyin;
   extern int yylex(void);
 
 
 
   void yyerror(char *);
   void clearAllRegisters(void);
 
   double factorial(double);
%}
 
%token term
 
%left  'or'  
%left  'and'  
%right not
 
%%
 
input
    :  /* empty */
    |  input line
    ;
 
line
    : '\n'
    |  expression '\n'            {  printf ("\t= %d\n", $1); }
    ;
 
expression
    : expression 'or' expression   { if ( $1 != 0)  $$ = 1;
    				     else if ($3 != 0 ) $$ = 1;
    					  else  $$ = 0 ;
    				     }
    |  expression 'and' expression   { if ( $1 != 0) { if ($3 != 0 ) $$ = 1;}
    					  else  $$ = 0 ;
    				     }
    | 'not' expression %prec not {  if ( $2 == 0) $$ = 1;
    				    else  $$ = 0  ;}
    | '(' expression ')'          { $$ = $2; }
    |  term                     { $$ = $1; if($1 != 0) printf("\ttrue\n");
    						else printf("\t fasle"); } 
    ;
 
%%
 
 
 
 
void yyerror(char *s){
   printf("\n%s ", s);}
 
 
 
int main()/*int argc,char** argv)
{
  if (argc>1){
    if (fopen(argv[1],"r") == NULL){
         printf("Can't read from %s\n",argv[1]);
         return 0;
    } else
         yyin = fopen(argv[1],"r");
  } else
         yyin = stdin;
         printf(">> ");
         yyparse();
}*/
{ 
//if (yyparse(c) == 0 )
printf("expression correcte\n");
 }
avec la compilation GCC il me return

Code :
1
2
3
4
5
6
7
8
read: 4: arg count
/tmp/cc65bOW8.o: In function `yylex':
logL.c:(.text+0x22f): undefined reference to `yyval'
logL.c:(.text+0x3df): undefined reference to `yywrap'
/tmp/cc65bOW8.o: In function `input':
logL.c:(.text+0xddb): undefined reference to `yywrap'
collect2: ld a retourné 1 code d'état d'exécution
rachid@Desktop:~/Bureau/flex/projet$
est-ce-que vous avez une proposition?!
m3asmi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2010, 20h28   #2
uriotcea
Membre éclairé
 
Avatar de uriotcea
 
Homme Didier
Ingénieur / physicien
Inscription : septembre 2003
Messages : 1 132
Détails du profil
Informations personnelles :
Nom : Homme Didier
Localisation : France

Informations professionnelles :
Activité : Ingénieur / physicien
Secteur : Service public

Informations forums :
Inscription : septembre 2003
Messages : 1 132
Points : 388
Points : 388
Salut,

Difficilie à lire ce que a ecrit, mais à priori tes erreurs correspondent à des variable déclarées externes, donc déclarées d'ailleur, mais ou ?
uriotcea est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2010, 00h54   #3
m3asmi
Invité de passage
 
rachid el ghazi
Inscription : mars 2010
Messages : 10
Détails du profil
Informations personnelles :
Nom : rachid el ghazi
Localisation : Maroc

Informations forums :
Inscription : mars 2010
Messages : 10
Points : 4
Points : 4
voila la résolution
log.l
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
 
%{
#include "logY.h" //   log.tab.h
#include <stdlib.h>
//extern void yyerror(char *);
//extern YYSTYPE yylval;
 
%}
 
t  [1]
f  [0] 
%%
 
{t}    { yylval = atoi(yytext); return T;}
{f}    { yylval = atoi(yytext); return F;}
 
and { return AND;}
or  { return OR;}	
not { return NOT;}
 
")"	return ')';
"("	return '(';
[ \t]     /* ignore whitespace */
"\n"    { return '\n'; }
.               yyerror("invalid character");
<<EOF>>   yyterminate();  /* signal end of dialogue */
 
%%
 
int yywrap(void) {
    return 1;
}

et le log.y
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%token T F
 
%left  OR  
%left  AND  
%right NOT
 
 
%{
    #include <stdio.h>
    void yyerror(char *);
    int yylex(void);
 
    extern FILE* yyin;
%}
%%
input
    :  /* empty */
    |  input line
    ;
 
line
    : '\n'                  {printf(">> ");}
    |  exp '\n'             { printf("\t Le résultat = %d\n>> ", $1); }
    ;
 
 exp: 
    exp OR terme  	{ $$ = $1||$3; }
   |terme          {$$ = $1;}
   ;
terme:
     terme AND fact 	{ $$ = $1&&$3;}
    |fact           	{ $$ = $1;}
    ;
fact:
     '(' exp ')'    	{ $$ = $2;}
    |NOT exp       {$$ = ! $2; }   
    | T			
    |F
    ;
 
%%
 
 
void yyerror(char *s) {
    printf("%s\n", s);
}
 
int main(int argc,char** argv)
{
  if (argc>1){
    if (fopen(argv[1],"r") == NULL){
         printf("Can't read from %s\n",argv[1]);
         return 0;
    } else
         yyin = fopen(argv[1],"r");
  } else
         yyin = stdin;
         printf(">> ");
         yyparse();
}

+ le makefile.sh (scripte de compilation)
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
clear;
prog=$1
if [ $# -eq 0 ]
then prog="log" ;echo "vous n'avez pas tappez le nom de fichier \nla compilation de prog log.* "
fi
echo "\n   compilation"
echo "\t-----------------------"
#clear les fichier tempo
 rm -f *L.c  *Y.c *Y.h *.y.c *.h *.o *.lex.c *~ ;
#compile le .l
flex "$prog".l
#compile le .l
bison -d "$prog".y
cp "$prog".tab.h "$prog"Y.h
cp "$prog".tab.c "$prog".y.c
gcc -o "$prog"ique "$prog".y.c lex.yy.c -lm -lfl
 
echo "\t-----------------------\n"
et merci pour tous ce qui à réfléchis avec moi
m3asmi est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 08h36.


 
 
 
 
Partenaires

Hébergement Web