help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string token


From: Hans Aberg
Subject: Re: string token
Date: Tue, 2 Dec 2003 20:52:14 +0100

At 12:02 +0000 2003/12/02, Nosnos wrote:
>I have a newbies problem, but could not find the solution.
>
>My bison file has something like that :
>
>%token <string> STR1
>%token <string> STR2
>
>example : STR1 STR2            { printf(STR1); printf(STR2);}
>;
>
>my flex has something like that :
>
>[...]
>"toto"    ncpy(yylval.string, yytext, yyleng); return STR1;
>"tata"    ncpy(yylval.string, yytext, yyleng); return STR2;
>[...]
>
>
>Even the contains of STR1 and STR2 are different, my printf return me the
>same string for STR1 and STR2.....
>
>
>What's wrong ?

In your C printf statement, you use the token numbers as format strings,
and no output data, so the effect is undefined according to the C standard.
So it is a question of writing correct C code, not a Help-Bison problem.

You might try an action like
    printf("...%s...%s...", $1, $2);
or
    printf("...%s...%s...", $1.string, $2.string);
depending on whether %union is used or not.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]