野牛文件中的Platformio编译错误
我将野牛与Flex一起使用Platformio中的Arduino框架。编译.y和.l文件没有问题,但是当我试图在平台中进行构建时,我会收到这些错误:
error: cannot convert 'str*' to 'strn*' for argument '1' to 'ast* newstrref(strn*)'
error: cannot convert 'str*' to 'strn*' for argument '1' to 'ast* newstrasgn(strn*, ast*)'
在这些功能的声明和def下:
struct ast *newstrref(struct strn *a);
struct ast *newstrasgn(struct strn *, struct ast *);
struct ast *newstrref(struct strn *s)
{
strref *a = (strref *)malloc(sizeof(strref));
if(!a) {
yyerror(OOF_MSG);
exit(0);
}
a->nodetype = STRING_REF_TYPE;
a->s = s;
return (ast *)a;
}
struct ast *newstrasgn(struct strn *s, struct ast *v)
{
strasgn *a = (strasgn *)malloc(sizeof(strasgn));
if(!a) {
yyerror(OOF_MSG);
exit(0);
}
a->nodetype = STRING_ASGN_TYPE;
a->s = s;
a->v = v;
return (ast *)a;
}
def的结构:
struct strref {
int nodetype;
struct strn *s;
};
struct strasgn {
int nodetype; /* type = */
struct strn *s;
struct ast *v; /* value */
};
struct strn {
char *name;
char *value;
};
实际上没有str struct不知道它来自哪里。也以下在.y中的行中调用错误:
strast:
STRING { $$ = newstr($1); }
| NAMESTR { $$ = newstrref($1); }
I'm using bison with flex combined with Arduino framework in Platformio. Compiling .y and .l files goes without a problem, but when I'm trying to make a Build in Platformio I got those errors:
error: cannot convert 'str*' to 'strn*' for argument '1' to 'ast* newstrref(strn*)'
error: cannot convert 'str*' to 'strn*' for argument '1' to 'ast* newstrasgn(strn*, ast*)'
below declarations and def's of those functions:
struct ast *newstrref(struct strn *a);
struct ast *newstrasgn(struct strn *, struct ast *);
struct ast *newstrref(struct strn *s)
{
strref *a = (strref *)malloc(sizeof(strref));
if(!a) {
yyerror(OOF_MSG);
exit(0);
}
a->nodetype = STRING_REF_TYPE;
a->s = s;
return (ast *)a;
}
struct ast *newstrasgn(struct strn *s, struct ast *v)
{
strasgn *a = (strasgn *)malloc(sizeof(strasgn));
if(!a) {
yyerror(OOF_MSG);
exit(0);
}
a->nodetype = STRING_ASGN_TYPE;
a->s = s;
a->v = v;
return (ast *)a;
}
def's of structs:
struct strref {
int nodetype;
struct strn *s;
};
struct strasgn {
int nodetype; /* type = */
struct strn *s;
struct ast *v; /* value */
};
struct strn {
char *name;
char *value;
};
Actually there is no str struct thus I have no idea where it came from. Also below lines in .y which invoke error:
strast:
STRING { $ = newstr($1); }
| NAMESTR { $ = newstrref($1); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,错误的原因在于您选择不共享的
.y
文件的一部分。因此,不可能确定问题是什么。但是我想您会在%令牌
声明中找到错字。 [注意1]请注意,在C和C ++中(从错误消息来看,您似乎都在使用C ++编译),只需提及
struct str
即可以它作为一个不完整的类型。此外,创建指向不完整类型的指针是合法的(常见)。因此,如果您在代码中的某个地方编写struct str*
而不是struct strn*
,则不会创建任何类型的错误或警告 - 直到您尝试使用错误声明变量。在我看来,这里发生了什么。但这只是一个猜测。在C中写作,我更喜欢使用标签和Typedef的同名我的结构。因此,我会写
我喜欢这种风格的原因之一,它可以保护我免受这种错字的保护。与
struct typo
不同,键入Typedef名称通常会导致未定义的符号警告。但这就是我。 YMMV。 (并且在C ++中无济于事,在C ++中,Typedef是多余的。)(实际上,我更喜欢在骆驼中编写类型,但这在这里并不相关。)
尤其是
Evidently, the cause of the error is in the part of the
.y
file which you chose not to share. So it's not going to be possible to say for sure what the problem is. But I guess you will find a typo in your%token
declarations. [Note 1]Note that in both C and C++ (and you seem to be compiling with C++, judging from the error message), it's sufficient to just mention
struct str
for it to leap into existence as an incomplete type. Moreover, it's legal (and common) to create a pointer to an incomplete type. So if somewhere in your code you writestruct str*
instead ofstruct strn*
, that will not create any kind of error or warning -- until you try to use the incorrectly declared variable. That looks to me like what's going on here. But it's just a guess.Writing in C, I prefer to always
typedef
my structs, using the same name for the tag and the typedef. So I would have writtenOne of the reasons I like that style is that it gives me some protection from this sort of typo. Unlike
struct typo
, typing a typedef name incorrectly usually leads to an undefined symbol warning. But that's just me. YMMV. (And it doesn't help so much in C++, where the typedefs are redundant.)(Actually I prefer to write typenames in CamelCase, but that's not relevant here.)
Notes