Flex / Bison错误:basic_string :: _ S_construct null无效

时间:2013-05-28 04:17:22

标签: bison flex-lexer

我的flex文件中有以下规则:

{ID}        {printf("(id, \"%s\") [%d]\n", yytext, yylineno); yylval.str = strdup(yytext); return IDENT;}

我的野牛档案中有以下规则:

identificador            : IDENT                            {cout << "identificador : IDENT\n"; cout << $1 << "\n";$$ = $1;}

当它尝试打印$1时,我收到以下错误:

terminate called after throwing an instance of 'std::logic_error'

what():basic_string :: _ S_construct null无效

对我而言,$1似乎是NULL,但我不明白为什么。 这两个文件都很大,因为语法很大,但我可以根据需要进行编辑以添加其他相关部分。

1 个答案:

答案 0 :(得分:1)

好吧,我不知道错误的确切原因,但我设法通过更改bison文件中的%union声明来修复它。

以前是:

%union {

     int integer;

     char character;

     char* str;

     entry* e;


 };

现在是:

%union {

     struct {

         int integer;

         char character;

         char* str;

         entry* e;

     };

 };