0

I'm trying to make a " simple " compiler using Flex & Bison, and now, I'm building the AST.

I've programmed all my classes in a header and a source file (pretty ugly but I had inclusion errors when I didn't do that) , and therefore I'm including it in my .y bison file.

The problem comes when I specify the type of the %union fields with class type from my file. When I'm writing MyClassType field;, the compiler gives me error since I'm trying to give to the field an abstract class type (that's normal, that's what I expect the compiler to do), and when I'm writing MyClassType* field; (what I really want to do) , the compiler says he doesn't know a type called MyClassType.

What I find very odd is that he acknoledge the existance of a type, but not the existance of a pointer to this type. Furthermore, I create instances of my classes in the grammar rules, and I don't have any errors (tried without fields of my classes in the %union, so that one error doesn't hide another one). So it's only in the %union that I can't use my classes.

In my .y file, the header for my classes is included between the first %{%}, and the %union is declared just after the preceeding block. I compiled the source file for my classes separately of the flex/bison project and I don't have any errors.

So, what I'm trying to understand is why can't I use my classes inside of bison's %union ?

Thanks in advance for your answers,

Cordially, Jaxon

  • I bet it gives those two errors (about `MyClassType`) in *different places*, maybe even in *different files*. – user253751 Nov 30 '15 at 22:35
  • Have you seen [this thread](http://stackoverflow.com/questions/1430390/include-struct-in-the-union-def-with-bison-yacc), it looks like the same issue. – lrm29 Nov 30 '15 at 22:42
  • 2
    It would be easier to follow and more reliable if you pasted relevant portions of your bison file in order into your question rather than a verbal description. – rici Dec 01 '15 at 01:48
  • @lrm29 : No I didn't saw this one, thanks. I did what they say and now it works. So if I understand, the union is correctly defined into the header of bison output file that is passed to .l file. But then, since .l file doesn't find classes anywhere in his includes or in the code, it fails to create the union. I've got it ? I didn't see that coming... – MetaZenithian Dec 02 '15 at 21:38
  • @rici : Sorry if I did wrong, but I couldn't see where my code would have been useful in the example, since it's just bare normal bison with really nothing in particular ; that, and the fact that I was really sure that I didn't do anything that I knew to be wrong. But anyway, I will keep that in mind in the future – MetaZenithian Dec 02 '15 at 21:45

0 Answers0