i am trying yo write some kind of a simple compiler that detects undeclared variable, and does some extra stuff. The problem is, i cannot use "$$" in my bison file, it says "$$ of `type' has no declared type". Here are the related parts of my flex and bison files:
flx file:
int[ \t\n]+matrix {yylval.type_id.Type = 4;return tINTMATRIXTYPE; }
bison file:
%}
%union semrec
{
struct
{
int Type;
char *id;
}type_id;
}
%start prog
%%
prog: stmtlst
;
stmtlst : stmt
| stmt stmtlst
;
tmt : decl //baktım
| asgn
| if
;
decl : type vars '=' expr ';'
;
type : tINTTYPE
| tINTVECTORTYPE
| tINTMATRIXTYPE {$$.Type=$1.Type;}
| tREALTYPE
| tREALVECTORTYPE
| tREALMATRIXTYPE
;
%%
Writing $1.Type in bison file works, but $$.Type does not work. Can anyone help? Thanks