expected specifier qualifier

I always got the following error:

In file included from scanner.l:2:
y.tab.h:24: error: expected specifier-qualifier-list before âExprTypeâ
scanner.l: In function âyylexâ:
scanner.l:67: error: âYYSTYPEâ has no member named âattributesâ


My %union in the parse.y looks something like this:

%union
      {
      ExprType etype;
      struct Attributes
            {
            char name[50];
            int intcharval;
            char strval[100];
            int actualvalue;
            int lvalue ;
            int dtype ;
            /* for symbol table*/
            int enumtype;
            struct ExprNode* node;
            } attributes;
            
      };

can you tell me what I should do? clearly there is an attributes that be accessed by yylval, the exact call at the scanner is:

{id}             { strcpy(yylval.attributes.name,yytext); return TID;}


I've also included y.tab.h in the scanner file
kuntilanakAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
How and where is ExprType defined ?
0
kuntilanakAuthor Commented:
it's declared on a tree.h and I already included that in the parse.y file, it looks something like this:


typedef enum{
	T_EXPR_INTCON,
	T_EXPR_STRINGCON,
	T_EXPR_CHARCON,//
 
	T_EXPR_VARIABLE,
	T_EXPR_ARRAY,
	T_EXPR_FUNCALL,
 
	T_EXPR_ADD,
	T_EXPR_SUB,
	T_EXPR_MUL,
	T_EXPR_DIV,
	T_EXPR_UMINUS,
 
	T_EXPR_REOP_GT,
	T_EXPR_REOP_LT,
	T_EXPR_REOP_LE,
	T_EXPR_REOP_GE,
	T_EXPR_REOP_NE,
	T_EXPR_REOP_EQ,
 
	T_EXPR_NOT,
	T_EXPR_AND,
	T_EXPR_OR,
 
	//T_FUNCAL_ENTRY,//could be in expr, also could be in stamtment
 
	T_TYPE_INT,
	T_TYPE_ARRAY_INT,
	T_TYPE_CHAR,
	T_TYPE_ARRAY_CHAR,
	T_TYPE_VOID,// an fun could has no return, thus has void, it is necessary to check error, like a+f(b), but f has no return,
	T_TYPE_BOOL,
	T_TYPE_STRINGCON,
	T_EXTERN,
 
	T_NOT_FOUND,//return when look up a variables not found,
 
 
	T_STMT_IF,
	T_STMT_IFELSE,
	T_STMT_WHILE,
	T_STMT_FOR,
	T_STMT_RETURN,
	T_STMT_FUNCALL,
	T_STMT_ASSIGN_VAR,
	T_STMT_ASSIGN_ARRAY,
 
 
	// include the array,
	// to think, if it is array, it should have a
	// arrayExp point to an Integer constant
	T_DCL_VAR_INT,
	T_DCL_VAR_CHAR,
 
	T_DCL_ARRAY_INT,
	T_DCL_ARRAY_CHAR,
 
	T_DCL_ARRAYLEN,
 
	T_DCL_EXTERN_VAR_INT,
	T_DCL_EXTERN_VAR_CHAR,
 
	T_DCL_EXTERN_ARRAY_INT,
	T_DCL_EXTERN_ARRAY_CHAR,
 
 
	T_DCL_FUN_VOID,
	T_DCL_FUN_INT,
	T_DCL_FUN_CHAR,
	T_DCL_FUN_STRING,
 
 
	T_DCL_FUN_EXTERN_VOID,
	T_DCL_FUN_EXTERN_INT,
	T_DCL_FUN_EXTERN_CHAR,
 
	T_FUN_BODY_INT,//used
	T_FUN_BODY_CHAR,//used
	T_FUN_BODY_VOID,//used
 
	T_PARAM_VAR_INT,
	T_PARAM_VAR_CHAR,
	T_PARAM_ARRAY_INT,
	T_PARAM_ARRAY_CHAR,
	T_PARAM_VOID,
 
	T_SYM_INT,
	T_SYM_CHAR,
	T_SYM_VOID
 
 
	} ExprType;

Open in new window

0
Infinity08Commented:
>> and I already included that in the parse.y file

In the correct location ?

Can you post your parse.y file (or at least the start of it)
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

kuntilanakAuthor Commented:
Here's the start of it:
%{
#include <stdio.h>funcCallEnded=1
#include <stdlib.h>
#include <string.h>
 
#define YYDEBUG 1
#define YYERROR_VERBOSE 1
#include "globals.h"
#include "tree.h"
#include "threeaddress.h"
#include "codegen.h"
#include "intermediate.h"
#include "syntaxtree.h"
 
extern int linenumber;
extern char *yytext;
 
/* variable declaration */ 
struct symEntry *sym_table, *GlobalFuncDefPtr;
struct allVarList *varList;
char *GlobalidName,assignVarCode[500],assignArrCode[500], forArrayAssign[500],paramStr[1000];
char GlobalFuncName[100],arrTemp[1000],arrTemp1[1000];
char *idList[100], *funcList[100], *paramList[100];
 
int i, local,GlobalIntcon[100],GlobalArrayflag[100],GlobalFuncflag, GlobalfuncNum, GlobalparamCount,loopvar, GlobalArrayParam, GlobalFuncDefFlag=0;
int GlobalExternFlag,funcfound,GlobalFuncArgTypes[50],GlobalArgCount,GlobalFuncCallFlag,returnSeen=0,globalOffset=0,localOffset=0;
int globalParamOffset=0;
int stringCount;
 
char treePresentFuncDef[50];
enum DataTypes GlobalDataType, GlobalFuncRetType, GlobalParamType[100],ToCheckReturnType;
enum EntryType GlobalEntryType;
struct ExprNode *pGlobal;
char *forStrings[2000];
 
TA_NODE *taNodeList, *taStringList, *taFuncList;
 
 
 
int functionCalledOrNot ;
%}
 
%union
	{
	ExprType etype;
	struct Attributes
		{
		char name[50];
		int intcharval;
		char strval[100];
		int actualvalue;
		int lvalue ;
		int dtype ;
		/* for symbol table*/
		int enumtype;
		struct ExprNode* node;
		} attributes;
		
	}; 
 
%token	<attributes>	TID		268
%token	<attributes>	TINTCON	269
%token  <attributes>	TCHARCON	270
%token	<attributes>	TSTRCON	271
%token	TDEQUALS	265
%token	TNEQUALS	274
%token TLE		275
%token	TGE		276
%token	TIF		260
%token	TELSE	 	261
%token	TWHILE		262
%token	TFOR		263
%token	TRETURN	264
%token	TEXTERN	266
%token	TVOID		267
%token	TCHAR		272
%token	TINT		273
%token TDAMP		277
%token TDPIPE		278
%token TNOT		279
%left TDPIPE
%left TDAMP
%left '+' '-'
%left '*' '/'
%right TNOT NEG
 
%type	<attributes>	prog dcl decltemp1 decltemp5 var_decl type  openp parm_types parmtypestemp1 parmtypestemp2 parmtypestemp3 func funtemp1 stmt idtemp boolexp stmnttemp1 stmnttemp4 expr exptemp2 exptemp3 exptemp4 paramtemp declsemicolontemp funcstarttemp declvarsemicolontemp intcontemp
 
%type	<etype>		relop

Open in new window

0
Infinity08Commented:
The part between %{ and %} is only put in the y.tab.c file, not the y.tab.h file, so in y.tab.h, you don't have the ExprType defined when it's used in the %union.
0
kuntilanakAuthor Commented:
so how can I resolve this issue?
0
Infinity08Commented:
Make sure that ExprType is defined before it's used :)
0
kuntilanakAuthor Commented:
so I should copy and paste that long type enum again inside the braces?
0
Infinity08Commented:
You can resolve it however you want. You just need to make sure that when y.tab.h is included, that the definition for ExprType is also present before its usage.
0
kuntilanakAuthor Commented:
why isn't in the current one it doesn't recognize the one I have included in tree.h? How would you resolve it?
0
Infinity08Commented:
As I said, the tree.h is only included in the y.tab.c file, not in the y.tab.h file.
0
kuntilanakAuthor Commented:
so is there any way so I can include tree.h in y.tab.h? Or maybe include it in the scanner file as well?
0
Infinity08Commented:
You can modify y.tab.h
You can use your own header file
You can include tree.h before you include y.tab.h
...

There are plenty of options :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kuntilanakAuthor Commented:
modifying y.tab.h will only resolve the problem temporary as when we compile the parser again it will be overwritten ... right?
0
Infinity08Commented:
Not if you make the modification the next step of your compilation process.
0
kuntilanakAuthor Commented:
so you modify it in the Makefile? cause if not everytime I call make then it will generate a new y.yab.h
0
Infinity08Commented:
>> so you modify it in the Makefile?

If that's the way you want to go, yes.
0
kuntilanakAuthor Commented:
I've also had this additional error:

parse.y:2:19: warning: extra tokens at end of #include directive


can you tell me what this is?
0
Infinity08Commented:
Not without seeing the code :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.