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

GCC Discussion :

compilation gcc tmp


Sujet :

GCC

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Mars 2010
    Messages : 10
    Points : 8
    Points
    8
    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 : 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
    %{
    #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 : 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
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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?!

  2. #2
    Membre averti Avatar de uriotcea
    Homme Profil pro
    Ingénieur / physicien
    Inscrit en
    Septembre 2003
    Messages
    1 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2003
    Messages : 1 301
    Points : 444
    Points
    444
    Par défaut
    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 ?

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Mars 2010
    Messages : 10
    Points : 8
    Points
    8
    Par défaut
    voila la résolution
    log.l
    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
     
    %{
    #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 : 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
    %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 : 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
    #!/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

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

Discussions similaires

  1. Compilation gcc avec upnp
    Par YuGiOhJCJ dans le forum C
    Réponses: 6
    Dernier message: 25/05/2010, 12h42
  2. [debutant] compilation gcc et makefile
    Par harsh dans le forum Systèmes de compilation
    Réponses: 4
    Dernier message: 08/06/2006, 18h30
  3. Compilation gcc -shared -c *.c Puis archivage ?
    Par FrigoAcide dans le forum Autres éditeurs
    Réponses: 4
    Dernier message: 09/05/2006, 10h24
  4. Erreur compilation GCC
    Par KnightsOfTheRound dans le forum GCC
    Réponses: 8
    Dernier message: 07/11/2005, 15h28
  5. Option de compilation gcc : sem.h
    Par Luther13 dans le forum Linux
    Réponses: 8
    Dernier message: 29/12/2004, 12h29

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