kuntilanak
asked on
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.n ame,yytext ); return TID;}
I've also included y.tab.h in the scanner file
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.n
I've also included y.tab.h in the scanner file
How and where is ExprType defined ?
ASKER
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;
>> 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)
In the correct location ?
Can you post your parse.y file (or at least the start of it)
ASKER
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
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.
ASKER
so how can I resolve this issue?
Make sure that ExprType is defined before it's used :)
ASKER
so I should copy and paste that long type enum again inside the braces?
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.
ASKER
why isn't in the current one it doesn't recognize the one I have included in tree.h? How would you resolve it?
As I said, the tree.h is only included in the y.tab.c file, not in the y.tab.h file.
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
modifying y.tab.h will only resolve the problem temporary as when we compile the parser again it will be overwritten ... right?
Not if you make the modification the next step of your compilation process.
ASKER
so you modify it in the Makefile? cause if not everytime I call make then it will generate a new y.yab.h
>> so you modify it in the Makefile?
If that's the way you want to go, yes.
If that's the way you want to go, yes.
ASKER
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?
parse.y:2:19: warning: extra tokens at end of #include directive
can you tell me what this is?
Not without seeing the code :)