开发者

Getting $$ to hold the concatenation of $1 & $2

开发者 https://www.devze.com 2023-02-27 06:47 出处:网络
I need to combine phrases together as a sentence and pass that as words. I have a yacc rule which states:

I need to combine phrases together as a sentence and pass that as words. I have a yacc rule which states:

words : words WORD  {
                if($1 == NULL)
                {
                    $$ = $2;
                }
                else
                {
                    printf("\t$1 = %s\n",$1);
                 开发者_如何学编程   printf("\t$2 = %s\n",$2);
                    strBuffer[0]='\0';
                    strcat((char *)strBuffer,$1);
                    $$ = strcat((char *)strBuffer,$2);
                    printf("\t$$ = %s\n\n",$$);                             
                }
            }

char strBuffer[200] is a sufficiently large global array.

But when I run the parser, I get:

$1 = The G
$2 = nats and 
$$ = nats and           

What should I do so that both $1 & $2 make it into $$?


Try:

sprintf($$, "%s%s", $1, $2);
0

精彩评论

暂无评论...
验证码 换一张
取 消