野牛语法警告 [英] Bison grammar warnings

查看:115
本文介绍了野牛语法警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Bison编写一个解析器,并且收到以下警告.

I am writing a parser with Bison and I am getting the following warnings.

fol.y:42 parser name defined to default :"parse"
fol.y:61:  warning:  type clash ('' 'pred') on default action

我一直在使用Google搜索摆脱它们的方法,但是由于我发现与它们有关的每篇文章都有一个编译错误,因此几乎空洞了它们的含义(更不用说如何修复它们了)他们自己的警告也没有得到解决.有人可以告诉我它们的含义以及如何解决它们吗?相关代码如下.第61行是最后一个分号.我删掉了语法的其余部分,因为它非常冗长.

I have been using Google to search for a way to get rid of them, but have pretty much come up empty handed on what they mean (much less how to fix them) since every post I found with them has a compilation error and the warnings them selves aren't addressed. Could someone tell me what they mean and how to fix them? The relevant code is below. Line 61 is the last semicolon. I cut out the rest of the grammar since it is incredibly verbose.

%union {
    char* var;
    char* name;
    char* pred;
}


%token <var> VARIABLE
%token <name> NAME
%token <pred> PRED

%%


fol:
        declines clauses {cout << "Done parsing with file" << endl;}
        ;
declines:
        declines decline
        |decline
        ;
decline:
        PRED decs
        ;

推荐答案

第一条消息很可能只是警告您语法规范中未包含%start parse.

The first message is likely just a warning that you didn't include %start parse in the grammar specification.

第二个意思是某处您有应该返回值的规则,但是您没有正确指定要返回的值的类型. PRED返回unionpred元素;问题可能是您尚未为declinedeclines创建%type条目.如果有联合,则必须为大多数(如果不是全部)规则指定类型-或只是没有明确动作的规则(以便覆盖默认的$$ = $1;动作).

The second means that somewhere you have rule that is supposed to return a value but you haven't properly specified which type of value it is to return. The PRED returns the pred element of your union; the problem might be that you've not created %type entries for decline and declines. If you have a union, you have to specify the type for most, if not all, rules — or maybe just rules that don't have an explicit action (so as to override the default $$ = $1; action).

我不认为问题出在您指定的行中,并且由于我们没有完整,最少的问题重现,因此我们无法为您进行验证. decs的规范可能是相关的(我不相信这是正确的,但可能如此).

I'm not convinced that the problem is in the line you specify, and because we don't have a complete, minimal reproduction of your problem, we can't investigate for you to validate it. The specification for decs may be relevant (I'm not convinced it is, but it might be).

您可能会从y.output文件(或类似文件)的bison -v输出中获得更多信息.

You may get more information from the output of bison -v, which is the y.output file (or something similar).

这篇关于野牛语法警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆