我正在flex和bison中构建一个编译器.问题是使用char *会带来很多问题,所以我试图将所有内容迁移到string.
剩下的唯一问题是有一个union字符串.我知道这不是标准,但通过使用指针应该没有问题.
相关代码:
#include <string>
using namespace std;
//-- SYMBOL SEMANTIC VALUES -----------------------------
%union {
struct lc{
string * code;
string * start;
string * verdadero;
string * falso;
string * next;
}code;
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是我收到的错误:
file.ypp:39:6: error: ‘string’ does not name a type
string * start;
file.ypp:40:6: error: ‘string’ does not name a type
string * verdadero;
file.ypp:41:6: error: ‘string’ does not name a type
string * falso;
file.ypp:42:6: error: ‘string’ does not …Run Code Online (Sandbox Code Playgroud)