开发者

Linking Non terminals for back patching

idlist  : idlist ',' ID {
                         $$.str=$3.str;
                         $$.ptr=(idtype*)&$1;
                        }
        | ID            {
                         $$.str=$1.str;
  开发者_开发知识库                       $$.ptr=NULL;
                        }

idlist is here of type idtype. I'm a newbie to Yaac. Am I doing something stupid because, My code is looping through a single id. when I use this at one level up.

So here the grammar has type after the ID. I could use a stack to do that, but i thought this was cute .


The problem is that you're taking the address of $1, which is a local temporary that exists only for that rule action. So after the action completes, it goes away, leaving $$.ptr dangling, and pointing at memory that's going to be reused for something else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜