?
Solved

expected specifier qualifier

Posted on 2008-11-04
19
Medium Priority
?
1,036 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:kuntilanak
  • 10
  • 9
19 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22877958
How and where is ExprType defined ?
0
 

Author Comment

by:kuntilanak
ID: 22879314
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 22879473
>> 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kuntilanak
ID: 22879596
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 22880337
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
 

Author Comment

by:kuntilanak
ID: 22880627
so how can I resolve this issue?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22880645
Make sure that ExprType is defined before it's used :)
0
 

Author Comment

by:kuntilanak
ID: 22880677
so I should copy and paste that long type enum again inside the braces?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22880802
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
 

Author Comment

by:kuntilanak
ID: 22881001
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 22881047
As I said, the tree.h is only included in the y.tab.c file, not in the y.tab.h file.
0
 

Author Comment

by:kuntilanak
ID: 22881079
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
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 22881236
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
 

Author Comment

by:kuntilanak
ID: 22881717
modifying y.tab.h will only resolve the problem temporary as when we compile the parser again it will be overwritten ... right?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22884209
Not if you make the modification the next step of your compilation process.
0
 

Author Comment

by:kuntilanak
ID: 22885505
so you modify it in the Makefile? cause if not everytime I call make then it will generate a new y.yab.h
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22885528
>> so you modify it in the Makefile?

If that's the way you want to go, yes.
0
 

Author Comment

by:kuntilanak
ID: 22886018
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 22887101
Not without seeing the code :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question