err: req for member in something not struct

K

Kyle Blake

I am writing a parser using flex & bison, however this appears to be a C
problem.
GCC gives the following error:
error: request for member file in something not a structure or union

The offending structure is declared as:

typedef struct YYLTYPE
{
int fl;
int fc;
int ll;
int lc;
char* file;
} YYLTYPE;
/* Apparently, bison wants it to be a macro */
#define YYLTYPE YYLTYPE

The reference that caused the error is the expansion of the following macro,
an adaption of the default one provided with bison:

#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).fl = YYRHSLOC(Rhs, 1).fl; \
(Current).fc = YYRHSLOC(Rhs, 1).fc; \
(Current).ll = YYRHSLOC(Rhs, N).ll; \
(Current).lc = YYRHSLOC(Rhs, N).lc; \
(Current).file = YYRHCLOC(Rhs, 1).file; \
} \
else \
{ \
(Current).fl = (Current).ll = \
YYRHSLOC(Rhs, 0).ll; \
(Current).fc = (Current).lc = \
YYRHSLOC(Rhs, 0).lc; \
(Current).file = YYRHSLOC(Rhs, 0).file; \
} \
while (0)

Current, YYRHCLOC(Rhs, 1), and YYRHCLOC(Rhs, N) are all of type YYLTYPE.
None of them are pointers.
It compiles fine if I comment out the line:
(Current).file = YYRHCLOC(Rhs, 1).file;
Even though file is still referenced in the else block.

Any ideas?
 
N

Nate Eldredge

Kyle Blake said:
I am writing a parser using flex & bison, however this appears to be a C
problem.
GCC gives the following error:
error: request for member file in something not a structure or union

It's hard to tell from looking at that snippet. Can you post the
complete bison input?
 
K

Kyle Blake

Nate said:
It's hard to tell from looking at that snippet. Can you post the
complete bison input?

Here it is:

***dconf-parser.y***
%{
#include <stdio.h>
#include "util.h"
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).fl = YYRHSLOC(Rhs, 1).fl; \
(Current).fc = YYRHSLOC(Rhs, 1).fc; \
(Current).ll = YYRHSLOC(Rhs, N).ll; \
(Current).lc = YYRHSLOC(Rhs, N).lc; \
(Current).file = YYRHCLOC(Rhs, 1).file; \
} \
else \
{ \
(Current).fl = (Current).ll = \
YYRHSLOC(Rhs, 0).ll; \
(Current).fc = (Current).lc = \
YYRHSLOC(Rhs, 0).lc; \
(Current).file = YYRHSLOC(Rhs, 0).file; \
} \
while (0)

%}

%token IDENT
%token STRING
%token CHAR
%token INT
%token YNM
%token NONE
%token BAD_INCLUDE
%token CONFIG
%token NAME
%token TYPE
%token TYPE_YN
%token TYPE_YNM
%token TYPE_INT
%token TYPE_STRING
%token TYPE_SELECT
%token TYPE_XSELECT
%token TYPE_DSELECT
%token DEFAULT
%token HELP
%token MORE
%token DEPENDS

%error-verbose
%defines
%locations

%%

start: /* empty */
| start config
;

config: ';'
| CONFIG IDENT '{' stmnts '}'
| CONFIG NONE '{' stmnts '}'
| CONFIG YNM '{' stmnts '}'
| CONFIG error
| error
;

stmnts: /* empty */
| stmnts stmnt ';'
| stmnts error ';'
;

stmnt: /* empty */
| name
| type
| default
| help
| depends
| BAD_INCLUDE {yyerror("could not include file"); YYERROR;}
;

name: NAME STRING
| NAME CHAR
| NAME error
;

type: TYPE TYPE_YN
| TYPE TYPE_YNM
| TYPE TYPE_INT
| TYPE TYPE_STRING
| TYPE TYPE_SELECT
| TYPE TYPE_XSELECT
| TYPE TYPE_DSELECT
| TYPE error
;

default: DEFAULT YNM
| DEFAULT INT
| DEFAULT STRING
| DEFAULT IDENT
| DEFAULT error
;

help: HELP STRING
| HELP CHAR
| HELP MORE
| HELP error
;

depends: DEPENDS expr
| DEPENDS error

expr: ;

***util.h***

#ifndef _UTIL_H_
#define _UTIL_H_

#include <stdio.h>

void
yyerror(const char* str);

#define YYSTYPE char*

typedef struct YYLTYPE
{
int fl;
int fc;
int ll;
int lc;
char* file;
} YYLTYPE;

/* Apparently, bison wants it to be a macro */
#define YYLTYPE YYLTYPE

#endif

***util.c***

void
yyerror(const char* str)
{
fprintf(stderr,
"dconf: %s (%d,%d-%d,%d)\n",
str,
yylloc->fl, yylloc->fc,
yylloc->ll, yyloc->lc);
}


Hope that helps.
 
V

vippstar

Here it is:

***dconf-parser.y***
%{
#include <stdio.h>
#include "util.h"
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).fl = YYRHSLOC(Rhs, 1).fl; \
(Current).fc = YYRHSLOC(Rhs, 1).fc; \
(Current).ll = YYRHSLOC(Rhs, N).ll; \
(Current).lc = YYRHSLOC(Rhs, N).lc; \
(Current).file = YYRHCLOC(Rhs, 1).file; \
} \
else \
{ \
(Current).fl = (Current).ll = \
YYRHSLOC(Rhs, 0).ll; \
(Current).fc = (Current).lc = \
YYRHSLOC(Rhs, 0).lc; \
(Current).file = YYRHSLOC(Rhs, 0).file; \
} \
while (0)

%}

%token IDENT
%token STRING
%token CHAR
%token INT
%token YNM
%token NONE
%token BAD_INCLUDE
%token CONFIG
%token NAME
%token TYPE
%token TYPE_YN
%token TYPE_YNM
%token TYPE_INT
%token TYPE_STRING
%token TYPE_SELECT
%token TYPE_XSELECT
%token TYPE_DSELECT
%token DEFAULT
%token HELP
%token MORE
%token DEPENDS

%error-verbose
%defines
%locations

%%

start: /* empty */
| start config
;

config: ';'
| CONFIG IDENT '{' stmnts '}'
| CONFIG NONE '{' stmnts '}'
| CONFIG YNM '{' stmnts '}'
| CONFIG error
| error
;

stmnts: /* empty */
| stmnts stmnt ';'
| stmnts error ';'
;

stmnt: /* empty */
| name
| type
| default
| help
| depends
| BAD_INCLUDE {yyerror("could not include file"); YYERROR;}
;

name: NAME STRING
| NAME CHAR
| NAME error
;

type: TYPE TYPE_YN
| TYPE TYPE_YNM
| TYPE TYPE_INT
| TYPE TYPE_STRING
| TYPE TYPE_SELECT
| TYPE TYPE_XSELECT
| TYPE TYPE_DSELECT
| TYPE error
;

default: DEFAULT YNM
| DEFAULT INT
| DEFAULT STRING
| DEFAULT IDENT
| DEFAULT error
;

help: HELP STRING
| HELP CHAR
| HELP MORE
| HELP error
;

depends: DEPENDS expr
| DEPENDS error

expr: ;

***util.h***

#ifndef _UTIL_H_
#define _UTIL_H_

#include <stdio.h>

void
yyerror(const char* str);

#define YYSTYPE char*

typedef struct YYLTYPE
{
int fl;
int fc;
int ll;
int lc;
char* file;

} YYLTYPE;

/* Apparently, bison wants it to be a macro */
#define YYLTYPE YYLTYPE

#endif

***util.c***

void
yyerror(const char* str)
{
fprintf(stderr,
"dconf: %s (%d,%d-%d,%d)\n",
str,
yylloc->fl, yylloc->fc,
yylloc->ll, yyloc->lc);

}

Hope that helps.

Well, first of all, flex/bison is not on-topic here. Nor is its
output.
I don't have any knowledge of those programs; I do know C however, and
just by my C knowledge, I can not spot the mistake in your "code".
However, in yyerror, you have yylloc-> and yyloc-> (notice the single
'l'). Is that intentional?

Regardless, as I've said your post is off-topic and even if you do get
help you shouldn't post here in the future about flex/bison queries. I
don't know where such messages would be on-topic.
 
K

Kyle Blake

Well, first of all, flex/bison is not on-topic here. Nor is its
output.
I don't have any knowledge of those programs; I do know C however, and
just by my C knowledge, I can not spot the mistake in your "code".
However, in yyerror, you have yylloc-> and yyloc-> (notice the single
'l'). Is that intentional?

Regardless, as I've said your post is off-topic and even if you do get
help you shouldn't post here in the future about flex/bison queries. I
don't know where such messages would be on-topic.

The single 'l' is a mistake.
I do not believe that it is off-topic, as it is the C part that has the
problem, not the bison part.
 
B

Ben Bacarisse

Kyle Blake said:
I am writing a parser using flex & bison, however this appears to be a C
problem.

GCC gives the following error:
error: request for member file in something not a structure or union

The offending structure is declared as:

typedef struct YYLTYPE
{
int fl;
int fc;
int ll;
int lc;
char* file;
} YYLTYPE;
/* Apparently, bison wants it to be a macro */
#define YYLTYPE YYLTYPE

The reference that caused the error is the expansion of the following macro,
an adaption of the default one provided with bison:

#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).fl = YYRHSLOC(Rhs, 1).fl; \
(Current).fc = YYRHSLOC(Rhs, 1).fc; \
(Current).ll = YYRHSLOC(Rhs, N).ll; \
(Current).lc = YYRHSLOC(Rhs, N).lc; \
(Current).file = YYRHCLOC(Rhs, 1).file;

I think you are missing an S -- YYRHCLOC is not the same as
YYRHSCLOC used in the other cases. If you turn up warnings the
compiler will complain about an undefined function.
 
K

Kyle Blake

Ben said:
I think you are missing an S -- YYRHCLOC is not the same as
YYRHSCLOC used in the other cases. If you turn up warnings the
compiler will complain about an undefined function.
That fixed it, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top