开发者

Linking Non terminals for back patching

开发者 https://www.devze.com 2023-04-11 11:57 出处:网络
idlist: idlist \',\' ID { $$.str=$3.str; $$.ptr=(idtype*)&$1; } ID{ $$.str=$1.str; 开发者_开发知识库$$.ptr=NULL;
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

精彩评论

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