Bison からよくわからない警告が表示されます。
warning: empty rule for typed non-terminal, and no action
それは私の非端末文字のそれぞれのためです。私が理解していない部分は、型を指定しないと、すべての $ns が未定義であることを示すコンパイル エラーが発生することです。これが私のbisonファイルの文法セクションです。
%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 + ")") ; }
;
%%