Bison warning: Empty rule for typed nonterminal

你离开我真会死。 提交于 2019-12-12 00:26:04

问题


I'm getting a warning I don't really understand from 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. 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 + ")") ; }
    ;

%%

回答1:


e :                                     
    | e PLUS t
    | t

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



来源:https://stackoverflow.com/questions/14887852/bison-warning-empty-rule-for-typed-nonterminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!