我需要使用flex和野牛来解析一些代码。野牛YYSTYPE:试图使用char *
YYSTYPE的默认类型是int
,尽管我从来没有这样声明过。这是来自野牛的默认值吗?
这将帮助我很多传递字符串回来。我读到:How to solve Bison warning "... has no declared type"这看起来很不错。 (我不需要联盟的全部力量,只是char *部分,但我可能会使用联盟,因为它稍后可能会有所帮助。)
它不适合我。我得到这些错误:
y:111.37-38: $1 of `ConstExpression' has no declared type
y:113.34-35: $1 of `ConstFactor' has no declared type
y:114.35-36: $1 of `ConstFactor' has no declared type
y:119.34-35: $1 of `Type' has no declared type
y:109.23-48: warning: type clash on default action: <str> != <>
y:115.23-27: warning: type clash on default action: <str> != <>
[...more of the same snipped...]
下面是我y
语法文件的声明:
%union {
char *str;
}
%type<str> ConstExpression ConstFactor Type
这里是我的.l
文件中的一行:
[a-zA-Z]+[a-zA-Z0-9]* { yylval.str = strdup(yytext); return yident;}
还有什么我需要要做什么来解决错误?
你真的认为人们可以调试你的语法文件,没有看到它来定义类型的令牌? – 2009-11-22 11:25:03
@Kinopiko,你认真对待这个,是因为他不仅仅是把他的整个作业都粘贴在里面,并且说“给我看代码”?它会杀了你只说:“我需要更多的信息,请发布整个语法文件”或者其他的? – steveha 2009-11-22 20:01:00
@Kinopiko,当他发布你所请求的信息时,你会撤销你的downvote吗?这看起来很苛刻。 – steveha 2009-11-22 20:01:44