2013-02-15 38 views
0

我收到一条警告,我从Bison不太明白。野牛警告:输入非终结符的空规则

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

这是我的每个非终端字符。我不明白的部分是,如果我不给他们一个类型,那么我会得到编译错误,指出所有$ ns都是未定义的。这是我的野牛文件的语法部分。

%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 + ")") ; } 
    ; 

%% 

回答

2
e :          
    | e PLUS t 
    | t 

e: | e PLUS t | t,就是什么e PLUS tt。删除第一个|