简体   繁体   English

Bison警告:键入非终结符号的空规则

[英]Bison warning: Empty rule for typed nonterminal

I'm getting a warning I don't really understand from Bison. 我收到一个警告,我对Bison并不是很了解。

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

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. 我不明白的部分是,如果我不给它们一个类型,那么我得到编译错误,说明所有的$ ns都是未定义的。 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

Is e: | e PLUS t | t e: | e PLUS t | t e: | e PLUS t | t e: | e PLUS t | t , that is, nothing or e PLUS t or t . e: | e PLUS t | t ,也就是说, 没有或者e PLUS tt Remove the first | 删除第一个| .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM