野牛警告:输入非终结符的空规则 [英] Bison warning: Empty rule for typed nonterminal

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

问题描述

我正在从野牛那里得到一个我不太理解的警告.

I'm getting a warning I don't really understand from Bison.

warning: empty rule for typed non-terminal, and no action

适用于我的每个非终止字符.我不了解的部分是,如果不给它们指定类型,则会出现编译错误,指出所有$ ns都未定义.这是我的野牛文件的语法部分.

it's for each of my non-terminal characters. The part I don't understand is that If I don't give them a type then I get compilation errors stating that all of the $ns are undefined. Here's the grammar section of my bison file.

%union {
  char *sval;
}

%token <sval> PLUS TIMES LPAREN RPAREN ID
%type  <sval> s e t f 
%%

s : e                   { cout << GetNonConstCharStar(std::string("(e ") + $1 + ")") << endl; }

e :                                     
    | e PLUS t          { $$ = GetNonConstCharStar(std::string("(e ") + $1 + ")" + " (PLUS " + $2 + ") " + "(t " + $3 + ")" ); }
    | t                 { $$ = GetNonConstCharStar(std::string("(t ") + $1 + ")"); }
    ;
t : 
    | t TIMES f         { $$ = GetNonConstCharStar(std::string("(t ") + $1 + ")" + " (TIMES " + $2 + ") " + "(f " + $3 + ")"); }  
    | f                 { $$ = GetNonConstCharStar(std::string("(f ") + $1 + ")"); }
    ;

f :  
    | LPAREN e RPAREN   { $$ = GetNonConstCharStar(std::string("(LPAREN \\")+ $1 + ") (e " + $2 + ") (RPAREN \\" + $3 + ")") ; }
    | ID                { $$ = GetNonConstCharStar(std::string("(ID ") + $1 + ")") ; }
    ;

%%

推荐答案

e :                                     
    | e PLUS t
    | t

e: | e PLUS t | t,即e PLUS tt.删除第一个|.

Is e: | e PLUS t | t, that is, nothing or e PLUS t or t. Remove the first |.

这篇关于野牛警告:输入非终结符的空规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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