简单的字符串通过Bison/Yacc中的节点传递 [英] Simple string passing through nodes in Bison/Yacc

查看:64
本文介绍了简单的字符串通过Bison/Yacc中的节点传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在yacc文件的语义规则中连接字符串:

I have to concatenate strings in semantic rules of my yacc file:

%union {
  stringstream sstream;
}
%type<sstream> node1 node2

---

node1
: node2 { $$ << $1 << " goodbye" }

node2
: final { $$ << "hello" }

但是,由于在联合中不允许使用stringstream甚至string,所以我找不到任何简单的方法来混合char *int并使节点传输我可以在任何地方操纵的字符串. 我该怎么办?

However, as stringstream or even string are not allowed in unions, I don't find any easy way to mix char *, int, and make nodes transport a string that I can manipulate everywhere. How should I do it ?

推荐答案

我不记得bison/yacc的详细信息,但是您可以使用指针和new.只要记住delete,如果bison/yacc给您机会.

I don't remember bison/yacc details, but you sure can use pointer and new it. Just remember to delete if bison/yacc gives you the opportunity.

这篇关于简单的字符串通过Bison/Yacc中的节点传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆