これがyacc file.yの私のトップです
%code requires {
struct Id {
char *var;
};
struct Commds;
struct Commd {
struct Id lhs;
};
struct Commds {
struct Commd commd;
struct Commds *next;
};
}
このコードを使用して%union
、パーサーの新しい型を定義しました。
%union {
char *id;
long long integer;
struct Id Identifier;
struct Commd Command;
struct Commds *Commands;
}
....
%type <Command> command
%type <Commands> commands
$$
レクサーからのトークンを評価している間に解析ツリーが構築されている間、 -dollars 属性でそれを使用しても問題ありません。残念ながら、セクションの他のメソッドでファイルの先頭に定義されている構造を使用したいと思います%{ codes %}
。残念ながら、次のように関数を定義するたびに:
void add(struct Commd cmd) {...};
エラーが表示されます: タイプが不明です! この構造体をパーサー全体から見えるようにする方法を教えていただければ幸いです。