views:

324

answers:

2

Here's my code:

 34  
 35 /**  
 36  ** \file position.hh  
 37  ** Define the example::position class.  
 38  */  
 39   
 40 #ifndef BISON_POSITION_HH   
 41 #define BISON_POSITION_HH   
 42    
 43 #include <iostream>   
 44 #include <string>   
 45    
 46 namespace example   
 47 {   
 48   /// Abstract a position.   
 49   class position   
 50   {   
 51   public:   
 52    
 53     /// Construct a position.   
 54     position ()    
 55       : filename (0), line (1), column (0)   
 56     {    

Thanks, speeder, that's great. Necrolis, thank you as well. Both of you guys are onto the same track on the compilation units. Here's the full error report:

In file included from location.hh:45, from parser.h:64, from scanner.h:25, from scanner.ll:8: position.hh:46: error: expected unqualified-id before ‘namespace’

location.hh looks like this:

35 /**
36  ** \file location.hh
37  ** Define the example::location class.
38  */
39 
40 #ifndef BISON_LOCATION_HH
41 # define BISON_LOCATION_HH
42 
43 # include <iostream>
44 # include <string>
45 # include "position.hh"
46 
47 namespace example
48 {
49 
50   /// Abstract a location.
51   class location
52   {
53   public:

I should also add that these files are being generated by bison. it's when i try to compile the c++ scanner class generated by flex++ that I get to this stage. I get the .cc code by issuing flex --c++ -o scanner.cc scanner.ll.

A: 

this happen when a ; or some other closing thing is lacking before the namespace. Are you sure that the lines before 34 have no code? If they have code (even if that code is other #include) the error is there.

EDIT: Or in case all 34 lines have no code, the error is on the file that includes this header, most likely there are a code without a ending ; or } or ) or some other ending character, and right after it (ignoring comments, of course) there are the #include position.hh

Or if there are two includes in a row, one before position.hh, the last lines of the header included before position.hh are with the error, usually a structure without a ; after the closing }

speeder
Speeder: all the lines before what I posted are comments. Thanks!
vergueishon
@jedibrand: there are many ways to write a comment, including incorrect ones...
Eugen Constantin Dinca
I've removed everything preceding line 40 and tried to compile again, same error...
vergueishon
Ok... I know how to track it... The error then is most likely in the file including this file. Before the "#include position.hh" Now go check it there. If possible, edit your post and paste the lines that come before the include.
speeder
Thanks, speeder. Just updated witht he code you requested...
vergueishon
omg that is LOTs of includes...So, seemly it is not in location.hh it maybe is in parser.h in a line before 64 or scanner.h in a line before 25 or in scanner.ll before 8...Or to make things worse, it may be in any included file on the cited locations, or in a include chain on these cited locations. I edited my awnser, read it again and see if you can track it.
speeder
You're right, speeder. I think the issue is with flex/bison...
vergueishon
Speeder was closest to the truth, though Necrolis offered the general solution first. Turns out it was not at the beginning or end of a file, but actually in a class in one of my header files. That file is not referenced by any of the files reported in the error message but, rather, in the middle of another header. Indeed, the issue was an improperly closed class lacking a };
vergueishon
+1  A: 

The error might be occuring in a file other than the file its reported in(due to the compilation units), namely at or near the end of that 'other' file(such as a missing '}' or ';' or '#endif' etc)

Necrolis