Flex/Bison Error:request for member `str' in something not a structure or union

别说谁变了你拦得住时间么 提交于 2019-12-04 17:56:17

The first glaring problem is that you should not be defining YYSTYPE if you are using yacc. Yacc defines YYSTYPE from your %union. You need to define YYSTYPE if you're using lex, but not using yacc.

Your %union parse stack item type only contains int and str members. Example: you have defined the exp grammar symbol as having type str, and then you have this production:

exp:        term                    {$$=$1; }
            | exp PLUS term         { $$=mknode($1,$3,"+"); }
            | exp MINUS term        { $$=mknode($1,$3,"-"); }
            ;

The mknode function returns node *, but the type of the $$ symbol is char * because it stands for the exp on the left hand side, which you typed as a str, and the str member of the %union is char *.

The arguments to mknode must also be node *. But $1 and $3 do not have that type.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!