www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/07/12/20:59:01

From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bison problem
Date: Fri, 12 Jul 2002 23:45:04 +0100
Lines: 50
Message-ID: <3D2F5BF0.8DCC1221@phekda.freeserve.co.uk>
References: <2002712-174257-175451 AT foorum DOT com>
NNTP-Posting-Host: modem-233.tin.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg3.svr.pol.co.uk 1026514756 1630 62.136.41.233 (12 Jul 2002 22:59:16 GMT)
NNTP-Posting-Date: 12 Jul 2002 22:59:16 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586)
X-Accept-Language: de,fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello.

maxam_80 wrote:
[snip]
> 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.

What errors do you get?

[snip]
> /************************/
> /* 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); }
>    ;
[snip]

I think you need an empty branch, so that Expression can terminate. Also, you
should use left-recursion, so that the memory usage is bounded. I think you
should try something like this:

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

Ah, but then your string will be constructed in the wrong order, I think.
Hmmm.

Regards,

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


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