2013-02-15 35 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。刪除第一個|