www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/07/12/19:55:45

From: maxam_80 <maxime_paquet AT yahoo DOT fr>
Newsgroups: comp.os.msdos.djgpp
Subject: Bison problem
Date: 12 Jul 2002 16:42:57 GMT
Message-ID: <2002712-174257-175451@foorum.com>
NNTP-Posting-Host: 195.101.164.38
NNTP-Posting-Date: 12 Jul 2002 16:42:57 GMT
X-Complaints-To: abuse AT foorum DOT fr
X-POSTER: foorum.com
X-Foorum_user_tmp_id: 2001929-105455-705548-195.101.164.38-
X-Originating-User: 195.101.164.38
X-Newsreader: Foorum
Lines: 114
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello,

Well, I need some help on Bison, the syntaxic analyser. My problem is to parse 
an input, and store semantic values into c-strings.

When I run Bison with standard data type, i.e int, no problem, I successfully 
compile. But when I compile it on string-oriented version of the same grammar, 
it fails.

Thanks

maxam_80.

P.S : Here is my grammar

/*****************/
/* Declaration C ******************************************************/

%{
   #include <string.h>
   #define YYSTYPE char*
   #define LG_LIGNE 256
%}

/*********************/
/* Declaration BISON **************************************************/

/************************/
/* Regles grammaticales ***********************************************/

%%
   Entree :
      /* Epsilon */     { ; }
   |  Ligne Entree      { ; }
   ;

   Ligne :
      '\n'              { $$ = memset($$, 0, LG_LIGNE); }
   |  Expression '\n'   { $$ = memset($$, 0, LG_LIGNE);
                          printf("\t%s\n", $1);
                        }
   ;

   Expression :
      Chiffre Expression   { $$ = strcat($$, $1);
                             $$ = strcat($$, $2);
                           }
   |  Chiffre              { $$ = strcat($$, $1); }
   ;

   Chiffre :
      '0'   { $$ = memset($$, '0', 1); }
   |  '1'   { $$ = memset($$, '1', 1); }
   |  '2'   { $$ = memset($$, '2', 1); }
   |  '3'   { $$ = memset($$, '3', 1); }
   |  '4'   { $$ = memset($$, '4', 1); }
   |  '5'   { $$ = memset($$, '5', 1); }
   |  '6'   { $$ = memset($$, '6', 1); }
   |  '7'   { $$ = memset($$, '7', 1); }
   |  '8'   { $$ = memset($$, '8', 1); }
   |  '9'   { $$ = memset($$, '9', 1); }
   ;

%%

/**********************/
/* Code C additionnel *************************************************/

   #include <stdio.h>

   yylex()
   {
      int c;

      c = getchar();

      /******************/
      /* Fin de fichier ***********************************************/

      if (c == EOF) { return (0); }

      yylval = memset(yylval, c, 1);

      return (c);
   }

   /************************/
   /* Fonction de controle ********************************************/

   int main()
   {
      int rc = 0;

      yyval = malloc(LG_LIGNE * sizeof(char)); /* where allocate $$ ??? */
      rc = yyparse();
      free(yyval);
      return(rc);
   }

   /********************/
   /* Message d'erreur ************************************************/

   #include <stdio.h>

   yyerror(char* s)
   {
      printf("%s \n", s);
   }



-- 
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019