-1

I get the following error when i run my Parser file ( binary got after compiling Flex/Bison files). error: syntax error, unexpected TKN_PRIMARY, expecting end of file

Here is rule defined in flex code:

<PRIMARY_MME_STATE>{number} {
 lexVal = YYText();
 std::cout<<"PRIMARY MME -->  "<<lexVal<<std::endl;
 yylval->strVal = new std::string(lexVal);
 return token::TKN_PRIMARYMME;
 }

And my understanding is that since value of TKN_PRIMARY is zero ( which is the value defined for END %token END 0 "end of file") Instead of returning TKN_PRIMARY , it is expecting token END to be returned. Please comment if my understanding is correct . And Also how to tackle this issue.

4

1 回答 1

1

如果TKN_PRIMARYEND具有相同的值(或者,一般来说,如果任何两个不同的标记具有相同的值),那么野牛解析器将以不可预测的方式运行。

引用野牛手册

但是,通常最好让 Bison 为所有令牌类型选择数字代码。Bison 会自动选择不相互冲突或与正常字符不冲突的代码。

我认为这绝对是解决问题的最佳方式。

于 2013-05-21T19:27:11.653 回答