0
これらの要素のメモリ位置が必要なので、私はバイソンの構造体の構造体の構造体へのポインタを使用するのにいくつかの問題がありますが、すべてseem to point to the same union positionです。わからない場合は、私は正しい方法を使用しています。私のコードは次のようになります。Cおよびbison:%UNION定義の構造体へのポインタ
main.h:
typedef struct _control *control;
struct _control { ... };
typedef struct _symbol *symbol;
struct _symbol { ... };
...
#include "parser.h"
parser.y
それはそれを行うための正しい方法ですが、私はちょうど私の組合要素が一度マッピングされてしまった場合%{
#include "main.h"
%}
%union {
control ctrl;
symbol s_head;
symbol s_tail;
}
...
%%
...
%%
int main (int argc, char** argv) {
...
yylval.ctrl = malloc(sizeof(struct _control));
yylval.s_head = malloc(sizeof(struct _symbol));
yylval.s_tail = malloc(sizeof(struct _symbol));
// This will give me the same memory position
printf("%ld %ld %ld %ld\n",
yylval, yylval.ctrl,
yylval.s_head, yylval.s_tail);
...
}
Bison(前身のYaccと同じ)は、 '%union'はCの' union'を宣言しています。 –