help-bison
[Top][All Lists]
Advanced

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

Re: Trouble with yytext


From: David Durham
Subject: Re: Trouble with yytext
Date: Fri, 7 Dec 2001 19:07:50 +0100

Hans Aberg wrote:

>At 01:47 -0800 2001/12/07, ROLAND wrote:
>
>>scomstr()
>>{ if (logflag)
>>  strcat(comstring,yytext);
>>}
>>
>
>Here you concatenate the strings flex finds, instead of making new copies,
>like when using strcpy, which looks funny to me.
>
And I was going to add: if you didn't know, strcat merely finds the null
char at the end of comstring and starts copying yytext in that place
overwriting that null and then adds a new null char at the end of the
total string. Hence, the warning: comstring would need to contain enough
space for all your tokens concatted together.  Hans has prescribed a
different and probably better way in the long run, but if you plan to
stick with you current method, I would surely do a realloc on comstring
each time to ensure that there is enough space for yytext. And unless
you maintain a comstring_len variable it will get more and more
inefficient since strcat will be searching for the null char on longer
and longer strings as the parser progresses.





reply via email to

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