链接非终端以进行反向修补
idlist : idlist ',' ID {
$$.str=$3.str;
$$.ptr=(idtype*)&$1;
}
| ID {
$$.str=$1.str;
$$.ptr=NULL;
}
idlist 这里是 idtype 类型。我是 Yaac 的新手。我是否在做一些愚蠢的事情,因为我的代码正在循环访问单个 id。当我在更高一级使用它时。
所以这里的语法在 ID 之后有类型。我可以使用堆栈来做到这一点,但我认为这很可爱。
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 .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在获取
$1
的地址,该地址是仅针对该规则操作而存在的本地临时地址。因此,在操作完成后,它就会消失,留下$$.ptr
悬空,并指向将被重用于其他用途的内存。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.