ahh , finally I backtrack the bug. Believe me I'm not saying that
I'm experienced but many years I have been working with C++ , at least 5 yrs .I'm working with the C compiler since I was at the 7th grade. however the fun part is not boosting about it. The fun part
is a small bug costs me around 3 1/2 hours of troubleshooting time.

well this is not an question so I thought that C++ form is not the
good place to share that bug with you. so I like to make this palce to
share my bug. May be somebody in future who dig this thread will find
his answer.

as we all knows C++ has a preprocessor. I'm loving C++ and it's my
best programming language but , there are week points in C++ , one
week point is it's week enough to have a preprocessor. using the
preprocessor makes my life easy. But sometime s ( like what happened to today ) there can be hard to find compile and runtime bugs which cost all these advantages. this post is not about telling you not to use C++ preprocessor , anyhow I keep that discussion
open but not the purpose of this thread , so this thread is about how
to track those bugs that comming with the preprocessor.


telling about my project , well I just design a SQL syntax helper project
that predict and tell what kind of syntax that he can type further by
poping up a small widget saying the next correct syntax or what
is the extract syntax that he enters belongs to.for example when user
just types SELECT it will popup and shows the next valid syntaxes
that he can type for a example SELECT { database } FROM {......
like that.

so my project contains a backend that parse that user input and
give that predictions. and any GUI font end is able to use that DLL file
. so as other compiler related tools this also has a lexer , and use
the flex opensource tool inside windows. So I'm writing this post
while I'm designing the lexer component . so as you know there
is a lex file that contains the rules for a lexer.and that file includes
the Torkens.h that contains the torken ID values. so that is the time
that I finish some of the root elements and a time for a 1st test
case. So I start to compile . I got these errors when I compile the
yy.lex.c file.

ex.yy.c(1077) : error C2143: syntax error : missing '{' before 'constant'
lex.yy.c(1077) : error C2059: syntax error : '<Unknown>'
lex.yy.c(1079) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1085) : error C2059: syntax error : '}'
lex.yy.c(1094) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1115) : error C2059: syntax error : '}'
lex.yy.c(1135) : error C2143: syntax error : missing '{' before 'constant'
lex.yy.c(1135) : error C2059: syntax error : '<Unknown>'
lex.yy.c(1138) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1159) : error C2059: syntax error : '}'
lex.yy.c(1168) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1179) : error C2059: syntax error : '}'
lex.yy.c(1193) : error C2059: syntax error : 'constant'
lex.yy.c(1197) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1212) : error C2059: syntax error : '}'
lex.yy.c(1222) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1242) : error C2059: syntax error : '}'
lex.yy.c(1251) : warning C4142: benign redefinition of type
lex.yy.c(1251) : error C2086: 'size' : redefinition
lex.yy.c(1253) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1279) : error C2059: syntax error : '}'
lex.yy.c(1290) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1296) : error C2059: syntax error : '}'
lex.yy.c(1308) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1335) : error C2059: syntax error : '}'
lex.yy.c(1401) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1404) : error C2059: syntax error : '}'
lex.yy.c(1465) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1467) : error C2059: syntax error : '}'
lex.yy.c(1474) : warning C4142: benign redefinition of type
lex.yy.c(1474) : error C2086: 'size' : redefinition
lex.yy.c(1476) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1485) : error C2059: syntax error : '}'
lex.yy.c(1493) : error C2449: found '{' at file scope (missing function header?)
lex.yy.c(1495) : error C2059: syntax error : '}'

well , the only way to fix these problems is going the lines one
by one so therefore I started at the first one. the that line of code
is like that.

#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
	{
	if ( ! yy_current_buffer )
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );

	yy_init_buffer( yy_current_buffer, input_file );
	yy_load_buffer_state();
	}

and I doesn't seems a wrong in the code first. can you tell where
is the wrong ? Most of us can't. It costs me thinking and thinking
about 3 and 1/2 hours.finally I decided to use MinGW C compiler
gcc ( for windows ) and compile. Yes it's also gives that same line
numbers have a error similar to that. Then I just turn off some
includes like #include "EventListener.h" and #include "Torken.h"
and tries to compile. well I want to say that inside the EventListener.h if __TORKEN_H__ is not definied then it include the
Torken.h . so uncommenting both files make sense. finally that's what I did. well what a wonder no errors , only the errors that comming from the dependencies . so I make the way to think about
the preprocessor . But there is only one problem exists . How to
generate the preprocessed file . well GCC you can , but MS VC++
I even yet don't know.So I wish to use the GCC and with the -E
tag and that will write them to the std output. so this is how I
did it.

I:\final-year-project-test\lexer>gcc -E lex.yy.c > preprocessed_only.pre

I:\final-year-project-test\lexer>

the character '>' will say the write std output tothe preprocessed_only.pre . Then I checked that line related to
the first error line.

void yyrestart( 61 *input_file )




 {
 if ( ! yy_current_buffer )
  yy_current_buffer = yy_create_buffer( yyin, 16384 );

 yy_init_buffer( yy_current_buffer, input_file );
 yy_load_buffer_state();
 }

ohh damm ! I can remember 61 that I enter as a preprocessor
directive. in the file Torkens.h , so finally that's how I bug track the
error.

#define EXISTS		58
#define EXIT		59
#define FETCH		60
#define FILE		61
#define FILLFACTOR	62
#define FOR			63

so the only way to correct is just change this without breaking the upper code. So here is the place where to change the code. and I
don't like to mix the C++ namespaces into this too. so I put
a :KUGLY: comment and a :COMPILER: comment and fix this error.

#define FILE_TORKEN 61
// :KUGLY: :COMPILE: the FILE has some name conflit with
// standard C FILE so that's why I use this.

so finally the answer for these kind of bugs is to say to the compiler
to stop after preprocessed. using the -E tag and grab the output
stdout.
-E for the gcc I don't know what's for the VC++ cl.exe ? and don't have that much of idea to tell it inside the VC++ IDE.

Recommended Answers

All 5 Replies

i sort of misread the title and thought that you were going to tell us about your erotic fantasies.

i sort of misread the title and thought that you were going to tell us about your erotic fantasies.

what are the erotic fantasies ?
I mean using the lex in windows it is flex.
http://flex.sourceforge.net/

>>this post is not about telling you not to use C++ preprocessor
Good, because it is not possible.


>>How to generate the preprocessed file . well GCC you can , but MS VC++ I even yet don't know.

what are the erotic fantasies ?

Google for it. Links to them are not permitted here at DaniWeb and you will get infracted for posting them.

i sort of misread the title and thought that you were going to tell us about your erotic fantasies.

+1

Really, some people need to take their minds out of the gutter ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.