tags:

views:

200

answers:

1

Hi

I'm a little confused about how to specify my grammar member's type. I want to declare prog and decls as ASTNode. I'm gonna use these members for adding to a list or etc. But yacc can't recognize them as an ASTNode and I get type errors.

Here my tIdent,tCharConst,tIntConstant have some types but, how to give ASTNode type to my members.

%union{
  int ival;
  char cval;
  char *sval;
  struct ASTNode *nval;
}

%token <sval> tIdent
%token <cval> tCharConst
%token <ival> tIntConst

    prog          : decls ;
    decls         : /* empty */
                  | decls decl
                  ;
+1  A: 

At the very beginning of your .y file, you need something like

%{
struct ASTNode { ... };
%}

in order to declare the type of ASTNode. Or you might instead put it in a .h file:

%{
#include "astnode.h"
%}
%union { 
  ...
}
%term ...

and so on.

Norman Ramsey