-
C and a bit of yacc/flex
Okay, so I had this code in my .l file (scanner file):
Code:
TokenType getToken(void)
{
static int firstTime = TRUE;
TokenType currentToken;
if (firstTime) {
firstTime = FALSE;
lineno++;
yyin = stdin;
yyout = stderr;
}
currentToken = yylex();
strncpy(tokenString, yytext, MAXTOKENLEN);
return currentToken;
}
TokenType is basically:
typedef int TokenType;
declared in one of my .h file
and I have this code in my .y file:
Code:
static TokenType yylex(void) {
return getToken();
}
The problem is that by doing this, the scanner always looks ahead once of the necessary, in other words when it has reached the end of the file.. it keeps on reading once then it finishes.. This is not what I want, I want it to terminate right after it reads the end of file.
-
can anyone please help me?