473,718 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Yacc/Bison: Trouble using struct in %union - "incomplete type" error

In my Yacc .y file I defined:

%union {
int value;
struct Symbol Sym;
}
The Symbol struct I defined in a header file I #included in the Prologue
section of the .y file as:

struct Symbol {
char *SymName; /* Name of symbol/token */
int SymType; /* Symbol type */
int SymValue;
};

However, on build I get:

bison -d prog.y
flex -t prog.l prog.lex.c
gcc -g -w -c prog.lex.c
In file included from prog.l:10:
prog.y:22: error: field `Sym' has incomplete type
make: *** [prog.lex.o] Error 1

If in the %union I make Sym a pointer to struct Symbol the build error
goes away. Can someone explain what is going wrong here and how I can
correct this to Sym is still just a struct?

--john
Jul 15 '06 #1
3 11819
On Sat, 15 Jul 2006 17:24:48 GMT, John Sasso <js******@nospa m.com>
wrote in comp.lang.c:
In my Yacc .y file I defined:

%union {
int value;
struct Symbol Sym;
}
[snip]

This is not C, and not a C language issue, therefore off-topic in
comp.lang.c, followups set. I have no idea whether it is topical or
not in comp.os.linux.d evelopment.apps .

comp.lang.c removed from follow up.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 15 '06 #2

"John Sasso" <js******@nospa m.comwrote in message
news:Ax******** ***********@twi ster.nyroc.rr.c om...
In my Yacc .y file I defined:

%union {
int value;
struct Symbol Sym;
}
The Symbol struct I defined in a header file I #included in the Prologue
section of the .y file as:

struct Symbol {
char *SymName; /* Name of symbol/token */
int SymType; /* Symbol type */
int SymValue;
};

However, on build I get:

bison -d prog.y
flex -t prog.l prog.lex.c
gcc -g -w -c prog.lex.c
In file included from prog.l:10:
prog.y:22: error: field `Sym' has incomplete type
make: *** [prog.lex.o] Error 1

If in the %union I make Sym a pointer to struct Symbol the build error
goes away. Can someone explain what is going wrong here and how I can
correct this to Sym is still just a struct?
I can't help very much from what you posted. All I can do is review how you
should include the file.

Let's say your struct:

struct Symbol {
char *SymName; /* Name of symbol/token */
int SymType; /* Symbol type */
int SymValue;
};

is in "symbol.h".

Then, the .y Bison grammar file, should have this:

%{
#include "symbol.h"
%}
%union {
int value;
struct Symbol Sym;
}

And, the .l Flex grammar file, should have this:

%{
#include "symbol.h"
#include "y.tab.h"
%}
Notice that "y.tab.h" is included in the .l Flex grammar and it comes after
"symbol.h". That's about all I can help you with.
Rod Pemberton
Jul 16 '06 #3
John Sasso <js******@nospa m.comwrote:
# In my Yacc .y file I defined:
#
# %union {
# int value;
# struct Symbol Sym;
# }
#
#
# The Symbol struct I defined in a header file I #included in the Prologue
# section of the .y file as:
#
# struct Symbol {
# char *SymName; /* Name of symbol/token */
# int SymType; /* Symbol type */
# int SymValue;
# };
#
# However, on build I get:
#
# bison -d prog.y
# flex -t prog.l prog.lex.c
# gcc -g -w -c prog.lex.c
# In file included from prog.l:10:
# prog.y:22: error: field `Sym' has incomplete type
# make: *** [prog.lex.o] Error 1

Are you also #including the header file in prog.l? The C files generated
by bison and lex are separate and should not be expected to known about
the other's includes. While bison might write out an interface file with
its unions and symbol definitions, you should only expect that to have
the declarations bison creates and not transitively declarations from
other include files.

# If in the %union I make Sym a pointer to struct Symbol the build error
# goes away. Can someone explain what is going wrong here and how I can
# correct this to Sym is still just a struct?

All struct pointers look the same; the compile can allocate the union
because it will know the size of the struct pointer even if it doesn't
know the size of the struct.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
You hate people.
But I love gatherings. Isn't it ironic.
Jul 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
33662
by: Lou Pecora | last post by:
g++ compiler error question. I have a container C whose constructor takes a class B that is inherited from an abstract class A. So I have the line of code: B binstance; C cinstance(binstance); The compiler gives the error,
0
1749
by: hamstak | last post by:
While attempting to perform a build on an .aspx page from within VS 2005 I receive the "Could not load type" error pertaining to the class representing the page. The class is derived from a custom base class (which itself is derived from System.Web.UI.Page). This custom base class has been used in other projects successfully. The Inherits attribute of the @Page directive is properly assigned and the application root is properly...
3
5423
by: Alden Pierre | last post by:
Hello, I'm having a hard time trying to figure why my code will not compile. When I try to compile the code, I get the non-aggregate type error. Any ideas on what I'm doing wrong? --------------------------------------------------------------------- File: main.cpp --------------------------------------------------------------------- #include "roster.h"
669
26019
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
13
2254
by: imutate | last post by:
Hi, I am migrating some std::vectors to use a template instead, but I get an incomplete type error in a struct declaration. #include <vector> template < typename T > class Vec : public std::vector< T { public: Vec():Vec<T>() { }
2
16127
by: cr55 | last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have class/struct/union type.The problem area is underlined. Any help will be greatly appreciated. #include <c:\cpp\input.h> #include < time.h> #define SIZE 20 struct Cust{ int custno; char fname;
3
12559
by: eros | last post by:
ALTER TABLE public.postcodes ALTER COLUMN machi TYPE varchar(100); Error: ERROR: syntax error at or near "TYPE"; Error while executing the query (State:42601, Native Code: 7) I am using WinSQL, Windows XP SP2 Japanese Version, PostgreSQL 8.x. I want to alter my machi field from varchar(30) to varchar(100) TYPE. This is my CREATE TABLE script:
2
3919
by: unclefester | last post by:
I have two classes: Test1 and Test2. Test1 has a field of data type Test2, & vice versa. I need some help in avoiding the incomplete type error ("Error: field has incomplete type"). Test1.h #ifndef _TEST1_ #define _TEST1_ #include "Test2.h" using namespace std;
5
3185
by: tejesh | last post by:
I am trying to compile the following code int backend_sm_run(struct interface_data *ctx) { xsup_assert((ctx != NULL), "ctx != NULL", TRUE); xsup_assert((ctx->statemachine != NULL), "ctx->statemachine != NULL", TRUE); backend_sm_check_globals(check);
5
9482
by: Anuz | last post by:
Hi all, While compiling a driver, I am getting this error: error: dereferencing pointer to incomplete type int __kc_adapter_clean(struct net_device *netdev, int *budget) { /*some initialization stuff */ struct adapter_struct *adapter = netdev_priv(netdev);
0
8827
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9352
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7985
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6652
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.