1

バイソンでセマンティック分析を行っていますが、トークンに関連付けられた複数の属性を使用したいと考えています。私のコードの関連部分は次のとおりです。

%union semrec
{
    int Type;
    char *id;

}

%start prog

%token <id>  tIDENT

ここでは、tIDENT トークンで「id」属性のみを使用できます。また、「Type」属性を tIDENT トークンに関連付けたいと考えています。これを行うために、私は次のことを試しました:

 %token <id>  tIDENT
 %token <Type>  tIDENT

しかし、トークン tIDENT の再宣言の警告が表示されます。私も次のことを試しました:

 %token <id> <Type> tIDENT

それもうまくいきませんでした。私に何ができる?これはちょっとした構文上の問題だと思います。

ありがとうございました。

4

1 に答える 1

2

You cannot do it this way: you have to define your %union in such a way that all the symbols that have multiple "attributes" have a struct to define all these "attributes". Something like

%union
{
  struct
  {
    int type;
    char *id;
  } type_id;
}
%type <type_id> tIDENT

and use $1.type or $1.id etc.

Note however that I very much doubt that you're doing the right thing. Chances are high that you will need an AST (Abstract Syntax Tree). You should look for information about that.

于 2013-03-29T08:43:06.453 に答える