help-bison
[Top][All Lists]
Advanced

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

Re: String concatenation?


From: Kevin Milner
Subject: Re: String concatenation?
Date: Tue, 3 Jun 2003 18:31:11 +0200

So in the scanner I should just do something like this, right?

{  yylval.strval = strdup(yytext); .... }

So what happens to this string at a later time? Do I need to free it in the
parser?
Thanks for your help,
Kevin Milner

----- Original Message -----
From: "Hans Aberg" <address@hidden>
To: "Kevin Milner" <address@hidden>
Cc: <address@hidden>
Sent: Tuesday, June 03, 2003 05:08 AM
Subject: Re: String concatenation?


> At 17:03 -0500 2003/06/02, Kevin Milner wrote:
> >Hello, I'm using Bison and Flex to make a specialized XML parser to
handle a
> >SOAP response. The problem I am having is that when I try to assign a
value
> >to a nonterminal, as in the following:
> >
> >xmlopen: OPENTAG tagname paramlist CLOSETAG {     $$.value = $2.value;
> >                        sprintf(buff, "xmlopen(%s)-> < tagname paramlist
>",
> >$$.value);
> >                        PrintRule(buff);
> >       }
> >
> >I get $2.value = "whatevertagname whateverparams >", as if xmlopen is
> >assigned the value of everything from the point I am interested in to the
> >end of the statement.
>
> This is one of the most common questions in this list: Probably you use
> Flex to generate a lexer. This lexer then merely supplies a pointer in a
> buffer to the identified text and nullterminates it. At the next call, it
> restores the buffer for the next identification.
>
> Thus, if you want to use the strings the lexer identifies at a later point
> in time, you must make a clone of it.
>
> >I'm using a struct that simply contains a char * called value. I tried
this
> >thinking that it would solve the problem, but the same thing happens if I
> >simply use %type char* on everything.
> >Can anyone help me understand the way that strings are assigned to
> >nonterminals in Bison?
>
> The Bison generated parser does absolutely nothing, except what tell it to
> do in the actions. The parser just reads the numbers it gets from the
lexer
> and lets you to execute actions at the appropriate times.
>
>   Hans Aberg
>
>
>






reply via email to

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