[英]Bison warning: Empty rule for typed nonterminal
我收到一個警告,我對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 + ")") ; }
;
%%
e :
| e PLUS t
| t
是e: | e PLUS t | t
e: | e PLUS t | t
e: | e PLUS t | t
,也就是說, 沒有或者e PLUS t
或t
。 刪除第一個|
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.