This is my .lex file:
"Sphere" {return SPHERE;}
"(" {return LBRACKET;}
")" {return RBRACKET;}
"." {return DOT;}
[a-zA-Z][a-zA-Z0-9]* {yylval.s = yytext; return NAME;}
[ \t\n]+ /* ignore */
. return yytext[0];
This is my bison .y file:
%union {
char* s;
double d;
int i;
}
/* Operators */
/* Tokens */
%token ALPHANUM
%token SPHERE
%token LBRACKET
%token RBRACKET
%token DOT
%token NAME
/* type declarations */
%type<s> NAME
%%
sentence: SPHERE LBRACKET NAME RBRACKET DOT
{
printf("%i\n", $3);
}
;
The error I get is:
“request for member ‘s’ in something not a structure or union”
Thank you for any help
If I’m not mistaken,
NAMEis a terminal. Therefore, the correct way of declaring its type is this:%typeis used only for nonterminals.